2022-02-23 14:42:32 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
import time
|
|
|
|
import serial
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
|
|
ser = serial.Serial(
|
|
|
|
port='/dev/serial0', #Replace ttyS0 with ttyAM0 for Pi1,Pi2,Pi0
|
2022-04-05 20:56:40 +00:00
|
|
|
baudrate = 9600,
|
2022-02-23 14:42:32 +00:00
|
|
|
parity=serial.PARITY_NONE,
|
|
|
|
stopbits=serial.STOPBITS_ONE,
|
|
|
|
bytesize=serial.EIGHTBITS,
|
2022-06-08 13:29:10 +00:00
|
|
|
timeout=2
|
2022-02-23 14:42:32 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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:
|
2022-06-08 13:30:34 +00:00
|
|
|
line = ser.readline().decode('utf-8', errors='replace').rstrip()
|
|
|
|
print(line)
|
|
|
|
ser.flush()
|
|
|
|
break
|
|
|
|
|
|
|
|
time.sleep(1)
|
|
|
|
|
2022-02-23 14:42:32 +00:00
|
|
|
quit()
|