34 lines
587 B
Python
Executable file
34 lines
587 B
Python
Executable file
#!/usr/bin/env python
|
|
import time
|
|
import serial
|
|
import sys
|
|
|
|
|
|
ser = serial.Serial(
|
|
port='/dev/serial0', #Replace ttyS0 with ttyAM0 for Pi1,Pi2,Pi0
|
|
baudrate = 14400,
|
|
parity=serial.PARITY_NONE,
|
|
stopbits=serial.STOPBITS_ONE,
|
|
bytesize=serial.EIGHTBITS,
|
|
timeout=1
|
|
)
|
|
|
|
ser.flush()
|
|
|
|
cw = int(sys.argv[1], 0)
|
|
com = [cw]
|
|
ser.write(serial.to_bytes(com))
|
|
ser.flush()
|
|
while True:
|
|
if ser.in_waiting > 0:
|
|
line = ser.readline().decode('utf-8', errors='replace').rstrip()
|
|
time.sleep(0.5)
|
|
print(line)
|
|
ser.flush()
|
|
break
|
|
|
|
quit()
|
|
|
|
|
|
|
|
|