LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Selectively execute cases in case-structure

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?

 

KTczE6c

NI System Configuration:
- NI PXIe-1071, 4-Slot 3U PXI Express Chassis , 1 GB/Slot throughput, Part Number: 781368-01
- NI PXIe-PCIe8381,x8 Gen2 MXI-Express for PXI Express Interface,3m, Part Number: 782522-01
- PXIe-5160 PXI Oscilloscope, 500 MHz, 10 bits, 2.5 GS/s, 2 Channels, 64 MB, Part Number: 782621-01
- Astronics PXIe-1209 2-Channel, 100 MHz PXI Pulse Generator, Part Number: 785033-01
0 Kudos
Message 1 of 14
(210 Views)

What you want is a state machine. There are tons of examples of them both online and in the LabVIEW shipping examples.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 2 of 14
(205 Views)

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?

NI System Configuration:
- NI PXIe-1071, 4-Slot 3U PXI Express Chassis , 1 GB/Slot throughput, Part Number: 781368-01
- NI PXIe-PCIe8381,x8 Gen2 MXI-Express for PXI Express Interface,3m, Part Number: 782522-01
- PXIe-5160 PXI Oscilloscope, 500 MHz, 10 bits, 2.5 GS/s, 2 Channels, 64 MB, Part Number: 782621-01
- Astronics PXIe-1209 2-Channel, 100 MHz PXI Pulse Generator, Part Number: 785033-01
0 Kudos
Message 3 of 14
(187 Views)

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.

0 Kudos
Message 4 of 14
(184 Views)

If you can provide the entire VI that would be ideal.

0 Kudos
Message 5 of 14
(181 Views)
Yes event structure inside a while loop. A simple state-machine architecture.
I will post the VI as an example.
NI System Configuration:
- NI PXIe-1071, 4-Slot 3U PXI Express Chassis , 1 GB/Slot throughput, Part Number: 781368-01
- NI PXIe-PCIe8381,x8 Gen2 MXI-Express for PXI Express Interface,3m, Part Number: 782522-01
- PXIe-5160 PXI Oscilloscope, 500 MHz, 10 bits, 2.5 GS/s, 2 Channels, 64 MB, Part Number: 782621-01
- Astronics PXIe-1209 2-Channel, 100 MHz PXI Pulse Generator, Part Number: 785033-01
0 Kudos
Message 6 of 14
(175 Views)

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.

NI System Configuration:
- NI PXIe-1071, 4-Slot 3U PXI Express Chassis , 1 GB/Slot throughput, Part Number: 781368-01
- NI PXIe-PCIe8381,x8 Gen2 MXI-Express for PXI Express Interface,3m, Part Number: 782522-01
- PXIe-5160 PXI Oscilloscope, 500 MHz, 10 bits, 2.5 GS/s, 2 Channels, 64 MB, Part Number: 782621-01
- Astronics PXIe-1209 2-Channel, 100 MHz PXI Pulse Generator, Part Number: 785033-01
0 Kudos
Message 7 of 14
(171 Views)

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.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 8 of 14
(161 Views)

Give this a look. I have some sketch code and notations that might be helpful to accomplishing your goal.

0 Kudos
Message 9 of 14
(160 Views)

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.

0 Kudos
Message 10 of 14
(113 Views)