LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

loop in subVI

Hi everybody,

 

For my project, I have to read some flow data from 3 different flowmeters. I already wrote the VI for 1 flowmeter to use it as sub-VI, this work perfectly alone. Of course in the main VI I will have to be able to read the data while mesuring and to stop it when it is finished.

 

Is the best solution to use global variable? Or as here, to use the RefNum ( http://forums.ni.com/ni/board/message?board.id=170&message.id=494719&query.id=309152#M494719 ). In the second case, is it possible to have a tutorial? I did not find it easly on this site, and I am a real noob (I understand the loop, timing, boolean stuff, but I do not everything regarding the RefNum, and the two "(strict)" boxes) 

 

I use LabView 8.0!

 

Attached are the VI's

 

Thank you for any advice.

 

Renaud Isaac

Download All
0 Kudos
Message 1 of 15
(5,810 Views)

Hi renisaac,

  You have defined a subvi,in that subvi there is a while loop with stop if true condition and you want to control it from the main vi...one thing i am going to tell you if a while loop is running you cant pass values to that until the while loop stops...So my suggestion is better replace that stop button in the subvi with a true constant...So your subvi will run only once ..So keep that subvi in the main vi while loop..in that way you can run the subvi as many times as possible untill you press the stop button...I think you need to change the subvi program also.

 

 

T hanks and regards,

srikrishnaNF

Regards,
Srikrishna


0 Kudos
Message 2 of 15
(5,796 Views)

Thank you for your message srikrishnaNF,

 

Indeed, I know that I can not exchange data with the subVI, and that is exactly my problem. The problem with your solution is that I will have to open and close the communication with the flow DDE server at every measurment. I do not know if this will cost a lot of performance, but it is not a "nice" solution.

 

After looking still more in detail the RefNum, I have the impression that a global variables should be more efficient, one for stoping all the subVI, and one by sub-VI chart I need, hence 7 for the whole project.

 

Of course if there is a nicer way to use the data form the running loop in the subVI, or another good solution, I am really interested!

 

 

Renisaac

 

0 Kudos
Message 3 of 15
(5,789 Views)

Hi,

  Then do in this way...put three flat frames..first frame is for opeing an connection ,second frame is for data collection(your subvi will be present in this frame) and in the last frame close the connection..Do a small change in the program of the subvi as shown in the attachment..

 

 

Thanks and regards,

srikrishnaNF

Regards,
Srikrishna


0 Kudos
Message 4 of 15
(5,778 Views)

@Renisaac wrote:

 

Indeed, I know that I can not exchange data with the subVI, and that is exactly my problem. [...]

 


You most certainly can exchange data with the subVI!  Look at Queues and Notifiers; they're the easiest ways.

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

0 Kudos
Message 5 of 15
(5,759 Views)

yes there are queues, notifiers which are efficient and easy to use....

you can also use the refnum of the stop control from your main VI and use a value property node to it in your subVI to stop the subVI loop when you click on the stop button in the main VI.

0 Kudos
Message 6 of 15
(5,757 Views)

I highly encourage using queues to pass variable values between subvi's and main.  I also highly encourage using refnums to cause the stopping of all loops.  I highly discourage using Globals.  You will run into a race condition.  There would be no way to know if you have an old value or an updated value when reading the global from main or another subvi.  If several subvi's are running in parallel, and your main is reading the global, how can you be sure that the read has happened after a write.  Also, one subvi could overwrite the global that was just written by another subvi.  Data will get lost.  Don't use globals.  With queues, the data stacks up and nothing gets lost.

 

- tbob

Inventor of the WORM Global
Message 7 of 15
(5,726 Views)

While I'm as fond of queues as the next programmer, I think a notifier is a better solution for this, assuming you have more than 1 subVI which you need to stop.

 

The reason is that with the way a queue works, the data is dequeued only in one place.  So, only 1 subVI will grab the "stop" value off the queue, and terminate.  Of course, that subVI can send another "stop" command previous to termination, which the next subVI will grab, etc...if you need to sequence the order in which your subVIs "stop" , then using a queue is a better way to go.

 

If you just want them to stop all at once when you press the main VI's "stop" button, though, it's simpler to use a notifier.  With a notifier, however, every loop which is waiting on the "stop" notification will receive it when it's sent.  You press your "stop" button and send a notifier, and every subVI which is waiting on that notification will stop.

 

It's just simpler.

 

My two cents!

d

0 Kudos
Message 8 of 15
(5,698 Views)

DianeS wrote:

While I'm as fond of queues as the next programmer, I think a notifier is a better solution for this, assuming you have more than 1 subVI which you need to stop.

 


I was refering to queues to pass data.  I agree with you that notifiers would be suitable for stopping the loops.  For this action, I would usually use a control reference.  However, maybe notifiers would be a better choice.

 

Any comments on which is better to stop multiple loops?  Notifiers or control references or (gasp) Local Variables?

 

- tbob

Inventor of the WORM Global
0 Kudos
Message 9 of 15
(5,680 Views)
There are several excellent threads on the subject of stopping multiple loops with a single control...here is my favorite one, but there are others.  Do a search on "stop multiple loops" and you should get a lot of hits.
0 Kudos
Message 10 of 15
(5,662 Views)