Created
March 5, 2015 18:32
-
-
Save robobenklein/fbc52edab1ffdfa62972 to your computer and use it in GitHub Desktop.
This program reads serial input and logs it to file with timestamp.
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
# -*- coding: utf-8 -*- | |
''' | |
This program reads serial input from the 'sport' and logs it to file with timestamp. | |
It may not be the best code out there but it works for all my intents and purposes. | |
Credit to Tim and Ben Klein | |
This code is licensed under WFTPL, http://www.wtfpl.net/txt/copying/ | |
Although it would still be nice to give some kind of credit ;) | |
''' | |
import serial | |
import datetime | |
sport = 'COM4' | |
datafile = 'dataout.csv' | |
ser = serial.Serial(sport, 9600, timeout=60) | |
#readline_in = [50,52,48,44,50,51,51,44,50,51,48,44,50,50,56,44,50,50,53,44,50,49,55,13,10] | |
#writeline_out = ''.join(map(chr,readline_in)) | |
#print('in',readline_in) | |
#print('out',writeline_out) | |
while True: | |
# ser.readLine waits for input -> potential lockup | |
dataline = ser.readline() | |
txtline = str(datetime.datetime.now()) + ''.join(map(chr,dataline)) | |
print(txtline) | |
with open(datafile, 'a', newline='') as f: | |
f.write(txtline) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment