Hi, I’m looking for help on how to trigger an action when data is received on a serial port. I’ve got a sensor that reads the serial port successfully, but if I understand correctly, a sensor polls the source at a specific interval. Is there any way to cause an action to be performed as soon as data appears on the port as opposed to polling?
ok, some progress, but not much. I can’t seem to get the serial sensor to read the data from the serial port, and I think it’s because the data I’m reading does not have a new line character. The lines are all terminated with a ‘\r’ but not a ‘\n’. If I’m right, is there any way to fix this?
I recall another post where the lack of a terminating newline was the reason why the data wasn’t received. In that particular case, data was transmitted from an Arduino. The person had access to the source code and simply modified it.
Unless you have the ability to modify how the information is transmitted, I don’t see how you can get around the requirement for a terminating newline.
It uses the readline() method which expects a newline to serve as EOL (end of line).
To meet your requirements, it would have to forego using that convenient method and read the received data, one byte at a time, into a buffer until the desired EOL is reached (a carriage return in your case). Then the buffer contents are read and flushed.
If you are handy with python, you can alter the code yourself. If not, you can submit a feature request but be aware that it may never be fulfilled (they’re not on any roadmap and only get done if they attract a developer’s attention).