Attention
IronPLC supports IEC 61131-3 Structured Text excluding I/O mapping.
Type Conversions¶
IEC 61131-3 defines a set of type conversion functions that convert
values between data types. Each function follows the naming pattern
<source>_TO_<target>.
IEC 61131-3 |
Section 2.5.1.5.1 |
Support |
Supported (numeric and time/date conversions) |
Conversion Categories¶
Integer Widening¶
Conversions from a smaller integer type to a larger integer type. These conversions are always safe — no data is lost.
Function |
Description |
Support |
|---|---|---|
|
8-bit to 16-bit signed |
Supported |
|
8-bit to 32-bit signed |
Supported |
|
8-bit to 64-bit signed |
Supported |
|
16-bit to 32-bit signed |
Supported |
|
16-bit to 64-bit signed |
Supported |
|
32-bit to 64-bit signed |
Supported |
|
8-bit to 16-bit unsigned |
Supported |
|
8-bit to 32-bit unsigned |
Supported |
|
8-bit to 64-bit unsigned |
Supported |
|
16-bit to 32-bit unsigned |
Supported |
|
16-bit to 64-bit unsigned |
Supported |
|
32-bit to 64-bit unsigned |
Supported |
Integer Narrowing¶
Conversions from a larger integer type to a smaller integer type. These conversions may lose data if the value exceeds the range of the target type.
Function |
Description |
Support |
|---|---|---|
|
16-bit to 8-bit signed |
Supported |
|
32-bit to 8-bit signed |
Supported |
|
32-bit to 16-bit signed |
Supported |
|
64-bit to 8-bit signed |
Supported |
|
64-bit to 16-bit signed |
Supported |
|
64-bit to 32-bit signed |
Supported |
|
16-bit to 8-bit unsigned |
Supported |
|
32-bit to 8-bit unsigned |
Supported |
|
32-bit to 16-bit unsigned |
Supported |
|
64-bit to 8-bit unsigned |
Supported |
|
64-bit to 16-bit unsigned |
Supported |
|
64-bit to 32-bit unsigned |
Supported |
Signed/Unsigned Conversions¶
Conversions between signed and unsigned integer types of the same or different sizes.
Function |
Description |
Support |
|---|---|---|
|
Signed to unsigned 8-bit |
Supported |
|
Signed to unsigned 16-bit |
Supported |
|
Signed to unsigned 32-bit |
Supported |
|
Signed to unsigned 64-bit |
Supported |
|
Unsigned to signed 8-bit |
Supported |
|
Unsigned to signed 16-bit |
Supported |
|
Unsigned to signed 32-bit |
Supported |
|
Unsigned to signed 64-bit |
Supported |
Integer to Real¶
Conversions from integer types to floating-point types. Large integer
values may lose precision when converted to REAL.
Function |
Description |
Support |
|---|---|---|
|
8-bit signed to single-precision |
Supported |
|
16-bit signed to single-precision |
Supported |
|
32-bit signed to single-precision |
Supported |
|
64-bit signed to single-precision |
Supported |
|
8-bit signed to double-precision |
Supported |
|
16-bit signed to double-precision |
Supported |
|
32-bit signed to double-precision |
Supported |
|
64-bit signed to double-precision |
Supported |
Real to Integer¶
Conversions from floating-point types to integer types. The fractional part is truncated.
Function |
Description |
Support |
|---|---|---|
|
Single-precision to 8-bit signed |
Supported |
|
Single-precision to 16-bit signed |
Supported |
|
Single-precision to 32-bit signed |
Supported |
|
Single-precision to 64-bit signed |
Supported |
|
Double-precision to 8-bit signed |
Supported |
|
Double-precision to 16-bit signed |
Supported |
|
Double-precision to 32-bit signed |
Supported |
|
Double-precision to 64-bit signed |
Supported |
Real to Real¶
Conversions between floating-point types.
Function |
Description |
Support |
|---|---|---|
|
Single-precision to double-precision |
Supported |
|
Double-precision to single-precision |
Supported |
Boolean Conversions¶
Conversions between BOOL and integer types. FALSE converts
to 0, TRUE converts to 1. For the reverse direction, 0 converts
to FALSE and any non-zero value converts to TRUE.
Function |
Description |
Support |
|---|---|---|
|
Boolean to 8-bit signed |
Supported |
|
Boolean to 16-bit signed |
Supported |
|
Boolean to 32-bit signed |
Supported |
|
Boolean to 64-bit signed |
Supported |
|
Boolean to 8-bit unsigned |
Supported |
|
Boolean to 16-bit unsigned |
Supported |
|
Boolean to 32-bit unsigned |
Supported |
|
Boolean to 64-bit unsigned |
Supported |
|
8-bit signed to Boolean |
Supported |
|
16-bit signed to Boolean |
Supported |
|
32-bit signed to Boolean |
Supported |
|
64-bit signed to Boolean |
Supported |
|
8-bit unsigned to Boolean |
Supported |
|
16-bit unsigned to Boolean |
Supported |
|
32-bit unsigned to Boolean |
Supported |
|
64-bit unsigned to Boolean |
Supported |
Time/Duration Conversions¶
Conversions between time duration types (TIME, LTIME) and
numeric or bit string types. The underlying value is the duration in
milliseconds.
Function |
Description |
Support |
|---|---|---|
|
Duration to 32-bit signed |
Supported |
|
Duration to 16-bit signed |
Supported |
|
Duration to single-precision float |
Supported |
|
Duration to 32-bit unsigned word |
Supported |
|
32-bit signed to duration |
Supported |
|
32-bit unsigned word to duration |
Supported |
|
Long duration to 64-bit signed |
Supported |
|
Long duration to 64-bit unsigned word |
Supported |
|
64-bit signed to long duration |
Supported |
All combinations of TIME/LTIME with signed integers, unsigned
integers, real types, and bit string types are supported.
Date Conversions¶
Conversions between date types (DATE, LDATE) and numeric or
bit string types. The underlying value is seconds since 1970-01-01.
Function |
Description |
Support |
|---|---|---|
|
Date to 32-bit unsigned word |
Supported |
|
Date to 32-bit unsigned integer |
Supported |
|
32-bit unsigned word to date |
Supported |
|
Long date to 64-bit unsigned word |
Supported |
All combinations of DATE/LDATE with signed integers, unsigned
integers, real types, and bit string types are supported.
Time-of-Day Conversions¶
Conversions between time-of-day types (TOD/TIME_OF_DAY,
LTOD/LTIME_OF_DAY) and numeric or bit string types. The
underlying value is milliseconds since midnight (TOD) or
nanoseconds since midnight (LTOD).
Function |
Description |
Support |
|---|---|---|
|
Time-of-day to 32-bit unsigned word |
Supported |
|
Time-of-day to 32-bit unsigned integer |
Supported |
|
32-bit unsigned word to time-of-day |
Supported |
|
Long time-of-day to 64-bit unsigned word |
Supported |
Both short aliases (TOD, LTOD) and full names
(TIME_OF_DAY, LTIME_OF_DAY) are supported. All combinations
with signed integers, unsigned integers, real types, and bit string
types are supported.
Date-and-Time Conversions¶
Conversions between date-and-time types (DT/DATE_AND_TIME,
LDT/LDATE_AND_TIME) and numeric or bit string types. The
underlying value is seconds since 1970-01-01 (DT) or nanoseconds
since 1970-01-01 (LDT).
Function |
Description |
Support |
|---|---|---|
|
Date-and-time to 32-bit unsigned word |
Supported |
|
Date-and-time to 32-bit unsigned integer |
Supported |
|
32-bit unsigned word to date-and-time |
Supported |
|
Long date-and-time to 64-bit unsigned word |
Supported |
Both short aliases (DT, LDT) and full names
(DATE_AND_TIME, LDATE_AND_TIME) are supported. All
combinations with signed integers, unsigned integers, real types,
and bit string types are supported.
Numeric to String¶
Conversions from numeric types to string representation.
Function |
Description |
Support |
|---|---|---|
|
8-bit signed to string |
Supported |
|
16-bit signed to string |
Supported |
|
32-bit signed to string |
Supported |
|
64-bit signed to string |
Not yet supported |
|
8-bit unsigned to string |
Supported |
|
16-bit unsigned to string |
Supported |
|
32-bit unsigned to string |
Supported |
|
Byte to string |
Supported |
|
Word to string |
Supported |
|
Double word to string |
Supported |
|
Single-precision to string |
Supported |
|
Double-precision to string |
Not yet supported |
String to Numeric¶
Conversions from string representation to numeric types. The string must contain a valid numeric literal for the target type.
Function |
Description |
Support |
|---|---|---|
|
String to 8-bit signed |
Supported |
|
String to 16-bit signed |
Supported |
|
String to 32-bit signed |
Supported |
|
String to 64-bit signed |
Not yet supported |
|
String to 8-bit unsigned |
Supported |
|
String to 16-bit unsigned |
Supported |
|
String to 32-bit unsigned |
Supported |
|
String to single-precision |
Supported |
|
String to double-precision |
Not yet supported |
Description¶
Type conversion functions explicitly convert values from one data type
to another. IEC 61131-3 does not perform implicit type conversions;
all conversions must use the appropriate *_TO_* function.
When a conversion may lose data (narrowing conversions), the behavior depends on the implementation. Values that exceed the range of the target type may be truncated or cause a runtime error.
Example¶
See Also¶
Data Types — data type reference