Created
January 6, 2017 03:22
-
-
Save dapperfu/e0b30720aca4eeb3634a00b880728d15 to your computer and use it in GitHub Desktop.
Log data from serial in to a csv file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import serial | |
import sys | |
import datetime | |
port = sys.argv[1] | |
ser = serial.Serial(port=port, baudrate=115200, timeout=5) | |
try: | |
while 1: | |
data = "{},{},{}".format(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f"), | |
port, | |
ser.readline().decode().strip()) | |
print(data, flush=True) | |
except KeyboardInterrupt: | |
pass | |
except serial.serialutil.SerialException: | |
pass | |
except: | |
raise |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment