Skip to content

Instantly share code, notes, and snippets.

@phred
Created March 6, 2013 17:15
Show Gist options
  • Save phred/5101068 to your computer and use it in GitHub Desktop.
Save phred/5101068 to your computer and use it in GitHub Desktop.
Blast out some commands to COM0, pausing every once and a while.
import sys, os, time
import serial
ser = serial.Serial(port='COM0',baudrate=115200, timeout=1)
# class TestSerial:
# def write(self, msg):
# print "GOT: " + msg
#
# ser = TestSerial()
if __name__ == "__main__":
if len(sys.argv) < 2:
print "Usage: strobe.py <file>"
sys.exit()
with file(sys.argv[1]) as f:
line = f.readline()
while line:
if "sleep" in line.lower():
_, delay = line.split(' ')
delay = int(delay)
print "Sleeping for %s milliseconds" % delay
time.sleep(delay/1000.0)
else:
print "Sending: " + line[:-1]
ser.write(line)
line = f.readline()
print "DONE"
z 10000 10000
m 100 100
sleep 500
z 1000 1000
m 200 200
sleep 100
z 100000 100000
m 1000 100
sleep 1000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment