LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Pass the value of the current case in a case structure to a global variable for use in VIs.

I have built a large queued state machine (>100 cases).  In each state, I run a VI that I have created.  These VIs are usually not very different from one another.  In many cases, I could simply use the same VI over and over again.  There is only one problem with that.  None of these VIs know which case to send the program to next.  I have to change the value of the "NEXT_CASE" constants in the VI and save it under a new name to be inserted into each new case.  Now my program consists of hundreds of VIs whose only difference is the value of their "NEXT_CASE" constants.  This causes all kind of headaches when I have to insert new cases into the state machine, and it is just too much for me to deal with.
 
I need to be able to use a global variable to keep track of the current case within my VIs.  I could change it from a string to a number and add or subtract from it to determine which case the program should go to next.  Since I'm usually only skipping from one case to the next (or the previous) I could use the exact same VI in most cases.  Can anyone tell me how to create a global variable that contains the value of the case in my case structure that I could use within my VIs to keep track of the current case?  Let me know if you have any questions.
0 Kudos
Message 1 of 3
(2,562 Views)
Instead of defining the next state inside the subvi, why not do it in the main vi inside each state case?  An output from the subvi could be used with a case structure to determine the next state.  Sort of like, if the subvi returns 0 then next state is State3, else if the subvi returns 1 then next state is State4.
 

Message Edited by tbob on 08-19-2005 03:15 PM

- tbob

Inventor of the WORM Global
0 Kudos
Message 2 of 3
(2,559 Views)
There's no reason to make the subVIs different and there's no reason for a global variable. In a simple state machine in which a numeric or enum is determining the next state, all the subVI has to do is return either a 1 (next) or -1 (previous). Take the number returned and add it to the current state. The current state is kept in a shift register. This is simple to implement when you just have to go forward or back 1 state. You can make it more sophisticated. Say to want to return an error state instead of either next or back. Define one or more error codes (i.e. -999) and in the main VI, test for that value before doing the add. Keep all of the logic inside the main program and make the subVIs as generic as possible.
0 Kudos
Message 3 of 3
(2,558 Views)