我使用Python中的脚本通过串行端口以2Mbps从PIC单片机收集数据.
PIC工作在2Mbps的完美时序,FTDI usb串行端口也能在2Mbps下工作(均通过示波器验证)
我发送消息(大约15个字符大小)大约每秒100-150倍,并增加数量(以检查我是否有丢失的消息等)
在我的笔记本电脑上我有Xubuntu作为虚拟机运行,我可以通过Putty和我的脚本(python 2.7和pySerial)读取串口
问题:
这是代码(我省略了大部分代码,但循环是相同的):
ser = serial.Serial('/dev/ttyUSB0', 2000000, timeout=2, xonxoff=False, rtscts=False, dsrdtr=False) #Tried with and without the last 3 parameters, and also at 1Mbps, same happens.
ser.flushInput()
ser.flushOutput()
While True:
data_raw = ser.readline()
print(data_raw)
Run Code Online (Sandbox Code Playgroud)
任何人都知道为什么pySerial需要这么多时间从串口读取直到行尾?有帮助吗?
我想实时拥有这个.
谢谢