Is there way to make an enumeration type tag in Ignition?

I’m just wondering if there is a way to make an actual enumeration type tag in Ignition?
Like where an integer value always equals a text state such as:
0-Off
1-Running

Or even more states like:
0-Manual
1-Auto
2-Cascade

I know this could be done on an actual screen component, but what if I wanted to read this state directly from the tag value? Is this possible in Ignition at all?

Thanks

You could create an expression data type that generates that enumeration. We do something similar with the switch expression statement.

Thanks for the reply. So you end up basically have 2 tags? The original integer one with the numerical value, and then a 2nd expression tag with the resulting string?

Yes, you could create an expression string tag to do that for you. This would be your example expression which uses the value from your integer tag.

if({[.]Tag} = 0, “Manual”,
if({[.]Tag} = 1, “Auto”,
if({[.]Tag} = 2, “Cascade”,
“”)))

Exactly @Tim is showing.

Alternatively you can use the switch statement:

switch({[.]Tag},
0,1,2,
'Manual', //Tag Value = 0
'Auto', //Tag Value = 1
'Cascade', //Tag Value = 2
'Unknown' //Falback
)
1 Like

I prefer to do this with a lookup expression and a states dataset, it makes it a lot easier if you have lot of devices that use the same states, such as if you have a couple of hundred motors.
Each motor has a state number, but all motor states are the same. You can then enumerate either on the window, or you can create a tag that enumerates and then use that on the window.
So you’ll have the following:
State(integer tag) - a number that indicates what state the motor is in.
States(dataset tag) - a dataset tag that contains an integer and a string representing the state.
In the state types dataset, just have a 2 column dataset such as this:
24
And whenever you want to enumerate, either in a tag or on screen use an expression:

lookup({States},{State},“State not found.”,0,1)

See the manual for info on the lookup expression. lookup - Ignition User Manual 8.0 - Ignition Documentation

The combo of the lookup expression function and dataset tags is extremely useful!

8 Likes

I wasn’t aware that this existed… I may have to revisit how we do this and change over to this mechanism. Thanks for the information.

1 Like

Great idea!!!
Using lookup I can do even multilingual “Enumerations”.
I have used case() or switch() but this way is much more flexible!!!

1 Like

I have used a SQL table to do that