LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Compare Enum state outside of while loop using Tags

Solved!
Go to solution

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. 

0 Kudos
Message 1 of 6
(867 Views)
Solution
Accepted by topic author labview_wannabe

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.

0 Kudos
Message 2 of 6
(836 Views)

I just can't believe how stupid I can sometimes be!

0 Kudos
Message 3 of 6
(825 Views)

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.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
Message 4 of 6
(820 Views)

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?

0 Kudos
Message 5 of 6
(807 Views)

@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".

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 6 of 6
(790 Views)