Python串口的使用比较简单,直接open串口,然后直接Write、Read即可,源码如下所示:
1.打开串口
self.s = serial.Serial(
port='COM1',
baudrate=115200,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE, # STOPBITS_TWO
bytesize=serial.EIGHTBITS
)
2. 读写数据
# write data
self.s.write(data)
# read data
data = self.s.read(1024)
上述读写尽量采用Thread、Queue进行处理,这样更为高效。
博客介绍了Python串口的使用,操作较为简单,直接open串口,再进行Write、Read即可。还提到对读写操作采用Thread、Queue处理会更高效。
3359

被折叠的 条评论
为什么被折叠?



