LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Notifies and/or Queue to control Multiple loops.

Hi,

 

For my application, I need to work with multiple while loops.

So what I thought could be a good idea is to create one state Machine like structure and then use a notifier to notify all other loops about the state. But I face some problems. I create an example vi. What I want, is, Main mode will start running. When I click the boolean button, the main mode will stop and work mode will run. Work mode runs for some time and then stops. When it stops, Main mode starts again. I seem to have something like that. But not quite. Looks like I have some problems about waiting till one of the work finishes! (Work mode starts before the Main mode stops and so on..). I tried using wait on notification function, did not work. I am not sure how to get around this problem. Please help.

Download All
0 Kudos
Message 1 of 8
(3,181 Views)

If you put a millisecond timer with an indicator in each of your consumer loops, you'll see that, before you make the boolean true, your main mode loop is going a lot slower than the work mode loop.  This is because, when the main mode case is active in all loops, the main mode loop has more tasks to do before that loop rotation can be complete.  Each loop only recieves a new notification from the notifier when it has completed it's current task/rotation--in other words, not until i starts the next rotation will it recieve that new notifier.  Therefore, I think because your work mode loop is going much faster when the state machines' states all all in main mode, it gets the notifiers a lot sooner than the main mode loop, and gets the noifiers to stop mainmode and initiate work mode before the main mode loop gets the notificatin waiting for it on it's next rotation to stop main mode.

0 Kudos
Message 2 of 8
(3,168 Views)

Hi WyoEng,

 

Thanks for your reply. I understand your point.

So how can I make sure that the notifier reaches all the loops together? Like, the notifier would wait until all the work in Main Mode finishes and then deliver the notification (or something like that..) to all the loops all at once .

0 Kudos
Message 3 of 8
(3,156 Views)
You should not be using the Notifer Status to see if you have received a notification you should be using the Wait for notification. Will only one of your tasks be running at a time? If so, I am not sure the notification is the right approach. The notification will be broadcast to all listeners. If you just need to activate a single process you should have distinct messages for each task. Have you considered using the event structure and user events? The issue you run into using the notification status is that it returns immediately. The wait on notifier will halt the task until a notification is received. Using user events will do the same thing as will queues. However given your description I think user events would be a good approach. You could target your events to specific tasks. Using a notifier every task will receive the notification and you will need code to filter out unwanted notifications. That is all your tasks will receive it and all will have to determine if they need that notification.


Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 4 of 8
(3,154 Views)

Hi Mark,

 

 No I am not always runnig one loop for each broadcast. This is an example that I have created in order to deal with my actual problem. In the actual problem, there are many different loops and some of them will work together on each notification. I was also trying to use wait for notification in the consumer loops. It does not seem to do any good. 

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

babu726,

 

I believe there is an option to sync up loops, so maybe you can use something like that with or without notifiers or queues.  There is a vi in LabVIEW called "syncronize timed structure starts".  Perhaps you could link the multiple loops this way, and only notify one of them, or somehow trigger it to start (if not with a notifier, then maybe having one in the main event structure), and use that to set off the others.

0 Kudos
Message 6 of 8
(3,105 Views)

I recently came accross this article on using Queues in a producer-consumer architecture.  Would something like this work for your application?

 

http://expressionflow.com/2007/10/01/labview-queued-state-machine-architecture/

 

Since you state that you use separate loops together to process a function, the Queue might be a good alternative to control data flow.

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

follow mark's advice...your program is way more difficult than it should be. producer/consumer architecture is quite difficult to understand if you have had no formal training of LV(core 1/2/3)...  

 

what exactly do you want to do? write a step by step procedure of how you want your program to run and what is required for the user to do...ask yourself, do you require sequential or parallel operations?

 

a state machine is a wonderful style to master for sequential operations! and it seems to be what you really need from looking at your program as you have very limited controls. producer/consumer steps this up for parallel executions of multiple loops and sub vi's and giving the user lots of control interface to the vi's. Smiley Wink

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