You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
578 B

5 years ago
  1. import serial
  2. from time import sleep
  3. ser = serial.Serial(
  4. port='/dev/ttyUSB0',\
  5. baudrate=9600,\
  6. parity=serial.PARITY_NONE,\
  7. stopbits=serial.STOPBITS_ONE,\
  8. bytesize=serial.EIGHTBITS,\
  9. #timeout=None) #doesn't work
  10. timeout=0)
  11. print("connected to: " + ser.portstr)
  12. # credit to https://eli.thegreenplace.net/2009/07/30/setting-up-python-to-work-with-the-serial-port
  13. # for a working read example
  14. while True:
  15. data = ser.read(9999)
  16. if len(data) > 0:
  17. # print 'Got:', data
  18. print data
  19. sleep(0.5)
  20. # print 'not blocked'
  21. ser.close()