31 lines
574 B
Python
31 lines
574 B
Python
|
#!/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 = 9600,
|
||
|
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.1)
|
||
|
print(line)
|
||
|
ser.flush()
|
||
|
break
|
||
|
|
||
|
quit()
|