Skip to content

Instantly share code, notes, and snippets.

@briankip
Created May 7, 2015 08:51
Show Gist options
  • Save briankip/2082727d6375a7f72c15 to your computer and use it in GitHub Desktop.
Save briankip/2082727d6375a7f72c15 to your computer and use it in GitHub Desktop.
python script for reading from windows serial
#/usr/bin/env python
import serial
#variables
port='COM2';
baudrate='9600';
bytesize=serial.EIGHTBITS; #EIGHT BITS
parity=serial.PARITY_NONE; # ODD
stopbits=serial.STOPBITS_ONE; # 2 STOP BITS
filename = 'serial.dump';
serialPort = serial.Serial(port, baudrate, bytesize, parity, stopbits); #should be open
serialPort.open();
def readloop(bytebuffer):
while True:
cc = serialPort.read()
bytebuffer.extend(cc);
if cc.encode('hex') == '\03'.encode('hex'): #end of text
dumpresults(bytebuffer)
break;
def dumpresults(content):
f = open(filename, 'w');
f.write(content)
f.close()
bytebuffer = []
readloop(bytebuffer)
bytebuffer = []
readloop(bytebuffer)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment