LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Only read in every 10 seconds with serial port

Solved!
Go to solution

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

0 Kudos
Message 1 of 8
(394 Views)

@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.

0 Kudos
Message 2 of 8
(383 Views)

Hi, it is a measuring device and unfortunately does not have this function.

0 Kudos
Message 3 of 8
(371 Views)

@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.

0 Kudos
Message 4 of 8
(355 Views)
Solution
Accepted by topic author Tim970

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.

----------------------------------------------------------------------------------------------------------------
Palanivel Thiruvenkadam | பழனிவேல் திருவெங்கடம்
LabVIEW™ Champion |Certified LabVIEW™ Architect |Certified TestStand Developer

Kidlin's Law -If you can write the problem down clearly then the matter is half solved.
-----------------------------------------------------------------------------------------------------------------
0 Kudos
Message 5 of 8
(338 Views)

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.

  1. Constantly receive serial data, display and save every 10 seconds
  2. Check for, receive, save, and display data every 10 seconds

 

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.

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 6 of 8
(309 Views)

@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.

 

  • If the device just outputs a continuous stream of data then reading and parsing everything for the last 10s is what you'll have to do. You don't really need the Wait function. I'm not sure how you are determining the number of bytes to read right now, but just set it to a sufficiently large number and set the read timeout to 10s.
  • If the device uses line feeds, carriage returns, or some other character to serve as a terminating character then configure the serial session to use the terminating character and perform multiple reads discarding all but the final one.
  • 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.
0 Kudos
Message 7 of 8
(297 Views)

@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.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 8 of 8
(283 Views)