-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserial_proxy.py
More file actions
30 lines (23 loc) · 785 Bytes
/
Copy pathserial_proxy.py
File metadata and controls
30 lines (23 loc) · 785 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env python
import serial, sys, string
# Horrible workaround for strange bug in ruby serial port libraries, for now
START_IOPACKET = '0x7e'
def find_packet(serial):
if hex(ord(serial.read())) == START_IOPACKET:
lengthMSB = ord(serial.read())
lengthLSB = ord(serial.read())
length = (lengthLSB + (lengthMSB << 8)) + 1
return serial.read(length)
else:
return None
if len(sys.argv) == 1:
sys.exit(["Required arg: serial dev (eg /dev/ttyUSB0)"])
serial_dev = sys.argv[1]
serial = serial.Serial(serial_dev, 9600)
serial.open()
while True:
packet = find_packet(serial)
if packet:
packet_bytes = [str(ord(byte)) for byte in packet]
print(string.join(packet_bytes, " "))
sys.stdout.flush()