Is there a way to insure serial readline only reads when there is someething in the buffer?

15 views
Skip to first unread message

DR

unread,
Apr 30, 2026, 10:32:50 PM (22 hours ago) Apr 30
to 'Jon Fear' via weewx-user
I am slowing working towards a live test of a sort of a driver to
deliver a packet to WeeWx.

Basically I have a Campbell Scientific datalogger gathering sensor
readings, and once every twenty seconds it writes a string to the serial
port.

My python 'driver' uses the serial readline to get the string, and it
does once things get going the first pass through.

I have the datalogger running all the time, and when I start my python
code the first pass is always reading a blank, so to speak, and all the
string conversions and such either return empty strings, or error out
with the attempt to float a value which isn't valid, yet.


I got around this for the time being by doing a len() on the readline
input string and only proceeding if the length is >1.


Then all seems to work since none of the splitting of the string into a
list and all has values rather than a blank to work with.

Somehow this seems inelegant and wonder if there is a better way to
approach this?  Despite Googling and reading about serial input methods
and pyserial and Geeks and RealPython I do not seem to find an answer.


Should I just put up with it seeming an odd way to do this and writing
an if...: at the beginning and let it go since it is just the first pass
of the python code reading the serial input buffer and works OK from
then on out?

Dale


Vince Skahan

unread,
Apr 30, 2026, 10:52:56 PM (21 hours ago) Apr 30
to weewx-user
If it works stably why worry it ? Basically sounds like a try/except block.
Reply all
Reply to author
Forward
0 new messages