01-27-2012 06:02 PM
Hi!
I have a main while loop in which I want to tell another while loop outside this one, in a subVI, to do something
I thought i could to this by setting, for example, a bool variable of a cluster, "start polling" = TRUE, in the main loop. Pass a reference to this cluster into the subVI, let the subVI read this value and act from it.. But as you can see in the attachment the cluster in the main loop is updated, but the cluster in the subVI is not.
I'm probably trying to do something in the wrong way, so if some nice soul out there could point me in the right direction 🙂
I guess I could solve this problem by using a global variable, but in the future i want pass more info back and forth between the loops.
01-27-2012 06:26 PM
01-28-2012 01:08 AM
But I want to send data in both directions. This would force me to have 3 queues running (if I don't wanna involve the queue controlling the state machine).
* One that is only used to handle the states in the state machine
* ONe that is used to send data to the poll function
* One that is used to send data from the poll function
Is there no other way?
01-28-2012 08:47 AM
When I posted my first reply it was from my phone so I was unable to look at your project. You made no mention of queues in your post but I see you are in fact using one.
I promise to get to your question if you promise to read my rambling that preceeds the answer.
For a loop to communicate in both directions using queues it requires an input queue and an output queue. If you have multiple channels of communication you can use multiple queues but you don't have to. You can use a cluster as the queue datatype with an element to define the channel.
I like how you use the dequeue. It is a very good idea to put it into a subVI. None of my top-level VIs have queue prims anywhere. All of the initialization, enqueues, dequeues, and release functions (I notice you are not releasing your queue, which you should always do) are in subVIs. Those VIs are either Action Engines or classes. One technique I like to use for communicating between loops is called a Slave Loop. Take a look at the Slave Loop even if you are unfamiliar with OOP. The discussion might still be useful.
You sound concerned about having three queues. I am working on an application that has three dozen queues. It sounds messy but the block diagram of the top-level VI fits on one screen. Same thing for all of it's subVIs. Three queues is very managable and you are starting on the right path by putting the dequeue in a subVI.
Let's get back to your actual question. First of all when you set your Start Polling boolean to true in the subVI, the subVI will exit. I'm sure you know that but the subVI is done running forever because that boolean is wired to the stop terminal of your while loop. You cannot make the subVI start again so Start Polling is more accurately an exit subVI signal.
But Start Polling never goes true. Why it doesn't go true is your real question. The reason is because the cluster in your poll VI is value reference to the internal parameters cluster control on the main VI. The cluster wire on the shift register in your main VI is a separate instance of that datatype and is not connected to the control referenced in your poll subVI. To set the cluster value in the poll subVI you have to change the value of the control. Bundling it into the cluster on your shift register only changes the value of the wire inside of the loop.
I hope this answers your question but I hope you do not use the answer. There are better ways. But at the end of the day you just need to get something done so it is ultimately your decision. Use what you are comfortable with. Just always keep in mind that there are better architectures that you should look into if you intend to write larger applications that are managable.