Search code examples
enumsplciec61131-3

How to declare data type ENUM in Yaskawa MotionWorks IEC 3?


I'm trying to add my own enum in MotionWorks. After creation of new data type the only available types are ARRAY,STRING,STRUCT.

Writing the following code:

TYPE SimulationType:
(
    Passing :=  0,
    Random  :=  1,
    Failing :=  2
) INT := 0;
END_TYPE

does not compile. Yaskawa seem to be complying to ENUM (according to this list) but I can't figure out how to declare it.

Edit: I can do the following:

TYPE
    ResultType:(Pass, Random, Fail);
END_TYPE

But it doesn't seem to create an enum, as I can't access it's value. I can access it like a structure.

Edit 2:

If I declare:

TYPE
    ResultType:(Pass, Random, Fail);
END_TYPE

And set variable

ExpectedResultType : ResultType;

Then in the code I try to use:

IF ExpectedResultType = ResultType.Pass THEN
    Done := TRUE;
END_IF;

It compiles, but will not run.

Trying to use this code will not compile:

CASE ExpectedResultType OF
    ResultType.Pass:
        Done := TRUE;
        Error := FALSE;
    ResultType.Random:
        Done := TRUE;
    ResultType.Fail:
        Error := TRUE;
        Done := FALSE;
END_CASE;

Solution

  • Enums in MotionWorks are declared in data types as this example:

    TYPE
        MyEnum:(Zero,One,Two,Three);
    END_TYPE
    

    ENUMs in MotionWorks can't be assigned a value. First enum will always be equal to 0 (zero), second one to 1 (one), and so on.

    Then enums can be used in IF .. END_IF statements like this:

    I'll call my variable "i". The variable must be declared as INT. Any other type will not work. In the code use it like this:

    IF i = MyEnum#Zero THEN
     (* do some work *)
    ELSIF i = MyEnum#One THEN
     (* do some other work *)
    END_IF
    

    ENUMs can't be used in CASE statements in MotionWorks.