LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

State machine, case won't give enum output

Solved!
Go to solution

Hello,

 

I'm trying to make a state machine, which at specified times should step to the next state. I don't use a timed sequence since you can't stop the sequence.

My problem:

In the state the time is measured. After 3 seconds the comparison becomes true, and the putout of the case should switch from enum 0 to enum 1.

That is exactly what it doesn't do. The probe shows the selector switches from false to true.

 

Something else that i noticed, the wire inside the case is according to the context help ({unsigned word [16 bit-integer (0-65536)] {enum 1}) the wires outside of the case are the same, except for the {enum 1}

 

What am i doing wrong?

 

Greet Nilvo

0 Kudos
Message 1 of 11
(3,870 Views)

Nilvo,

 

WIthout the VI it is almost impossible to tell what is happening.  As a guess I suspect that one of the cases has something other than the enum wired to the output.  Do you have coercion dots at the output tunnel?  Is the enum a typedef?  Has the enum been changed since you started wiring?

 

Please post yoru VI.

 

Lynn

0 Kudos
Message 2 of 11
(3,868 Views)

Since it's a school project with some competition, i can't post the VI. May i send it to you?

I've noticed a red arrow on the tunnel where the Enum becomes a unsigned integer...

 

Greetz Nilvo

0 Kudos
Message 3 of 11
(3,865 Views)

I have not heard of a competitive school project since I was a junior, quite a few years ago.  The cheapest digital voltmeter (built from an electromechanical counter, discrete transistors, ...) got the highest grade.  Everyone who got it working got at least a passing grade.

 

The red arrow is called a coercion dot.  Look up coercion dots in the LV help.  It indicates that LV has changed the data type.  Fundamentally an enum is an integer data type (with the item texts attached) so it can be converted to ordinary integers.  At some point this has apparently happened, probably in one or more cases of your state machine. The other possibility is that you have enum constants which were made from different versions of the enum (for example before and after adding an item to the enum).  While you are reading the LV Help, look up typedefs (Type Definitions).  If you make you enum a type def, then all the constants made from it will automatically update when you make any changes to the enum.  This will mostly prevent the coercion dot issue and the associated problems in the state machine.

 

Lynn

Message 4 of 11
(3,833 Views)

Well... it's not so easy at our school... we have 7 weeks to program a complety car wash, on 3 different interfaces (PLC PC an micro controller)...

 

The coercion dots appears at the input of the shift register and output of the case...

I'll take a look at the dots tommorrow

 

Thanx annyway!

0 Kudos
Message 5 of 11
(3,830 Views)

I took a look at the coercion dots, but i can't find out why they appear in my program. All the connections are tunnels, enum constants or a shift register...

It's very fustrating since i know the whol program works, but the state machine doesn't...

 

can anyone take a look at the program?

 

gr Nilvo

0 Kudos
Message 6 of 11
(3,792 Views)

If at any place you wire in a pure integer (i.e. a "0" constant coming out of a "default" case), everything will be coerced to integers. I think also that shift registers can remember the type you previously plugged in... Try to unwire them from the inside until it loses its type (i.e. black wire), then re-wire it.

Message 7 of 11
(3,782 Views)
Solution
Accepted by topic author Nilvo

When using ENUMs for a state machine you should always used a typedefed ENUM. This will avoid th eissue you are seeing now. The typedef will alllow you to modify the defintion (add or remove items) and automatically update all instances of that typedef (they can be controls, indicators or constants) in your code. The coercion dots you are seeing are the result of different data types (yes, an ENUM is a unqiue data type) bing wired on the same tunnel or shoft register.



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 11
(3,771 Views)

Well... just found out that when you wire only one of the cases, the wire is of the type Enum. When you wire both cases, it becomes an integer...

I'm looking for typedef on this moment, what it is and how to implement.

 

Gr Nilvo

0 Kudos
Message 9 of 11
(3,757 Views)

File -> New...    -> Control

 

Put your enum in that control. At the top, there's a listbox with the choices 'Control', 'Typedef', or 'Strict Typedef'. Change it from control to typedef.

 

In your VI's, you can then drag that .ctl from the project explorer to your block diagram to create a constant with that type, or to the front panel to create a control with that type. You can also right-click on an existing non-typedefed one, and select replace -> select a vi..., and select your .ctl file.

0 Kudos
Message 10 of 11
(3,754 Views)