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.

25 lines
477 B

5 years ago
  1. #!/usr/bin/python2.7
  2. import serial
  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=0)
  10. print("connected to: " + ser.portstr)
  11. #this will store the line
  12. line = []
  13. while True:
  14. for c in ser.read():
  15. line.append(c)
  16. if c == '\n':
  17. print("Line: " + ''.join(line))
  18. line = []
  19. break
  20. ser.close()