You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
722 B
Python
34 lines
722 B
Python
import serial
|
|
|
|
ser = serial.Serial(
|
|
port='/dev/ttyUSB0',
|
|
baudrate=3000000,
|
|
parity=serial.PARITY_NONE,
|
|
stopbits=serial.STOPBITS_ONE,
|
|
bytesize=serial.SEVENBITS,
|
|
timeout=0.1
|
|
)
|
|
|
|
one = 0xfe
|
|
zero = 0xe0
|
|
stop = 0xfe
|
|
|
|
status = bytes([zero, zero, zero, zero, zero, zero, zero, zero, stop])
|
|
poll = bytes([zero, zero, zero, zero, zero, zero, zero, one, stop])
|
|
|
|
ser.write(status)
|
|
ret=ser.read(30)
|
|
print(' '.join('{:02x}'.format(x) for x in ret))
|
|
|
|
while(1):
|
|
ser.write(poll)
|
|
ret=ser.read(50)
|
|
print(' '.join('{:02x}'.format(x) for x in ret))
|
|
if(ret[8] & 0xE0):
|
|
print("A")
|
|
if(ret[9] & 0xF0 == 0x70):
|
|
print("B")
|
|
if(ret[10] & 0x0F == 0x0e):
|
|
print("Z")
|
|
ser.flush()
|