参考:
1、https://pyserial.readthedocs.io/en/latest/pyserial_api.html?highlight=flush
安装:
需要安装Pyserial
pip install Pyserial
成功后用,在python IED中测试,import serial
打开:
>>>ser=serial.Serial("COM5",115200),
如果打不开,检查测试环境
发送:
>>>ser.write('hello,serial test'.encode())
17
发送测试(如果返回字节数,说明返回成功),这里需要转换一个编码为字节
接收:
>>> print(ser.readline())
b'abcdefg\r\n'