LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to build an array within a master/slave relationship?

Solved!
Go to solution

Hello NI Community,


I am having trouble building an array within a master/slave relationship. I want two arrays to be built for a set amount of iterations once the "Pressurization" button is pressed. (This data acqusition would only happen once per program run). I'm new to Labview so I apologize in advance for my messy layout.

 

I want the slave program of creating the two arrays and analyzing the pressurization slope to happen concurrently with the master program, and the master program to continue to aquire the same pressure data.

 

Is the master slave relationship even necessary here? How do I pass a variable (pressure reading from main once per loop without getting stuck in a nested loop situation?

 

0 Kudos
Message 1 of 8
(3,443 Views)

 I beleive a Producer/Consumer pattern would do this easily. You acquire data in your producer loop, and you can do data analysis/data logging in your consumer loop. You have to use a Queue for lossless data transmission.

 

edit: Some more advices:

  1. Do not use Express VIs for DAQ. Learn how to program DAQmx properly using the low level VIs. Have a look at the many examples.
  2. Your VI is way overcomplicated. Why do you use Flat Sequence Structure? There is no purpose of it here... Also, same for the "Wait until next ms multiple", you connected a 1 msec value to it, it will not do any difference in this case. Maybe you wanted to time your top loop to iterate at 1 second? Then connect 1000 msec to this function in the top loop. The lower loop does not need timing, since it will execute only when the top loop send a Notification/Queue element...
  3. I recommend you to take some of the free training available online. Have a look at the DAQmx and Producer/Consumer examples. If something is problematic, attach your VI here and we try to help. Good luck!

Edit2:

As I see, you need to perform a Linear Fit on your data. How long you wanna run this application? If you build arrays indefinitely, it will become a memory leak after a while...Of course it depends on the rate and iteration number.

Maybe you want to calculate the Linear Fit in a continuous way? In this case I would use a "Point by Point" function with a given buffer size. So you do not need to build arrays, neither no need for shift registers/feedback nodes.

http://zone.ni.com/reference/en-XX/help/371361M-01/ptbypt/linear_fit_ptbypt/
Message 2 of 8
(3,429 Views)

I think what you really want is a Producer/Consumer.  Use a queue instead of a notifier and send the data through the queue instead of relying on local variables.  You can make the data type of the queue a cluster to hold all of the different data you need to send.


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
Message 3 of 8
(3,424 Views)

So would it be best to build my arrays in the producer loop, to be sent to my consumer loop for further processing?  (To create an array, should I use a case structure to simulate the (if pressurization==true & i < numberofmeasurements) then ..insert into array with shift registers?)

 

Also, to send data from my consumer loop back to my producer loop, should I use a local variable?

 

Thank you for your help.

0 Kudos
Message 4 of 8
(3,392 Views)

No, this is not what I've adviced.

As I see you acquire one single data point in the top loop (which should be the producer loop). I hate this Express VI with the "evil" dynamic data, but I guess this is what you want, yes? So you want to measure one single pressure value at once, ok. You can Enqueue this single data point into the Queue, and send it to the Consumer loop. You do NOT need to build any array. You can continuously calculate Linear Fit coefficients for a given length using the Point_by_Point Linear Fit VI. So your array is "hidden" inside this VI.

 

Edit1: "Also, to send data from my consumer loop back to my producer loop, should I use a local variable?"

Why do you need to send data from the consumer loop to the Producer??? Do not use local variables when you do not need them. In your attached VI it is also wrong to use that many local variables, like the "Bottle Pressure". Send this value via the Notifier, or much better, as we said, a Queue. Just a moment, I create a small example...

0 Kudos
Message 5 of 8
(3,380 Views)

Yes I want to use a linear fit for about 20 datapoints. I will try the point by point continous linear fit. 

Also for the local variable question, I want my producer loop to respond to the slope data point I acquired. (the interval the slope is in will be associated with a method 1,2,3--> which will be used to energize a solenoid valve for an amount of time)

 

Thank you Blokk!

0 Kudos
Message 6 of 8
(3,359 Views)
Solution
Accepted by topic author smat123

Here is a small example, only to show some idea (many things are not optimal in this example!!). Based on your VI which you attached, you miss many basic concepts from LabVIEW, you should go through some online training.

 

ProducerConsumerData 1_BD.png

0 Kudos
Message 7 of 8
(3,357 Views)

Also for the local variable question, I want my producer loop to respond to the slope data point I acquired. (the interval the slope is in will be associated with a method 1,2,3--> which will be used to energize a solenoid valve for an amount of time)

 

Thank you Blokk!


No problem, but then you could interact with your solenoid valve from the Consumer loop! Will be much easier. If your DAQ rate is not too high, it should be totally OK from your Consumer loop... So only collect pressure data in the top Producer loop, and do EVERYTHING else in the Consumer loop. I guess a maximum of 1 second (you have a pressure DAQ rate of 1 sec, yes?) delay for your solenoid valve should not be a problem?

0 Kudos
Message 8 of 8
(3,353 Views)