From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Reading time only when new value is in buffer of device from previous read

Is there a way to have the interface time stamp a reading from the serial device only after the serial device has received a new reading in its buffer. Currently once the interface starts the loop again it reads what is in the buffer even if it is the same reading from the previous run through the loop. Do i need to clear the devices buffer each time i read from it? If so how?
0 Kudos
Message 1 of 4
(3,235 Views)
Hello,

I assume that you are using LabVIEW, please let me know if you're using another development environment.

The serial interface does not support direct time stamping, but you can timestamp data as soon as you receive it into the LabVIEW software buffer by using the "Get Date/Time in Seconds" and "Format Date/Time String" VI's. Of course, this won't be as accurate as
hardware timestamping.

Regarding your problem receiving the same data in separate iterations of the loop, this is probably because your device is actually sending the data more than once. Once you read data from the software buffer, it is gone. The only way that it will come back is if it is again received on the serial port.

Try using the LabVIEW <-> Serial example under the Exampl
e Finder to eliminate possible programming errors. Also, using Hyperterminal will show you for sure whether or not your device is sending out the data multiple times.

If you do need to clear a software buffer attached to a serial port, simply perform a read with the number of bytes you would like to clear.

Hopefully this has helped your understanding of the problem and possible solutions; if not, please let me know by posting here.

Scott
0 Kudos
Message 2 of 4
(3,235 Views)
Thank-you - I have essentially figured out the timing issue - what is causing the problem is one of the hardware devices I am working with, is an old one way counter and updates nearly every six seconds. So might just have to have a delay in my program.

Now I just have to figure out my output files - i am outputting temp vs time and time period vs time - my output files however are outputting the data all in a single column - any ideas. I am also having difficulties getting the time data to sum itself for the results.

Any help would me appreciated.
0 Kudos
Message 3 of 4
(3,235 Views)
A lot of this depends on what sort of report you are generating (text based? Excel?). Without having further information, I'd say check out some of the example programs as you seem to have a rather basic need for general file output. You might also pose this question with more detail over in the LabVIEW forum.

Scott B.
Applications Engineer
National Instruments
0 Kudos
Message 4 of 4
(3,235 Views)