05-01-2015 06:01 AM
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..
Solved! Go to Solution.
05-01-2015 06:50 AM
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.
05-01-2015 06:52 AM
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
05-01-2015 09:35 AM
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:
SubVI:
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.
05-01-2015 10:17 AM
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?
05-01-2015 11:56 AM
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.
05-01-2015 01:07 PM
thanks..I'll give that a try.
05-01-2015 01:12 PM