Created
May 7, 2015 08:51
-
-
Save briankip/2082727d6375a7f72c15 to your computer and use it in GitHub Desktop.
python script for reading from windows serial
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
#/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