Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. import time
  2. import serial
  3.  
  4. # configure the serial connections (the parameters differs on the device you are connecting to)
  5. ser = serial.Serial(
  6. port='/dev/ttyUSB0',
  7. baudrate=115200,
  8. parity=serial.PARITY_NONE,
  9. stopbits=serial.STOPBITS_ONE,
  10. bytesize=serial.EIGHTBITS
  11. )
  12.  
  13. ser.isOpen()
  14.  
  15.  
  16.  
  17. answer = "test"
  18. while 1 :
  19. answer = input("Select a spot:")
  20. if answer == 'exit':
  21. ser.close()
  22. exit()
  23. else:
  24. # send the character to the device
  25. # (note that I happend a \r\n carriage return and line feed to the characters - this is requested by my device)
  26. ser.write(answer.encode())
  27. out = ''
  28. # let's wait one second before reading output (let's give device time to answer)
  29. time.sleep(1)
  30. while ser.inWaiting() > 0:
  31. temp = ""
  32. out += str(ser.read(1),"utf-8")
  33.  
  34. if out != '':
  35. print (">>" + out)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement