03-29-2023 09:07 AM - edited 03-29-2023 09:08 AM
There are three states within a state machine model. They are "State 1", "State 2", and "State 3". These states are defined as enums. I need to run this model through an infinite while loop, which changes to a particular enum state every second. I am also running two other while loop outside of this infinite while loop which turns on LED in the front panel as soon as a particular enum state is selected: atleast that is what I am trying to do. I must use tag because I need communication to happen between while loops.
Both the LEDs turn on as soon as State 1 is selected. I do not want that. I want one LED to turn on as soon as State 1 is selected. This LED should turn off and the other LED should turn on as soon as State 2 is selected. I am not able to do that. What am I doing wrong here? If I cannot do that with enums, what else can I use, apart from global and local variables?
I have attached VI with this thread.
Solved! Go to Solution.
03-29-2023 11:16 AM
That's because your Enums are not the same
You have one Enum : State 1 = 0, State 2 = 1, State 3 = 2
One reader has Enum with only one element State 2 = 0 and
The other reader has Enum State1 = 0.
Copy the Enum with 3 elements to the other while loops.
03-29-2023 11:47 AM
I just can't believe how stupid I can sometimes be!
03-29-2023 11:55 AM - edited 03-29-2023 11:56 AM
If you are going to use this anywhere outside of an experimental throw-away VI then I strongly suggest that enum be a typedef'd one, or you are in for HUGE headaches down the road. Just think of the issue you just had in several different VIs and you have no idea where every single version of your enum is... Think of all the headaches trying to find and update each version of your enum.
03-29-2023 12:09 PM
Hi @billko,
thanks for the reply. Can I use typedef to share the enum states between different VIs? If not, is there a way I can use tags or channels or streams to share the enum states between different VIs? Will there be a delay between values or states in main VI and subVI?
03-29-2023 12:45 PM
@labview_wannabe wrote:
Hi @billko,
thanks for the reply. Can I use typedef to share the enum states between different VIs? If not, is there a way I can use tags or channels or streams to share the enum states between different VIs? Will there be a delay between values or states in main VI and subVI?
The whole idea behind a typedef is that when you make change to the main control, all the instances of that control change as well. So let's say you add a state to the enum. It gets added everywhere, possibly breaking code in other VIs - which is a GOOD thing because it is screaming at you, "I NEED ATTENTION! You need to change your code here".