pastebin - collaborative debugging tool
python.kpaste.net RSS


monitor serial port and log csv with timestamp.
Posted by Anonymous on Tue 26th Feb 2019 03:32
raw | new post

  1. #!/usr/bin/python3
  2. import serial
  3. import time
  4. import sys
  5.  
  6. ser = serial.Serial('/dev/ttyUSB1',9600,timeout=0)  
  7. #ser.setDTR(1)
  8. print(ser.name)
  9. seq = []
  10. count = 1
  11. previousTime=time.time()
  12. currentTime=time.time()
  13. c=0
  14. while True :
  15.     for c in ser.read():
  16.         seq.append(chr(c))
  17.         joined_seq = ''.join(str(v) for v in seq)
  18.     if chr(c) == '\r':
  19.         #print("Line " + str(count) + ': ' + joined_seq)
  20.         #strToHex(joined_seq)
  21.         print(str(int(time.time()))+","+joined_seq.strip()+"")
  22.         sys.stdout.flush()
  23.         c=0
  24.         seq = []
  25.         count += 1
  26.     time.sleep(0.0001)
  27. ser.close()

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}





All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at