How to Convert Variable Values of One Data Type to Another Data Type

Introduction:

The instructions below demonstrate how to convert variable values of one data type to another data type within Codesys.

Software Version:

Codesys IDE 3.5.15.50
Codesys package

Related Tutorials:

New to Codesys?
Video - How to convert between data types in Codesys

Instructions:

Structured Text

Using the “TO_< data type>” operator, it is possible to convert variables of one data type to another. Codesys program example:
image

Example: While the program is running, the “TO_REAL” operator converts our INT value into a REAL.

Ladder Logic

Using the “Box” or “Box with EN/ENO”, it is possible to convert variables of one data type to another. The “Box with EN/ENO” can be found in the “ToolBox” on the right side of the Codesys IDE:

Note: The “Box with EN/ENO” is located under “General”.

Note: To select the “TO_REAL” conversion operator, select the “???” at the top of the “Box with EN/ENO” and click the ellipsis. This will summon the “Input Assistant”. Next, select “TO_REAL” from the “Conversion Operators” section

Codesys program example:
image

Example: While the program is running, the “TO_REAL” “Box with EN/ENO” converts our INT value into a REAL.

Keywords

codesys, convert, conversion, variable, variables, data, operator, box, toolbox, value