02-13-2024 04:23 AM
Hi,
I would like to read in the current sent value via the serial port every 10 seconds. I've tried a while loop with the wait block, but that doesn't work, because it still reads out all the values sent, just delayed. However, I only want to read out the value that is available after every 10 seconds. Do you have any ideas how this could work?
Kind regards,
Tim
Solved! Go to Solution.
02-13-2024 04:41 AM
@Tim970 wrote:
Hi,
I would like to read in the current sent value via the serial port every 10 seconds. I've tried a while loop with the wait block, but that doesn't work, because it still reads out all the values sent, just delayed. However, I only want to read out the value that is available after every 10 seconds. Do you have any ideas how this could work?
Kind regards,
Tim
What device are you reading from?
Depending on the communication protocol it uses, there may be a serial command to read out a single value. Repeating this read out every 10 seconds may offer a solution.
02-13-2024 04:52 AM
Hi, it is a measuring device and unfortunately does not have this function.
02-13-2024 05:04 AM
@Tim970 wrote:
Hi, it is a measuring device and unfortunately does not have this function.
Then I think you need to know the sample time of this device: what's the amount of samples returned after 10 seconds?
A crude approach would be to read the data and discard all samples except those corresponding to intervals of 10 seconds.
02-13-2024 06:18 AM
If you don't have control over the device and you are not bothered about data in the port and your intention is to log the data for every 10 seconds.
As already suggested read all the data in the serial port.
Use timer engine to log data whenever it elapses 10 seconds.
02-13-2024 09:21 AM - edited 02-13-2024 09:23 AM
Without seeing your code all we can do is give very general advice and guesses.
My guess is you are doing it wrong.
In general there are a couple way you can do this.
Frankly I tend to prefer #1 because you can still monitor your device between display/logging intervals.
This can be an important safety feature when working with high power devices.
02-13-2024 09:41 AM
@Tim970 wrote:
Hi, it is a measuring device and unfortunately does not have this function.
So how does it work? And what are your true requirements? Would it be beneficial to read continuously and only display/log the value every 10s?
If you want to continue only reading every 10s, then you have a couple roads you can go down.
02-13-2024 10:52 AM
@JimB. wrote:
- If it would be acceptable to return the next received value every 10s instead of the last received value, you could flush the buffer before reading.
I highly advise against using Flush Buffer as it will be somewhat random where in the message the buffer will be flushed. So if you go this route, you are going to need to do at least 2 reads to ensure you get a full message.
As others suggested, the simplest route is to have a loop that does nothing but read the port and it passes the data on through a queue to whoever needs that information (logging loop, state machine, etc.) every 10 seconds.