09-11-2019 12:59 PM
I have a case structure with 3 cases. I would like to execute cases based on the the error generated in each case. For instance if "Connect" results in error, then I would like to try "Disconnect", "Connect", "Read" and then again "Disconnect". If there is an error in "Read", I would like to execute "Connect", "Read" and then "Disconnect". How can we achieve this with the the help of a case structure?
09-11-2019 01:04 PM
What you want is a state machine. There are tons of examples of them both online and in the LabVIEW shipping examples.
09-11-2019 01:12 PM
Yes. I have already implemented the state-machine version of this but my program selects cases based on user mouse click. Is it possible to create a state-machine architecture where I can call a state based on the error occurred in a different state?
09-11-2019 01:14 PM
How are you handling the mouse clicks? Do you have an event structure embedded in this case structure or is it separate?
Marks statement is correct. You could do what you are needing with a state machine. How you incorporate your event management may be the actual question based on your second post.
09-11-2019 01:16 PM
If you can provide the entire VI that would be ideal.
09-11-2019 01:19 PM
09-11-2019 01:26 PM
Here is an example VI where I use mouse click event to register and execute each state via the front pane.
Now I would like to selectively jump and execute cases based on the error generated in "Connect", "Req" and "Disconnect" cases. For instance in the case "Connect", if the Boolean X=Y? is false, then I would like to jump to "Disconnect" case and execute it first and then re-try "Connect" case.
09-11-2019 01:34 PM
Use user defined events to trigger the appropriate event to drive your state machine. Though I don't think I would implement a state machine entirely using the event structure. It is possible, as I implemented the ATM example of a CLD exam solution using an event structure state machine.
09-11-2019 01:37 PM
Give this a look. I have some sketch code and notations that might be helpful to accomplishing your goal.
09-11-2019 03:04 PM
You are close to trying to implement a Queued State Machine, which is not a great design pattern most of the time. A State Machine is fine, and a Queued Message Handler is fine, and combining those is great, but what you're describing sounds like you want to call each case arbitrarily. A "State" should be a "state" that the system is in- not a case that gets called each time. It doesn't make sense conceptually to call "Connect" a state- it's an action, not a "state of being".
In this situation, I'd replace each of your cases with a subVI. You can then call Read.vi, then throw a case structure on the Error output. In the Error case, it calls Disconnect, Connect, then Read again. If you continue down this path, you'll end up with a queue holding each command to execute. If you consider each "command" as a message, it'll work great, but if you consider them as "states" you'll get out of whack pretty quickly.