2

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;
Ilya Dan
  • 301
  • 1
  • 8

4 Answers4

2

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.

Ilya Dan
  • 301
  • 1
  • 8
1

This what I have for Schneider which is IEC61131 so it should be the same

TYPE E_HomeLimitSwitch:
(
  ePositiveDirectionRisingEdge := 0,
  eNegativeDirectionRisingEdge := 1,
  ePositiveDirectionFallingEdge := 2,
  eNegativeDirectionFallingEdge := 3
);
END_TYPE

I don't think you INT:=0 should be there.

mrsargent
  • 2,267
  • 3
  • 19
  • 36
  • It doesn't work with Yaskawa unfortunately. If I erase placements then it does compile, but seem to create a structure of some type instead of enum. – Ilya Dan Mar 14 '19 at 15:53
0

You can only set the default value to one of your local enum members. Not to other values or even a number as you tried.
Try this instead in line 6:
) INT := Passing;

pboedker
  • 523
  • 1
  • 3
  • 17
  • It would not compile with any digit / type / word in the declaration. When no default is set it compiles, but enum is not declared correctly. It looks like it compiles as a structure. – Ilya Dan Mar 14 '19 at 15:59
  • Well, I have run your code from 'Edit 2' in my Beckhoff PLC (also IEC61131-3), and it compiles and runs perfectly. After a reset, ExpectedResultType is reset to 'Fail(0)' and writing 'Random' or 'Fail' into it also works in the case. Are you sure your program is still the same as your 'Edit 2'? – pboedker Mar 15 '19 at 08:53
  • 1
    I work with Beckhoff since early 2016 and enums work there very well indeed. But the question is about much inferior Yaskawa's MotionWorks 3. Beckhoff's Twincat same as many other manufacturers is based on CoDeSys. However MotionWorks is based on some other system. Their implementation is different. Theoretically code syntax should be similar, but it isn't. – Ilya Dan Mar 15 '19 at 14:31
0

unlike Codesys, Yaskawa's MotionWorksIEC does not fully support enumerations. In ST language enum usage is quite popular in CASE statements but MotionWorksIEC does not support enum use in case statements.

But, you still can define enums as shown below.

TYPE
PackMLState:(Starting,Starting,Aborting,Aborted,Helding,Held,Etc);
END_TYPE

You can use the enum type as;

IF machineState = PackMLState#Starting THEN
;;
END_IF

Comparing Codesys and MotionWorksIEC (Which is basically Phoenix Contact, KW Software Multiprog), there are some differences. For clarification, the lack of enum use in Cases doesn't make Multiprog an inferior IDE.