Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

E122: Invalid enum base type

This error occurs when an enum is declared with a base type that is not a valid integer type. Enums in IEC 61131-3 can only use integer types as their underlying representation.

Example

TYPE Color : STRING (red := 1, green := 2, blue := 3);
END_TYPE

TYPE Status : REAL (active := 1, inactive := 0);
END_TYPE

TYPE Timestamp : TIME (start := 0, stop := 1);
END_TYPE

These examples show invalid base types:

  • STRING is not a valid base type for an enum. Only integer types are allowed.
  • REAL is a floating-point type, not an integer type
  • TIME is a time/date type, which although internally represented as an integer, should not be used as an enum base type

Valid integer types

The following integer types are valid for enum base types:

  • INT, UINT - 16-bit integers
  • SINT, USINT - 8-bit integers
  • DINT, UDINT - 32-bit integers
  • LINT, ULINT - 64-bit integers
  • BYTE - 8-bit unsigned
  • WORD - 16-bit unsigned
  • DWORD - 32-bit unsigned
  • LWORD - 64-bit unsigned

How to fix

Use a valid integer type

Change the base type to one of the supported integer types:

TYPE Color : INT (red := 1, green := 2, blue := 3);
END_TYPE

TYPE Status : BYTE (active := 1, inactive := 0);
END_TYPE

Or omit the type specification

If no specific size is required, you can omit the type specification (will default to DINT):

TYPE Color (red := 1, green := 2, blue := 3);
END_TYPE