Skip to content

Instantly share code, notes, and snippets.

@briankip briankip/py.py
Created May 7, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.