Python serial port event handler

I'm trying to write some code, triggering an event every time data arrives on the serial port. I am using pyserial but I cannot find any code that works.

the ones i found are like

for True:
    inputb = ord(ser.read(1))
    'Rest of the code'

      

But I'm looking for a way to add an event when a byte has been read using a function like DataReady () or similar function that can only fire an event when valid data arrives

Thank you for your help.

+3


source to share





All Articles