-
Notifications
You must be signed in to change notification settings - Fork 0
/
prgm.py
38 lines (28 loc) · 801 Bytes
/
prgm.py
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
31
32
33
34
35
36
37
38
from time import sleep
import serial
SERIAL_PORT = '/dev/serial/by-id/usb-Prolific_Technology_Inc._USB-Serial_Controller-if00-port0'
ser = serial.Serial(SERIAL_PORT, 9600)
ser.flushOutput()
ser.flushInput()
ser.sendBreak()
s = bytes()
for it in (range(64),
range(63, -1, -1)
):
s += bytes(b'C')
for n in it:
for k in range(min(8, n), -1, -1):
s += b'L' + bytes([k, int(255 * (8-k)/8)])
s += b'S' + bytes([20])
ser.write(b'A')
ser.write(bytes([len(s) // 256, len(s) % 256]))
print(''.join('\\x' + '%.2x' % c for c in s))
print(len(s))
for i in range(0, len(s), 32):
ser.flush()
r = ser.read()
print('r=%r' % (r,))
assert(r == b'?')
print('write=%d' % ser.write(s[i:i + 32]))
ser.flush()
assert(ser.read() == b'A')