主要参考Jetson nano串口的使用——UART,有改动
代码
xx.py:
import serial as ser
import time
a = "abcabc\t"
b = 0.
c = "\tfyo"
se = ser.Serial("/dev/ttyTHS1", 9600, timeout=1)
while True:
b = b + 1
se.write(a.encode())
se.write(str(b).encode("GB2312"))
se.write(c.encode("GB2312"))
se.write("\r\n".encode())
print(se.readline().decode("GB2312"))
time.sleep(1)
print("send ok")
print(se.is_open)
运行
python xx.py