LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Serial data recording and sampling

Hello,

I developed this program to collect signals from 3 serial devices (pulse oximeters) and 1 voltage signal from a gas analyzer. The point of the program is to display the data from the devices in real time and also save the data to a file.  The problem is when I review the data in the saved file it looks like the sampling rate is changing while running the program i.e. it is not recording at a constant rate throughout the file.   I think this has something to do with the producer/consumer loops and the fact that each of the devices outputs data at different rates.  I would like the program to record data into the file at 1 sample per second but I am not sure how to do this.  When I put a wait function into the producer loop it just creates a huge data lag.  I don't mind if I miss some data from of the devices at higher sampling rates.  I just want the program to record whatever the output is of the devices every second.  Thanks!

Download All
0 Kudos
Message 1 of 6
(151 Views)

Hello, @Koa123.

 

     Thank you for including your code.  However, many "more experienced" LabVIEW Developers, myself included, do not update our LabVIEW licenses annually.  We often recommend that you "Save for Previous Version" and specify, say, LabVIEW 2019 or 2021 (both of which I have on my work PC).

 

     When saving data at the rate of 1/sec, you should not need a Producer/Consumer design.  Can you arrange your Data Acquisition from your three Pulse Oximeters and your Gas Analyzer to output data at 1 Hz?  If so, you could just acquire and write once per loop.

 

     If the data rates are not that "nice", you could use a Producer/Consumer pattern to "filter" the data (say by averaging all the data that arrives in a second) and, again, send 4 channels at 1 Hz into your "Write" function.  There are probably other ways to do this, but without seeing your code (which I can't open because I don't have the Latest Version of LabVIEW), I can't be more specific.  But other talented LabVIEW users will probably be able to help you ...

 

Bob Schor

0 Kudos
Message 2 of 6
(146 Views)

Hi Bob,

I cannot change the output of the serial devices to 1hz; two sample at 1 hz and another samples at .5 hz.  Here is my code!

Thank you,
Koa

0 Kudos
Message 3 of 6
(139 Views)
0 Kudos
Message 4 of 6
(138 Views)

Your code layout is pretty messy and could really do with some cleanup or being put into subVIs, but if I look past that...

 

It looks like your devices are only set to read, never to write, indicating that they probably just constantly output their data.  Is that correct?

 

If this is the case, do you have any sort of external synchronizing going on or do they all just create their outputs "whenever"?  I'm guessing you just get the outputs "whenever" and have no option to sync them up via some sort of hardware control.

 

What I would suggest you do is to change your queue data type from an array of strings to a cluster containing your array of strings, plus a time stamp.  Make sure you get the time stamp right after the "VISA Read" returns, so you get the time stamp the data arrives and not the time stamp at the start of the while loop iteration.

 

Then, adjust your data type so that instead of waveforms, which must have a constant delta-time between each point, save your data as arrays of graphed points with the X coordinate being the time stamp and the Y coordinate being the data taken at that time.

 

Finally, when you want to save your data, choose a start, end, and delta time, and then for each single point in time you want to save, interpolate between the two points in each array based on their timestamps compared to the time you are "syncing up" each saved data point to match to.

 

Also as a side note, just to catch edge cases, I would set all of your serial read loops to not enqueue anything on the first iteration.  There is a small but nonzero chance that at some point you will start listening for serial data when the device is in the middle of a transmission, so you will only get half a packet of data and it will ruin your parsing and give you junk data for the first point.

0 Kudos
Message 5 of 6
(116 Views)

I agree with Kyle's observation that getting the Serial data "synched" could be a problem.  I notice you seem to be taking data in at a rather faster rate than you want to save it (which, if memory serves, was once/sec).  You have 4 data streams, three Serial (and thus largely "unclocked" and one DAQmx (and that's the clock you should use) -- think about how you might synchronize them.

 

I noticed a MathScript (that might not be the correct name -- I never use them) that calculated SaO2 from inO2 and AA.  The LabVIEW code, below, I think does the same thing, but without the parentheses, without raising things to the -1 power to indicate a division, and without taking up so much Block Diagram real estate (it would take up even less if you made this a sub-VI -- it would be 32 x 32 pixels, could have an Icon that says "Calc SaO2" so you'd know what it did, could even have Error In and Error Out in the lower corners to warn you if you tried to divide by 0.

koa123 Formula.png

 

Bob Schor

0 Kudos
Message 6 of 6
(63 Views)