04-05-2013 05:43 PM
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.
04-05-2013 06:49 PM
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.
04-05-2013 08:36 PM
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 .
04-05-2013 08:43 PM
04-05-2013 09:17 PM
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.
04-08-2013 09:49 AM
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.
04-08-2013 10:08 AM
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.
04-08-2013 11:29 AM - edited 04-08-2013 11:50 AM
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.