6 Programming
6-46
NJ-series CPU Unit Software User’s Manual (W501)
Union Specifications
Data Types of Union Members
Restrictions
• The initial values for unions are always zero.
• You cannot move unions.
• You cannot specify unions for parameters to POUs.
An enumeration is a derivative data type that uses text strings called enumerators to express variable
values. To use an enumeration, you must first set the values that can be obtained from that variable as
enumerators (text strings). Use enumerations to make it easier for humans to understand the meaning
behind the values of a variable.
Expressing Enumerations
When you define an enumeration, you must define the possible values of the variable as enumera-
tors and give the enumeration a name.
Creating Enumerations
1
Create an enumeration data type in the Enumeration Table.
Set the enumerators and their values for the enumeration.
2
Specify the enumeration data type from above as the data type and register the variable in the
variable table.
Example:
Here, Color is defined as the data type of an enumeration. For this example, we will set three
enumerators: red, yellow, and green. The numbers associated with these enumerators are as fol-
lows: red = 0, yellow = 1, green = 2. The variable DiscColor will change to one of the following:
red (0), yellow (1), or green (2).
Item Specification
Data types that can be
specified for members
Refer to the table on the valid data types for union members that is given below.
Number of members 4 max.
Setting initial values Not supported. Always zero.
Classification Data type Usage
Basic data types
Boolean and bit strings Supported.
BOOL and bit string data array specifications Supported.
Other basic data types Not supported.
Derivative data types
Array specification for structures, unions, and
enumerations
Not supported.
POU instances Not supported.
Enumerations (ENUM)