Scripting with Enumeration Selector ID's

Discuss issues and ideas you have to configuring displays with PowerVision
cconner_aie
Posts: 93
Joined: Thu Jun 11, 2015 10:12 am

Scripting with Enumeration Selector ID's

Post by cconner_aie » Thu Feb 16, 2017 12:25 am

Is there a way to check a variable against the enumeration selector value? I have a feeling when referencing enumerations in scripts I can only get the display value, but I hope I'm wrong.

E.G.

Code: Select all

...
if (someVariable == VariableEnumeration.SOME_ENUMERATION) {
	// do stuff...
}
...
This warns me about a Signed/Unsigned mismatch, but still compiles. I'll admit I haven't tested this, the fact that it warns me of this made me move on to try something else.

I thought that this might work, and I get no warnings.

Code: Select all

...
int localVariable;
smRead(VariableEnumerations.SOME_ENUMERATION, localVariable);
if (someVariable == localVariable) {
	// do stuff...
}
...
However when running this I get unexpected results, and it looks like it might be taking the ascii hex values of the enumeration display value and then casting that into a double (the result is a very large number). I read in another forum that the color displays convert all variables to doubles which would explain this.

Long story short, with my testing I don't see a way to check a variable against an enumeration selector value, which is unfortunate because I really don't like the ambiguity of the following. This also opens up the possibility of changing the enumerations selector values and breaking the script.

Code: Select all

...
if (someVariable == 0) {  // VariableEnumerations.SOME_ENUMERATION
	// do stuff...
}
...
I'm hoping I'm missing something, which is usually the case, I'd love to be able to use case statements with the enumeration selector values but trying that opened up another can of worms and I couldn't get anything to compile (case statements must be constant, signed/unsigned error again, etc.).
Coleby Conner
Controls Engineer, Anderson Industrial Engines
boyce
Enovation Controls Development
Enovation Controls Development
Posts: 322
Joined: Wed Sep 08, 2010 5:09 pm

Re: Scripting with Enumeration Selector ID's

Post by boyce » Thu Feb 16, 2017 10:23 am

I think you can program using the VariableIDs rather than enumerations. I don't think it will be possible to create a list of enumerations because the VariableIDs are a list of ordinals that can change when the program is changed. You can always compare a VariableIDs to an uint value.
Boyce Schrack
Enovation Controls
boyce
Enovation Controls Development
Enovation Controls Development
Posts: 322
Joined: Wed Sep 08, 2010 5:09 pm

Re: Scripting with Enumeration Selector ID's

Post by boyce » Thu Feb 16, 2017 11:12 am

This may be basic and not really answer your question, but this code works:


uint local;
smRead(VariableIDs.TestVariable, local);


if (local == VariableEnumerations.TestVariable_Enumeration2)
{
...
}
Boyce Schrack
Enovation Controls
cconner_aie
Posts: 93
Joined: Thu Jun 11, 2015 10:12 am

Re: Scripting with Enumeration Selector ID's

Post by cconner_aie » Thu Feb 23, 2017 9:03 am

I didn't think to try uint rather than int, which makes sense after I see it.

Thanks!
Coleby Conner
Controls Engineer, Anderson Industrial Engines