LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

read and acquire data at different loops

Solved!
Go to solution

Hello gents,

I need your help to understand how I can read sensor data using DAQ assistance and data log it in two different loops. As shown in attached picture, The vi works as reading accurately, data logging, but when I press stop the vi doesn't stop. I need the producer loop to work in high rate and at the same time I want to data log the current value each 2 seconds. What is the mistake I am doing here. parallel loops.JPG

0 Kudos
Message 1 of 21
(651 Views)

It is hard to debug pictures, especially if some terminals don't even have labels (a very big no-no!).

 

Please attach your VI. Make sure to do a "save for previous" (2020 or below).

 

0 Kudos
Message 2 of 21
(635 Views)

Change your Notifiers to Queues!  I admit that the end Logging on Error is probably bad BUT, writing Notifier data to file is WRONG WRONG WRONG. 


"Should be" isn't "Is" -Jay
0 Kudos
Message 3 of 21
(625 Views)

You have a very common race condition with your Notifiers.

 

What is happening with the Notifier is you are writing a TRUE to the Notifier and then end the loop and close the Notifier. All of this happens 99.99% of the time before the upper loop can read the notification. Since the Notifier is no longer valid, you get a default value of FALSE from the Wait On Notification.

 

In this situation, I would use a Channel Wire to replace both of your Notifiers. With a Streaming Channel Wire, you get an extra parameter for "Final Value?". You can use that to stop your loop instead of an extra notification.

 

Also, your consumer loop should really run as fast as it can. You can use a timer or loop counter to conditionally write your data instead of having a large loop delay.



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 4 of 21
(622 Views)

@crossrulz wrote:

You have a very common race condition with your Notifiers.

 


Not really all that common, nor is it a classic Race.  -1 wired to a notifier tmo means no True tmo can exist.  What we have here is an infinite loop!  Lots of other problems exist in the code!  Concepts of lossy vs lossless data transfer are fundamental to any DAQ measurement and Logging application.   

 

There are just so many features wrong in the OP (picture) that you should not confuse the poster by incorrectly claiming a race condition exists as well as all the other problems.   Jeeze, Tim!


"Should be" isn't "Is" -Jay
0 Kudos
Message 5 of 21
(610 Views)
0 Kudos
Message 6 of 21
(604 Views)

@JÞB wrote:

Change your Notifiers to Queues!  I admit that the end Logging on Error is probably bad BUT, writing Notifier data to file is WRONG WRONG WRONG. 


The queues (in default configuration) would grow forever because they are constantly getting stuffed, but only read every 2 seconds. Channel wires would be a good suggestion. 

 

(The notifier would work if you would close it in the right order. Also only one notifier would be needed, containing a cluster of boolean and numeric.)

0 Kudos
Message 7 of 21
(593 Views)

Hi Albert, I did the cluster for numeric and Boolean, it did the same thing, reading, recording, but stop is not working. I will try the channel wires and see what will happen. 

0 Kudos
Message 8 of 21
(587 Views)

@Omar-Abdelhameed wrote:

See attached. 


What you really want is a "Producer Consumer" loop.  In fact, there is a template for that you can find in by selecting menu>>New.. From Template. 

 

Tim (crossrulz) and Christian (Altenbach) can help you get the code doing what you want it to do!  Unfortunately, you wrote a "highly Featured " snippet of code .

 


"Should be" isn't "Is" -Jay
0 Kudos
Message 9 of 21
(585 Views)

@Omar-Abdelhameed wrote:

Hi Albert, I did the cluster for numeric and Boolean, it did the same thing, reading, recording, but stop is not working. I will try the channel wires and see what will happen. 


Who is Albert? did you move the close notifier after the upper loop or add some simple data dependency to delay closing the notifiers only after the upper loop completes?

 

You could also just stop the upper loop on error, completely eliminating the boolean notifier. Once the notifier closes, there will be an error and the upper loop would stop.

 

altenbach_0-1781540061955.png

 

 

0 Kudos
Message 10 of 21
(581 Views)