Skip to content

Instantly share code, notes, and snippets.

@srlm-io
Created October 28, 2015 22:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save srlm-io/d87063ffdee2d9a6089e to your computer and use it in GitHub Desktop.
Save srlm-io/d87063ffdee2d9a6089e to your computer and use it in GitHub Desktop.
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