Created
October 28, 2015 22:28
-
-
Save srlm-io/d87063ffdee2d9a6089e to your computer and use it in GitHub Desktop.
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
from __future__ import print_function | |
import serial | |
# This script is intended to redirect a specially demarcated section | |
# of the serial stream to STDERR, which you can then redirect to | |
# wherever you wish (like a text file for importing into Excel). | |
# host usage: | |
# python serial_split.py 2> mydata.txt | |
# client serial stream example: | |
# | |
# Program starting... | |
# blah blah blah | |
# Data next! | |
# ++++++++++++++++++++ | |
# num, something, column | |
# 1,2,3 | |
# 1,4,9 | |
# 1,8,27 | |
# ==================== | |
# Program done, shutting down | |
# Thanks! | |
start_sequence = '++++++++++++++++++++' | |
end_sequence = '====================' | |
device = serial.Serial('/dev/ttyUSB0', 115200) | |
logging = False | |
while True: | |
line = device.readline() | |
print(line) | |
if logging == False and line == start_sequence: | |
logging = True | |
continue # make sure that we do not log the start sequnce | |
elif logging == True and line == stop_sequence: | |
logging = False | |
if logging: | |
print(line, file=sys.stderr) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment