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.

33 lines
772 B

5 years ago
  1. #!/usr/bin/python2.7
  2. import serial
  3. import os
  4. import string
  5. #button0 = "User Pressed button: 0"
  6. ser = serial.Serial(
  7. port='/dev/ttyUSB0',\
  8. baudrate=9600,\
  9. parity=serial.PARITY_NONE,\
  10. stopbits=serial.STOPBITS_ONE,\
  11. bytesize=serial.EIGHTBITS,\
  12. #timeout=None) #doesn't work
  13. timeout=0)
  14. line = []
  15. print("connected to: " + ser.portstr)
  16. while True:
  17. # line = ser.readline(); #this adds extra new lines in random spots, wut
  18. # line = ser.read().splitlines() #this makes everything like \g in mysql
  19. # line = ser.read().rstrip('\n') #does similar to above, without brackets
  20. line = ser.readline().rstrip('\n') # this fails to remove line breaks. fuck pyserial
  21. if line:
  22. # print(line.splitlines()) # also doesn't work
  23. print(line)
  24. #ser.close()