LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

"Parallel" process

Solved!
Go to solution

I don't think I ever got this answered..I'm running a functional test  (LV2014..Win 7..DAQ6229)  In the functional test.vi is a flat seq structure.  In each of these seq's is a subvi... subvi1 then subvi2 etc.  Each of these subvis I use the DAQ to measure DIO/voltages...etc. to do my UUT testing.  Is there a way in ethier the functional test.vi or the subvis to monintor a boolean which stops the functional vi?  Just looking for a way to have the DAQ running its thing...running the test ..and monitor a door switch  ( the boolean) so that if the user opens the door to the test set it stops the test and turns on a Software LED that I've put on the front panel GUI of functional test.  I know how to implement the boolean..I know how to implement the functional tests.   I just don't know how to combined them so that they are both running simutaneously.

Thanks..

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

Sounds like what you really need here is a state machine.  Each step in your flat sequence structure should be each their own state.  You can then add a state for checking your door switch.  With this setup, you can just check the switch after each step.


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 2 of 8
(3,801 Views)

There are two questions here.  One is "How do I get an immediate response to a change, either to a control or to an instrument reading?", and the other is "How do I synchronize the activities of two parallel processes?"

 

The first can be handled by an Event structure residing inside a While loop.  This is something that patiently "waits" for one or more of the Events it is programmed to recognize.  These are typically changes in the value of a Front Panel control, or "signalling changes" to a LabVIEW control or indicator (this means that you change the value in LabVIEW, but "signal" that the value changed).

 

There are numerous ways to get two parallel processes to exchange information.  If you want to control the second process (such as to stop it), you need one or more "points of intervention".  Unfortunately, if you have your process-to-be-controlled structured as a long, single sequence, figuring out an intuitive way of "interrupting" it can be tricky.

 

One thing you can do (given your existing architecture) is to look at each of the sub-processes (which I gather reside in sub-VIs).  Is there a point within them that, if you had a "Stop" VI that returned a True value, would cause the sub-process to immediately exit, and that if Stop were true when it started, would again cause it to exit?  [This is sometimes called a VI Global or a Functional Global Variable].

 

If this is the case, write yourself a Stop VI that contains a While loop with an uninitialize Shift Register holding a Boolean value (and initially False, by default).  Wire the output to a Boolean Indicator called Stop, with a Boolean input called "Set Stop".  Inside, put a Case statement such that if Set Stop is ever True, it sets the Shift Register (and thus Stop) to True.

 

In your Event structure, if a Stop condition appears, call the Stop VI with True wired to Set Stop.  In each of your sub-VIs, call Stop in such a way that if it ever becomes True, the sub-VI exits (doing a safe shutdown, if necessary).

 

Note that you can have multiple Stop VIs sprinkled around your code, and even within a sub-VI -- you need to find the "vulnerable" points that are accessed sufficiently frequently to allow Stop to have an effect.

 

I'll leave it to others to discuss restructuring the entire top-level program (a single sequence is not a good way to do this, if for no other reason than it is absolutely inflexible ...).

 

Bob Schor

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

You could have the SubVI's be registered to respond to an event themselves, for example going to a defined stop state (rather than Bob_Schor's suggestion of having the top level VI respond to the event by placing a flag in a shared location and then polling this flag in or in-between SubVI's).

 

For example:

 

Top Level VI:

 

Top_Level_VI.PNG

 

SubVI:

 

SubVI.PNG

 

However, this still won't respond immediately if you have actions in some state that take a long time before the next loop iteration in a SubVI.



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

This is more of the way I thought of implementing it.  Having a hard time gasping the subvis being events themselves.  Once the user selects functional test, I want each subvi to run w/o interaction from the user.  My understanding event structures is they wait for a mouse click for example.  Can event structures execute subvis ( in my example) 1, 2, 3 etc one after another w/o user interaction?

0 Kudos
Message 5 of 8
(3,750 Views)
Solution
Accepted by topic author Clint1000

In my example, you want to run SubVI 1 and SubVI 2 sequentially in a Sequence Structure (actually completely unnecessary when wired as it is in my example, since sequential operation is enforced by dataflow), but you want either of them to be able to respond to a door switch event.  The door switch is modelled as a Boolean control ("Door Switch") on the Front Panel of the Top Level VI.

 

Let's say for example that you were halfway through running SubVI 1's actions (it has a state machine case structure defined in its Event Structure's Timeout diagram) when the door switch is opened (in this model, the Door Switch Boolean control in the Top Level VI is pressed).  A Value Change event is raised, which is enqueued in the event registration that we made in the Top Level VI.  Because the Event Structure in SubVI 1 has this event registration wired to its dynamic terminal and has a diagram assigned to handle the event, that diagram executes the next iteration of its internal while loop.  That diagram sets its next state to be a Door Switch E Stop action.  On the next iteration of its internal while loop: It executes the Timeout diagram of the Event Structure; then executes the Door Switch E Stop diagram of the contained state machine case structure; which takes care of any shutdown / cleanup that needs to happen, sets an error, and terminates the while loop.  Now SubVI 1 returns, SubVI 2 executes but does nothing because of the error from SubVI 1, then we return to the Top Level VI and finish execution.



0 Kudos
Message 6 of 8
(3,730 Views)

thanks..I'll give that a try.

0 Kudos
Message 7 of 8
(3,712 Views)
OK, first thing is you need to get rid of the sequence structure (like Sir Tim) told you. You will never get to where you want with that in the way.

Next, you need to get comfortable with the idea of parallel processes communicating with each other using signalling structures like events, queues, notifiers or FGVs.

Finally, never pass an event reference between subVIs, it may work in limited cases, but it leaves too many openings for problems.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 8 of 8
(3,703 Views)