11-26-2012 04:30 PM
I usually use a producer/consumer type layout for my block diagram but for this one program I need the following:
A timed loop that runs at 15 ms
Another timed loop that runs at 20 ms
An event structure to capture operator interface
My problem is how to link them together so when "exit" is pressed, all the loops stop and the program exits (back to the main screen).
For some reason I can't get it to work correctly! I've tried while loops around different structures with wait until next (1ms) timers, etc.
Due to proprietary reasons, I cannot post my code...but the structure is exactly how I've described it.
I'm using Labview 2012, Windows 7.
Thanks!
Solved! Go to Solution.
11-26-2012 04:38 PM
Why not use a notifer in each loop to check for the stop condition. After you complete the processing of one iteration of the loop check to see if a notification arrived. If it did, stop that loop. If not, go to the next iteration.
11-26-2012 11:45 PM - edited 11-26-2012 11:46 PM
If you wire the loop name inputs, you can use those names and do a Stop Timed Structure.vi in the user event something like this:
I leave the case of multiple timed loops to you. Ignore the "blank event case, the VI Snippet did that. It actually shows "Stop Button":Value Change.
11-27-2012 04:40 AM
11-27-2012 05:05 AM
@Yamaeda wrote:
Another solution is 3 event structures with timeout as loop time. Make all listen to stop event and you're good to go.
Sorry to contradict.
Here is why:
1) Having event structures in a timed loop is never a good idea
2) Due to the caveats of event structures, such approach is only suggested for very experienced users requiring lots of documentation (who knows who will look into the code later on!).
And two questions for the OP:
Are you running on RT?
Why do you use timed loops at all if not?
If working with a producer/consumer, the producer should send a dedicated shutdown command to the consumer and finish its work. The consumer cleans up most of the resources (except those only used in the producer, which are freed by shutting down the producer) before terminating.
Regarding of your setup (three loops, who is producer? who is consumer? Cascaded producer/consumer architecture?) this can be rather easy or worksome.
Killing the timing source for the timed loop seems rather easy, but is the "big hammer" approach. Feasable? Maybe, depending on the task. Nice? Most probable not.
Maybe you should extend your LV knowledge and start looking into advanced architectures like the Queued Message Handler or, if using LVOOP, Actor Framework.
hope this helps,
Norbert
11-27-2012 08:37 AM
@Norbert
1) I agree using an event structure in a timed loop can be problematic, but i've several times use the event structure as the timed loop (timeout and timeout case) with the ability to react directly to user interaction (the other event cases). 🙂
/Y
11-27-2012 09:03 AM
I'm not using producer/consumer layout this time, that's why I'm asking the question. As for my labview knowledge, I've used queued message handler extensively in other projects. I've worked with labview since v 4.3 and have hundreds of machines out in the field. For some reason this one stumped me...
Other questions:
No, not RT system, not necessary, especially the cost.
I've found that the timeout portion of the event structure doesn't always timeout "on time"...I need a 12 ms timeout to communicate with an item that is pretty time critical. The 15 ms timeout can be a "wait until next ms" timeout, not as critical.
I came up with a few ideas last night (yes, I sometimes dream in G unfortunately) and I'll look at the examples from those who responded. I truly appreciate the input, I have no one here to bounce ideas off of, pretty much on my own (for 23 years).
Thanks!
11-27-2012 09:07 AM
11-27-2012 09:21 AM
@teritask wrote:
[..]I've found that the timeout portion of the event structure doesn't always timeout "on time"...[..]
When talking about "Timeout", better think of something like a watchdog. If something happens, the timeout is reset without occuring.
Windows does not guarantee any timing constraints. With certain configurations, loop times of about 10ms are very reasonable (but not guaranteed!), maybe even down to 1ms.
If you require a determinism of 1ms (maybe less), there is no way around RT or FPGA.
Norbert
11-27-2012 10:23 AM
I found my issue...knew I should have postponed looking at it yesterday after 4 pm...brain kind of stops working about that time!
I was paring down my code so I could post a snippet when I found the issue.
I was feeding the STOP value out of an event in the event structure to stop that loop with all the other events feeding a F. Therefore that loop may see a T to stop, immediately followed by a F when a timeout occurs while the other loops are finishing up. Bad programming, don't know why I chose that method.
I appreciate the suggestions, which I will try a few. I've never used notifiers and they look interesting.
Thanks again for all the help.
Sincerely,
Teri