LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Diagram Layout

Solved!
Go to solution

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!

0 Kudos
Message 1 of 11
(2,856 Views)

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.



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 2 of 11
(2,854 Views)

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:

 

stop loop.png

 

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.

0 Kudos
Message 3 of 11
(2,835 Views)
Another solution is 3 event structures with timeout as loop time. Make all listen to stop event and you're good to go.
G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 4 of 11
(2,815 Views)

@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

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 5 of 11
(2,807 Views)

@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

0 Kudos
Message 6 of 11
(2,782 Views)

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!

 

 

0 Kudos
Message 7 of 11
(2,776 Views)
That's why we're here Teri. 🙂
G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 8 of 11
(2,770 Views)

@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

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 9 of 11
(2,765 Views)
Solution
Accepted by topic author teritask

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

 

 

0 Kudos
Message 10 of 11
(2,745 Views)