LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Suggestions for using many event structures in one top level VI

Solved!
Go to solution

Hello all,

 

I have a rather large VI which has many event structures (over ten) each doing a different thing (controlling different parts of an experiment) each is surrounded by its own while loop with a wait of 1000 ms.

 

Is there a more elegant way of handling many event structures in a top level VI, I am thinking about  implementing the following:

http://digital.ni.com/public.nsf/allkb/A882E27D1D7A949386256E0D0066B91A

 

I know this won't solve the many while loop problem but it will reduce the block diagram a fair amount.

 

Any suggestions would be greatly appreciated.

 

Cheers all

0 Kudos
Message 1 of 8
(3,235 Views)

@QuantumPenguin wrote:

Hello all,

 

I have a rather large VI which has many event structures (over ten) each doing a different thing (controlling different parts of an experiment) each is surrounded by its own while loop with a wait of 1000 ms.

 

Is there a more elegant way of handling many event structures in a top level VI, I am thinking about  implementing the following:

http://digital.ni.com/public.nsf/allkb/A882E27D1D7A949386256E0D0066B91A

 

I know this won't solve the many while loop problem but it will reduce the block diagram a fair amount.

 

Any suggestions would be greatly appreciated.

 

Cheers all


LOL, my responses range from "What a brilliant idea!!!" to "What were you THINKING???" but we'll never know until you upload the actual VI you are talking about.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 2 of 8
(3,229 Views)

Why would a loop containing an event structure need a 1000ms wait? While this will throttle the number of event that can be handled in a give time, it could also inflate the event queue.

 

All this seems rather weird and I am sure there are better alternatives. Can we see some code?

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

I know It would be far more helpful to upload a VI, but it is ridiculously large I'm unable to upload it. I can upload an image? Essentially the VI consists of 13 event structures, each surrounded by its own separate while loop. The code inside each event structure is pretty varied, some is very simple, others have very large amounts of code - which could be VI's in their own right.

 

The main problem is that the block diagram is now ridiculous, and also I just hate the solution. There must be a less crude method than what is currently used. 

0 Kudos
Message 4 of 8
(3,221 Views)

While the VI would be better, of course, I think a picture of the BD would help somewhat.  Fire away!

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 5 of 8
(3,201 Views)

@QuantumPenguin wrote:

I have a rather large VI which has many event structures (over ten) each doing a different thing (controlling different parts of an experiment) each is surrounded by its own while loop with a wait of 1000 ms.


General rule: A VI should only have 1 event structure.  It really sounds like you need to re-architect this code.  Have you looked into a Queued Message Handler (often incorrectly called a Queue State Machine and very similar to a Producer/Consumer)?  The idea is that you have 1 loop that handles UI events and the processing is passed to another loop via a queue.  That second loop just reads messages and does whatever it needs to with the message.  It gets a little better.  You can many QMHs, each doing their own job.  So you can make your big, giant VI into many VIs that run in parallel and talk over Queues and/or User Events.  This is actually called Actor Oriented Programming, so you might want to have a look at the Actor Framework as well.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 6 of 8
(3,151 Views)
Solution
Accepted by topic author QuantumPenguin

@QuantumPenguin wrote:

Hello all,

 

I have a rather large VI which has many event structures (over ten) each doing a different thing (controlling different parts of an experiment) each is surrounded by its own while loop with a wait of 1000 ms.

 

Is there a more elegant way of handling many event structures in a top level VI, I am thinking about  implementing the following:

http://digital.ni.com/public.nsf/allkb/A882E27D1D7A949386256E0D0066B91A

 

I know this won't solve the many while loop problem but it will reduce the block diagram a fair amount.

 

Any suggestions would be greatly appreciated.

 

Cheers all


While my implementation of that approach is slightly different, I agree with that approach. Doing so lets me break up my application into separate parts for each type of instrument I am using.

 

One example top level diagram looks like this.

A1.png

 

and a typical sub-VI looks like this.

A2.png

 

Works great, easy to maintain, and re-use code it easy to harvest.

 

Ben  

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 7 of 8
(3,138 Views)

@QuantumPenguin wrote:

 

I have a rather large VI which has many event structures (over ten) each doing a different thing (controlling different parts of an experiment) each is surrounded by its own while loop with a wait of 1000 ms.

 


Quantum,

     I'm guessing that when you say "a rather large VI", you mean one whose Block Diagram does not fit on a single (even a 27") monitor screen.  That's your first problem -- all of your VIs should be relatively modest in size (which is most easily accomplished by using lots of sub-VIs to encapsulate functionality and using design patterns like the Queued Message Handler to manage program flow).

     You don't say (and we can't see) how the Event Structure communicates with the rest of the program.  There is something to be said for having a single Event Structure, and letting it run "full speed" (since it takes no CPU time if there are no Events, having a Wait to slow it down doesn't make a lot of sense).  Note that if by a "Wait of 1000 msec" you mean you programmed a TimeOut Event for 1000 msec, that's another story, since that (in principle) won't hamper your loop responsiveness.

 

Guess we really need to see this "interesting" VI to be of more help.

 

Bob Schor 

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