LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to get subVI to select state of main VI

I have a main state machine that calls a subVI for each state.  The main VI works but it didn't offer a way to abort out of a subVI.  I figured out how to incorporate a control refnum to use a stop button on the mail VI to stop the subVI.  M problem now comes that if the user aborts the subVI using the stop button on the main VI, I would like to send the state machine to an aborted state on the main VI and not the next state.  I thought I would do this with a simple select function but that didn't work.  After spending much time reading the forums I'm not sure what direction I should go.  Is there a simple way to accomplish this, or should I be learning how to do it with a queued state machine?  I have never tried to program a queued state machine so I'm not sure how to get started with it.  I have attached the test VI I have been playing with all week.

 

Thank you for the help.

Danny
Download All
0 Kudos
Message 1 of 5
(2,606 Views)

I posted the wrong version of of the subVI.  Here is the base version.  Sorry about that.

Danny
0 Kudos
Message 2 of 5
(2,592 Views)

I think you are going to have a confusing architecture with a subVI having a state machine inside of a main VI with its own statemachine.

 

I tried running your VI's, and when the subVI timed out, an error occurred in it saying an object reference is invalid.  Why?  In the "Delay" case, you use a Bool Refnum to set a property node, but you never wired any reference to that connector of the subVI in your main VI.  Likewide the DigNum Refnum in the while loop in the Delay case also never had a refnum wired to it.

 

If you are going to use refnum's, they need to be Required inputs to the subVI so you don't have errors like this.

 

Beyond that, if you need to send a state back to the main VI, either wire up another refnum for that, or have it go out of the subVI on an output from its connector panel.

0 Kudos
Message 3 of 5
(2,589 Views)

In your main vi, you don't need the outermost case structure.  You can handle the state machine with one case structure only.  I have made some modifications for you.  See attached vi.  Also got rid of all the stop local variables and changed the action to a latch type.

 

I didn't look at your subvi, but according to others, you may have problems there also.

 

This picture shows the main change:

 

22348i22C5EC72CDAC3072

 

- tbob

Inventor of the WORM Global
0 Kudos
Message 4 of 5
(2,579 Views)

Ravens Fan,

 

Thanks for the help.  I have not had any problems with an error.  The problem might be that there was second subVI in the main VI that I didn't include in the attachments because I didn't think it was necessary. I have attached it in this posting for you.  The state machine inside the main state machine was done to limit the number of states in the main vi and to allow me to repeat sequential steps without writing the same code again and again.  The VI's I attached I have been using for testing, but the code I want to use this on is much larger.  All of the automation I am working on is pretty simple and is a stepwise process.  Turn on and off relays, wait, send serial commands then wait.  ect.  This is where I started thinking a queued state machine might be better but was not sure if it was the right for the application.  Because of the nature of the automation I might have 50 steps in the process and would like to have the option to abort or jump out of the initial order sequence of steps to make adjustments before proceeding with the remaining steps.  My current program has smaller subVI state machines for groups of steps but I don't have a good way to stop a subVI and then resume at another step.

 

Thank you.

Danny
0 Kudos
Message 5 of 5
(2,573 Views)