I'd like to send a monitoring information (temperature) to a serial receiver periodically. The problem is I don't know if there is any monitoring service (serial receiver) and how fast it is reading. I only need the latest value. The problem is that serial.write will block if the buffer is full. If I skip writing if the buffer is full, a receiver will only get old data on the first connect. How can I replace data in the buffer or make sure there is only one dataset in the buffer?
1 Answer
The problem is that serial.write will block if the buffer is full.
Only until the bytes get sent out through the TX pin.
If I skip writing if the buffer is full, a receiver will only get old data on the first connect.
No it won't. There is no "old" data.
How can I replace data in the buffer or make sure there is only one dataset in the buffer?
You don't need to.
You are showing a fundamental misunderstanding of how serial works. When you send data it just twiddles the TX pin in the right way with the right timing. If there is something connected to it that understands that twiddling at the speed it's being twiddled then it interprets it as serial data. If there's nothing to see that twiddling it still twiddles. The "blocking" is only if you try and send more data than the serial port can physically send out in the time you're sending it.
If a serial port transmits in a forest and there is no one there to hear it, yes, it still makes a noise.