python串口数据接收中的事件处理程序

Vic*_*gas 5 python events serial-port

我试图编写一个代码,每次在串行端口中接收到数据时都会调用一个事件。我正在使用 pyserial,但找不到有效的代码。

我发现的就像

for True:
    inputb = ord(ser.read(1))
    'Rest of the code'
Run Code Online (Sandbox Code Playgroud)

但我正在寻找一种在使用 DataReady() 或类似函数读取字节时添加事件的方法,该函数仅在有效数据到达时才触发事件

感谢您的帮助。