11-23-2012 07:05 AM - edited 11-23-2012 07:07 AM
Hi all,
I have a VI that allows to run two tasks A and B. The tasks are always run one after the other, never at the same time, no matter the order (A->B or B->A can happen). Usually I use notifiers to stop my tasks and here I wanted to use the same notifier to stop tasks A and B since (again), they never run at the same time. My problem is that when task A receives the notification, it stops, task B starts (so far so good) and stops immediatly (bad !) because it receives also the notification that made A stop.
I attach a small VI reproducing the problem.
In my case, setting "Ignore previous" input to True in both tasks doesn't help because in that case all notifications seem to be ignored...
Any idea how I can make it work ? I was thinking that my task B would never receive the notification since A had already received it...
Thanks !
Solved! Go to Solution.
11-23-2012 07:55 AM
Hi Tycho,
Notifiers work as demultiplexers, thus the behavior of your code is not strange ; it's just the expected one : once the notifier is trigered, the same "True" message is sent to both loops and they stop !
But your code doesn't correspond to the situation you describe : both loops (tasks) run simultaneously ; that's why they receive the same notification !
What do you want to do : do you always want task B to start immediatly when task A stops, and vice-versa ? Only once or in a loop ?
Best regards,
HL
11-23-2012 09:14 AM
Hi HL,
In the example I sent, the loop on the right starts only when the first one is finished, because it waits for the error and notifier wires. The loop with the event structure runs in parallel to fire notifications when I press the button.
What I want to do is this:
+ I have a data acquisition that can run in two modes,
+ these two modes correspond two the tasks I called A and B in my examples,
+ if the data acqusition is running in mode A, when I hit a switch to go from task A to task B, I stop task A with the notifier and starts task B. My problem is that the notifier also stops task B. This is what I show in a simpler way in my example.
Cheers,
T
11-23-2012 09:23 AM
Hey, I just discovered the VI "Cancel Notification".
I'm going to try that !
11-23-2012 09:44 AM
Oups ! Sorry, I didn't notice the wires between the top loops 😞
In that case, it should work if you wire "True" to "Ignore previous" in the right one : a first notification stops the left loop and starts the right one, but you'll have to modify the bottom structure to be able to send a second notification to stop the right loop.
HL
11-23-2012 10:43 AM
Actually "ignore previous" does not work properly because in my application (unlike the small example I sent), I can have A->B or B->A. It could work if I had always the same order.
If I call "Cancel Notification" at the end of A task and B task, it works perfectly.
Cheers,
T
11-26-2012 10:00 AM
WHy not implement this using a state machine. It sounds like your tasks are mutually exclusive so they can reside in a single state machine. You may also get more code reuse since there is a likely chance that you can share some states between the tasks.
11-26-2012 10:33 AM
Hi,
Actually, I'm using a queued state machine and each of my process A and B correspond to a specific state.
The notification is used to stop both A and B. The problem I had was when stopping A and proceed immediatly to B. The notification was still "on" at the start of B and B was stopped immediatly after it started...
The problem is solved when I use "Cancel Notification" and the end of A and B.
Cheers,
T