
- •1 A Brief Introduction to CoDeSys
- •1.1 What is CoDeSys
- •1.2 Overview of CoDeSys Functions...
- •1.3 Overview on the user documentation for CoDeSys
- •2 What is What in CoDeSys
- •2.1 Project Components...
- •2.2 Languages...
- •2.2.1 Instruction List (IL)...
- •2.2.2 Structured Text (ST)...
- •2.2.3 Sequential Function Chart (SFC)...
- •2.2.4 Function Block Diagram (FBD)...
- •2.2.5 The Continuous Function Chart Editor (CFC)...
- •2.2.6 Ladder Diagram (LD)...
- •2.3 Debugging, Online Functions...
- •2.4 The Standard...
- •3 We Write a Little Program
- •3.1 Controlling a Traffic Signal Unit...
- •3.2 Visualizing a Traffic Signal Unit...
- •4 The Individual Components
- •4.1 The Main Window...
- •4.3 Managing Projects...
- •4.4 Managing Objects in a Project...
- •4.5 General Editing Functions...
- •4.8 Help when you need it...
- •5 Editors in CoDeSys
- •5.1 This is for all Editors...
- •5.2 Declaration Editor...
- •5.2.1 Working in the Declaration Editor
- •5.2.3 Pragma instructions in the Declaration Editor
- •5.3 The Text Editors...
- •5.3.1 Working in text editors
- •5.3.2 The Instruction List Editor...
- •5.3.3 The Editor for Structured Text...
- •5.4 The Graphic Editors...
- •5.4.1 Working in graphic editors
- •5.4.2 The Function Block Diagram Editor...
- •5.4.3 The Ladder Editor...
- •5.4.4 The Sequential Function Chart Editor...
- •5.4.5 The Continuous Function Chart Editor (CFC)...
- •6 The Resources
- •6.1 Overview of the Resources
- •6.2 Global Variables, Variable Configuration, Document Frame
- •6.2.1 Global Variables...
- •6.2.2 Variable Configuration...
- •6.2.3 Document Frame...
- •6.3 Alarm Configuration
- •6.3.1 Overview
- •6.3.2 General information on alarms, Terms
- •6.3.3 Alarm classes
- •6.3.4 Alarm groups
- •6.3.5 Alarm saving
- •6.3.6 'Extras' Menu: Settings
- •6.4 Library Manager...
- •6.6 PLC Configuration...
- •6.6.1 Overview
- •6.6.2 Working in the PLC Configuration...
- •6.6.3 General Settings in the PLC Configuration
- •6.6.4 Custom specific parameter dialog
- •6.6.5 Configuration of an I/O Module...
- •6.6.6 Configuration of a Channel
- •6.6.7 Configuration of Profibus Modules...
- •6.6.8 Configuration of CAN modules...
- •6.6.9 Configuration of a CanDevice (CANopen Slave)
- •6.6.10 PLC Configuration in Online Mode
- •6.6.11 Hardware scan/State/Diagnosis information from the PLC
- •6.7 Task Configuration...
- •6.7.1 Working in the Task Configuration
- •6.7.2 System Events
- •6.7.3 Taskconfiguration in Online Mode
- •6.8 Watch and Receipt Manager...
- •6.8.1 Overview
- •6.8.2 Watch and Receipt Manager in the Offline Mode
- •6.8.3 Watch and Receipt Manager in the Online Mode
- •6.9 The Sampling Trace
- •6.9.1 Overview and Configuration
- •6.9.2 Display of the Sampling Trace
- •6.9.3 'Extras' 'Save Trace'
- •6.9.4 'Extras' 'External Trace Configurations'
- •6.10 Workspace
- •6.11 Parameter Manager ..
- •6.11.1 Overview, Activating
- •6.11.2 The Parameter Manager Editor, Overview
- •6.11.3 Parameter List Types and Attributes
- •6.11.4 Managing parameter lists
- •6.11.5 Editing parameter lists
- •6.11.6 Parameter Manager in Online Mode
- •6.11.7 Export / Import of parameter lists
- •6.12 Target Settings
- •6.13 The PLC-Browser
- •6.14 Tools
- •6.14.1 Properties of available Tool Shortcuts (Object Properties)
- •6.14.2 Managing Tool Shortcuts
- •6.14.3 Frequently asked questions on Tools
- •7.1 What is ENI
- •7.2 Preconditions for Working with an ENI project data base
- •7.3 Working with the ENI project data base in CoDeSys
- •7.4 Object categories concerning the project data base
- •8 DDE Interface
- •8.1 DDE interface of the CoDeSys programming system...
- •8.2 DDE communcation with the GatewayDDE Server...
- •9 The License Management in CoDeSys
- •9.1 The License Manager
- •9.1.1 Creating a licensed library in CoDeSys
- •10 APPENDIX
- •Appendix A: IEC Operators and additional norm extending functions
- •Arithmetic Operators...
- •Bitstring Operators...
- •Selection Operators
- •Comparison Operators...
- •Address Operators...
- •Calling Operators...
- •Type Conversions...
- •Numeric Operators...
- •Appendix B: Operands in CoDeSys
- •Constants
- •Variables
- •Addresses
- •Functions
- •Appendix C: Data types in CoDeSys
- •Standard data types
- •Defined data types
- •Appendix D: The CoDeSys Libaries
- •The Standard.lib library
- •String functions...
- •Bistable Function Blocks...
- •Trigger...
- •Counter...
- •Timer...
- •The Util.lib library
- •BCD Conversion
- •Bit-/Byte Functions
- •Mathematic Auxiliary Functions
- •Controllers
- •Signal Generators...
- •Function Manipulators...
- •Analog Value Processing...
- •The AnalyzationNew.lib library
- •The CoDeSys System Libraries
- •Appendix E: Operators and Library Modules Overview
- •Appendix F: Command Line-/Command File
- •Command Line Commands
- •Command File (cmdfile) Commands
- •Appendix G: Siemens Import
- •Import from a SEQ Symbol File
- •Import from a S5 Project File
- •Converting S5 to IEC 61131-3
- •Appendix H: Target Settings in Detail
- •Settings in Category Target Platform
- •Appendix I: Use of Keyboard
- •Appendix J: Compiler Errors and Warnings
- •Warnings
- •Errors

10 - APPENDIX
10 APPENDIX
Appendix A: IEC Operators and additional norm extending functions
CoDeSys supports all IEC operators. In contrast with the standard functions functions (see appendix D, Standard library), these operators are recognized implicitly throughout the project. Besides the IEC operators CoDeSys also supports the following operators which are not prescribed by the standard: INDEXOF and SIZEOF (see Arithmetic Operators), ADR and BITADR (see Address Operators).
Operators are used like functions in POU.
Attention: At operations with floating point variables the result depends on the currently used target system !
•Arithmetic operators
•Bitstring Operators
•Bit-Shift Operators
•Selection Operators
•Comparison Operators
•Address Operators
•Calling Operators
•Type Conversions
•Numeric Operators
10.1Arithmetic Operators...
ADD
Addition of variables of the types: BYTE, WORD, DWORD, SINT, USINT, INT, UINT, DINT, UDINT, REAL and LREAL.
Two TIME variables can also be added together resulting in another time (e.g., t#45s + t#50s = t#1m35s)
Example in IL:
LD 7
ADD 2,4,7
ST Var1
Example in ST:
var1 := 7+2+4+7;
Example in FBD:
CoDeSys V2.3 |
10-1 |

Appendix A: - IEC Operators and additional norm extending functions
MUL
Multiplication of variables of the types: BYTE, WORD, DWORD, SINT, USINT, INT, UINT, DINT, UDINT, REAL and LREAL.
Example in IL:
LD 7
MUL 2,4,7
ST Var1
Example in ST:
var1 := 7*2*4*7;
Example in FBD:
SUB
Subtraction of one variable from another of the types: BYTE, WORD, DWORD, SINT, USINT, INT, UINT, DINT, UDINT, REAL and LREAL.
A TIME variable may also be subtracted from another TIME variable resulting in third TIME type variable. Note that negative TIME values are undefined.
Example in IL:
LD 7
SUB 2
ST Var1
Example in ST:
var1 := 7-2;
Example in FBD:
DIV
Division of one variable by another of the types: BYTE, WORD, DWORD, SINT, USINT, INT, UINT, DINT, UDINT, REAL and LREAL.
Example in IL:
LD 8
DIV 2
ST Var1 (* Result is 4 *)
Example in ST:
var1 := 8/2;
Example in FBD:
10-2 |
CoDeSys V2.3 |

Appendix A: - IEC Operators and additional norm extending functions
Note: If you define functions in your project with the names CheckDivByte, CheckDivWord, CheckDivDWord and CheckDivReal, you can use them to check the value of the divisor if you use the operator DIV, for example to avoid a division by 0. The functions must have the above listed names.
Attention: Please regard, that different target systems may behave differently concerning a division by zero !
See in the following an example for the implementation of function CheckDivReal: Example for the implementation of the function CheckDivReal:
FUNCTION CheckDivReal : REAL
VAR_INPUT divisor:REAL;
END_VAR
IF divisor = 0 THEN CheckDivReal:=1;
ELSE
CheckDivReal:=divisor; END_IF;
Operator DIV uses the output of function CheckDivReal as divisor. In a program like shown in the following example this avoids a division by 0, the divisor (d) is set from 0 to 1. So the result of the division is 799.
PROGRAM PLC_PRG
VAR erg:REAL;
v1:REAL:=799;
d:REAL; END_VAR
erg:= v1 / d;
MOD
Modulo Division of one variable by another of the types: BYTE, WORD, DWORD, SINT, USINT, INT, UINT, DINT, UDINT. The result of this function will be the remainder of the division. This result will be a whole number.
Example in IL:
LD 9
MOD 2
ST Var1 (* Result is 1 *)
Example in ST:
var1 := 9 MOD 2;
Example in FBD:
MOVE
Assignment of a variable to another variable of an appropriate type. As MOVE is available as a box in the graphic editors FBD, LD, CFC, there the (unlocking) EN/EN0 functionality can also be applied on a variable assignment.
Example in CFC in conjunction with the EN/EN0 function: Only if en_i is TRUE, var1 will be assigned to var2.
Example in IL:
LD ivar1
MOVE ivar2
CoDeSys V2.3 |
10-3 |

Appendix A: - IEC Operators and additional norm extending functions
ST ivar2 (* Ergebnis: var2 erhält Wert von var1 *)
( ! you get the same result with:
LD ivar1 ST ivar2 )
Example in ST:
ivar2 := MOVE(ivar1);
( ! you get the same result with: ivar2 := ivar1; )
INDEXOF
This function is not prescribed by the standard IEC61131-3.
Perform this function to find the internal index for a POU.
Example in ST:
var1 := INDEXOF(POU2);
SIZEOF
This function is not prescribed by the standard IEC61131-3.
Perform this function to determine the number of bytes required by the given variable.
Example in IL: arr1:ARRAY[0..4] OF INT;
Var1 INT
LD arr1 SIZEOF
ST Var1 (* Result is 10 *)
Example in ST:
var1 := SIZEOF(arr1);
10.2Bitstring Operators...
AND
Bitwise AND of bit operands. The operands should be of the type BOOL, BYTE, WORD or DWORD.
Example in IL:
Var1 BYTE
LD 2#1001_0011
AND 2#1000_1010
ST Var1 (* Result is 2#1000_0010 *)
Example in ST:
var1 := 2#1001_0011 AND 2#1000_1010
Example in FBD:
Note: If you have a program step in the SFC like the following
10-4 |
CoDeSys V2.3 |

Appendix A: - IEC Operators and additional norm extending functions
and if you use 68xxxor C-code generators, please note the following: The allocation of the value of the second input variable at the AND operator module to variable z will not be executed ! This is due to the optmized processing in the SFC in case of value FALSE at the input variable.
OR
Bitwise OR of bit operands. The operands should be of the type BOOL, BYTE, WORD or DWORD.
Example in IL: var1 :BYTE;
LD 2#1001_0011
OR 2#1000_1010
ST var1 (* Result is 2#1001_1011 *)
Example in ST:
Var1 := 2#1001_0011 OR 2#1000_1010
Example in FBD:
Note: If you have a program step in the SFC like the following
and if you use 68xxxor C-code generators, please note the following: The allocation of the value of the second input variable at the OR operator module to variable z will not be executed ! This is due to the optmized processing in the SFC in case of value FALSE at the input variable.
XOR
Bitwise XOR of bit operands. The operands should be of the type BOOL, BYTE, WORD or DWORD.
Note: Regard the behaviour of the XOR function in extended form, that means if there are more than 2 inputs. The inputs will be checked in pairs and the particular results will then be compared again in pairs (this complies with the standard, but may not be expected by the user).
Example in IL:
Var1 :BYTE;
LD 2#1001_0011
XOR 2#1000_1010
ST Var1 (* Result is 2#0001_1001 *)
Example in ST:
Var1 := 2#1001_0011 XOR 2#1000_1010
Example in FBD:
CoDeSys V2.3 |
10-5 |

Appendix A: - IEC Operators and additional norm extending functions
NOT
Bitwise NOT of a bit operand. The operand should be of the type BOOL, BYTE, WORD or DWORD.
Example in IL:
Var1 :BYTE;
LD 2#1001_0011
NOT
ST Var1 (* Result is 2#0110_1100 *)
Example in ST:
Var1 := NOT 2#1001_0011
Example in FBD:
10.3Bit-Shift Operators...
Note: Please note, that the amount of bits, which is regarded for the arithmetic operation, is pretended by the data type of the input variable !. If the input variable is a constant the smallest possible data type is regarded. The data type of the output variable has no effect at all on the arithmetic operation.
SHL
Bitwise left-shift of an operand : erg:= SHL (in, n)
in gets shifted to the left by n bits. If n > data type width, for BYTE, WORD and DWORD will be filled with zeros. But if signed data types are used, like e.g. INT, then an arithmetic shift will be executed in such cases, that means it will be filled with the value of the topmost bit.
Note: See in the following example in hexadecimal notation that you get different results for erg_byte and erg_word depending on the data type of the input variable (BYTE or WORD), although the values of the input variables in_byte and in_word are the same.
Example in ST:
PROGRAM shl_st
VAR
in_byte : BYTE:=16#45;
in_word : WORD:=16#45; erg_byte : BYTE; erg_word : WORD;
n: BYTE :=2;
END_VAR
erg_byte:=SHL(in_byte,n); (* Result is 16#14 *) erg_word:=SHL(in_word;n); (* Result is 16#01141 *)
Example in FBD:
Example in IL:
LD 16#45
SHL 2
ST erg_byte
10-6 |
CoDeSys V2.3 |

Appendix A: - IEC Operators and additional norm extending functions
SHR
Bitwise right-shift of an operand: erg:= SHR (in, n)
in gets shifted to the right by n bits. If n > data type width, for BYTE, WORD and DWORD will be filled with zeros. But if signed data types are used, like e.g. INT, then an arithmetic shift will be executed in such cases, that means it will be filled with the value of the topmost bit.
See the following example in hexadecimal notation to notice the results of the arithmetic operation depending on the type of the input variable (BYTE or WORD).
Example in ST:
PROGRAM shr_st
VAR
in_byte : BYTE:=16#45;
in_word : WORD:=16#45; erg_byte : BYTE; erg_word : WORD;
n: BYTE :=2; END_VAR
erg_byte:=SHR(in_byte,n); (* Result is 11 *) erg_word:=SHR(in_word;n); (* Result is 0011 *)
Example in FBD:
Example in IL:
LD 16#45
SHR 2
ST erg_byte
ROL
Bitwise rotation of an operand to the left: erg:= ROL (in, n)
erg, in and n should be of the type BYTE, WORD or DWORD. in will be shifted one bit position to the left n times while the bit that is furthest to the left will be reinserted from the right.
See in the following example in hexadecimal notation that you get different results for erg_byte and erg_word depending on the data type of the input variable (BYTE or WORD), although the values of the input variables in_byte and in_word are the same.
Example in ST:
PROGRAM rol_st
VAR
in_byte : BYTE:=16#45;
in_word : WORD:=16#45; erg_byte : BYTE; erg_word : WORD;
n: BYTE :=2;
END_VAR
erg_byte:=ROL(in_byte,n); (* Result is 16#15 *) erg_word:=ROL(in_word;n); (* Result is 16#0114 *)
Example in FBD:
Example in IL:
LD 16#45
ROL 2
CoDeSys V2.3 |
10-7 |