How can define enumerator in Methods?

Viewed 197

There is a problem when u define an enum in a method.

I was trying to do this:

VAR
    enumA:(A,B,C);
END_VAR

and there is the compiler reaction when I used this in TwinCAT3 Shell (TcXaeShell). enter image description here

any help would be appreciated.

3 Answers

You should first define variable type as enumeration in DUT

TYPE MyEnum:
    (A, B, C)
END_TYPE

Then in a program you can declare variable of that type

VAR
    enum: MyEnum;
END_VAR

Inside the program if you want to compare it.

IF enum = MyEnum.C THEN
    // Do something
END_IF;

I’ve run into this issue before. You must declare the local enumeration in the variables section of the function block. Then you can use it in the methods of the function block.

Related