LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 
Reply

Read & display serial data

Solved!
Go to solution

Hi all,

 

I am using LV2013. I created a VI that reads measurements value and display in a waveform graph. The measurements values are transmitted continuously however to form an image (using a specific algorithm) each frame requires 144 measurement values. The process is repeated to form another image with another 144 measurement values. My questions is: how to check that I will not miss any measurement values? Currently I apply a for loop with 144 iterations. Is this a correct way?

 

Thank you.

0 Kudos
Message 1 of 7
(1,253 Views)

Having a For Loop execute 144 times to be sure you get the 144 data points seems perfectly acceptable.  The only question I have is how do you know that the first of the 144 data points you collect is actually the first?  If the device is sending data continuously without prompting, how do you know it didn't start reading after the first 50 or so data points had been transmitted?

 

You are using the "Bytes at Port" method which is almost always wrong.  What happens if you get 0 bytes?  What if you get multiple bytes representing several values?  You'll get bad data or you'll wind up missing data.

 

Why do you have two loops?  I don't see anything in the 2nd loop but the waveform graphs that could easily be put in the first loop.  I see you have a major race condition problem using a local variable of an indicator to pass data from loop 1 to loop 2.  You can easily miss data that way, or wind up reading the same value twice.  If you pass data from one loop to another, you should use queues and a producer/consumer design pattern to make sure all the data is passed without loss.

0 Kudos
Message 2 of 7
(1,232 Views)

Hi,

Thank you for the advice. I followed your advice and created a simple VI using a fake data comes from random numbers together with queue/dequeue functions. At first I am trying understand the flow and what will be the output. I created 1440 random data which represents 10 frames (144x10) of measurements data. The array data displayed random data with 1D array named 'array'  displayed the 1440 random data, 'subarray [144x1]' displayed the first 144 data which are correct. Again using the for loop I tried to execute 144 times to generate 144 measurement data.However the 1D array from for loop in loop#2 displayed same values in each iterations. This is the part where I get really confusing.Why the same values are displayed from the for loop? Please advice.

 

Thank you 

0 Kudos
Message 3 of 7
(1,187 Views)
Solution
Accepted by topic author Ledang
01-30-2016 12:10 AM

Because you have a For Loop in the 2nd loop that takes whatever element you just dequeued and creates a 144 element array of that.  Why?

 

You don't need the timeout on your dequeue for what you are doing.  It is better if you have the producer loop send a signal to the consumer to tell it to stop processing.

 

See the attached modified VI.

0 Kudos
Message 4 of 7
(1,182 Views)

Hi,

Now I understand why the data display the same number for 144 times. From my understanding the for loop creates a 1D array of 144 measurements data. Anyway thanks Raven for your guide Smiley LOL.

0 Kudos
Message 5 of 7
(1,151 Views)

Hi Ravens,

 

Could you please upload the VI in Labview 2012 version?

I'm facing a similar issue and would like to see the correct vi.

Thanks in advance.

Vanessa

0 Kudos
Message 6 of 7
(421 Views)

Hi Vanessa,

 

here's the solution converted to LV2012…

Best regards,
GerdW
CLAD expired, using 2009SP1 + LV2011SP1 + LV2017 (+LV2018 sometimes) on Win7+cRIO
Kudos are welcome Smiley Wink

0 Kudos
Message 7 of 7
(417 Views)