
- •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

Appendix D: - The CoDeSys Libaries
Appendix D: The CoDeSys Libaries
10.16 The Standard.lib library
10.16.1 String functions...
Please note: String functions are not "thread safe": When using tasks, string functions may only be used in a single task. If the same function is used in different tasks, there is a danger of overwriting.
LEN
Returns the length of a string. Input STR is of type STRING, the return value of the function is type INT.
Example in IL:
LD 'SUSI'
LEN
ST VarINT1 (* Result is 4 *)
Example in FBD:
Example in ST:
VarSTRING1 := LEN ('SUSI');
LEFT
Left returns the left, initial string for a given string. Input STR is type STRING, SIZE is of type INT, the return value of the function is type STRING.
LEFT (STR, SIZE) means: Take the first SIZE character from the right in the string STR.
Example in IL:
LD |
'SUSI' |
LEFT |
3 |
ST |
VarSTRING1 (* Result is 'SUSI' *) |
Example in FBD:
Example in ST:
VarSTRING1 := LEFT ('SUSI',3);
RIGHT
Right returns the right, initial string for a given string.
RIGHT (STR, SIZE) means: Take the first SIZE character from the right in the string STR.
Input STR is of type STRING, SIZE is of type INT, the return value of the function is of type STRING.
Example in IL:
CoDeSys V2.3 |
10-39 |

|
Appendix D: - The CoDeSys Libaries |
LD |
'SUSI' |
RIGHT |
3 |
ST |
VarSTRING1 (* Result is 'USI' *) |
Example in FBD:
Example in ST:
VarSTRING1 := RIGHT ('SUSI',3);
MID
Mid returns a partial string from within a string.
Input STR is type STRING, LEN and POS are type INT, the return value of the function is type STRING.
MID (STR, LEN, POS) means: Retrieve LEN characters from the STR string beginning with the character at position POS.
Example in IL:
LD 'SUSI'
MID 2,2
ST VarSTRING1 (* Result is 'US' *)
Example in FBD:
Example in ST:
VarSTRING1 := MID ('SUSI',2,2);
CONCAT
Concatenation (combination) of two strings.
The input variables STR1 and STR2 as well as the return value of the function are type STRING.
Example in IL:
LD |
'SUSI' |
CONCAT |
'WILLI' |
ST |
VarSTRING1 (* Result is 'SUSIWILLI' *) |
Example in FBD:
Example in ST:
VarSTRING1 := CONCAT ('SUSI','WILLI');
Please note: The CONCAT function does not work, if nested over more than five levels.
10-40 |
CoDeSys V2.3 |

Appendix D: - The CoDeSys Libaries
INSERT
INSERT inserts a string into another string at a defined point.
The input variables STR1 and STR2 are type STRING, POS is type INT and the return value of the function is type STRING.
INSERT(STR1, STR2, POS) means: insert STR2 into STR1 after position POS.
Example in IL:
LD |
'SUSI' |
INSERT 'XY',2 |
|
ST |
VarSTRING1 (* Result is 'SUXYSI' *) |
Example in FBD:
Example in ST:
VarSTRING1 := INSERT ('SUSI','XY',2);
DELETE
DELETE removes a partial string from a larger string at a defined position.
The input variable STR is type STRING, LEN and POS are type INT, the return value of the function is type STRING.
DELETE(STR, L, P) means: Delete L characters from STR beginning with the character in the P position.
Example in IL:
LD |
'SUXYSI' |
|
DELETE 2,3 |
|
|
ST |
Var1 |
(* Result is 'SUSI' *) |
Example in FBD:
Example in ST:
Var1 := DELETE ('SUXYSI',2,3);
REPLACE
REPLACE replaces a partial string from a larger string with a third string.
The input variable STR1 and STR2 are type STRING, LEN and POS are type INT, the return value of the function is type STRING.
REPLACE(STR1, STR2, L, P) means: Replace L characters from STR1 with STR2 beginning with the character in the P position.
Example in IL:
LD 'SUXYSI'
REPLACE 'K',2,2
ST |
VarSTRING1 (* Result is 'SKYSI' *) |
Example in FBD:
CoDeSys V2.3 |
10-41 |

Appendix D: - The CoDeSys Libaries
Example in ST:
VarSTRING1 := REPLACE ('SUXYSI','K',2,2);
FIND
FIND searches for a partial string within a string.
The input variable STR1 and STR2 are type STRING, the return value of the function is type STRING.
FIND(STR1, STR2) means: Find the position of the first character where STR2 appears in STR1 for the first time. If STR2 is not found in STR1, then OUT:=0.
Example in IL:
LD |
'SUXYSI' |
FIND |
'XY' |
ST |
VarINT1 (* Result is '3' *) |
Example in FBD:
Example in ST:
arINT1 := FIND ('SUXYSI','XY');
10.16.2 Bistable Function Blocks...
SR
Making Bistable Function Blocks Dominant: Q1 = SR (SET1, RESET) means:
Q1 = (NOT RESET AND Q1) OR SET1
The input variables SET1 and RESET as well as the output variable Q1 are type BOOL. Declaration example:
SRInst : SR ;
Example in IL:
CAL SRInst(SET1 := VarBOOL1, RESET := VarBOOL2)
LD SRInst.Q1
ST VarBOOL3
Example in FBD:
Example in ST:
SRInst(SET1:= VarBOOL1 , RESET:=VarBOOL2 );
VarBOOL3 := SRInst.Q1 ;
10-42 |
CoDeSys V2.3 |

Appendix D: - The CoDeSys Libaries
RS
Resetting Bistable Function Blocks Q1 = RS (SET, RESET1) means:
Q1 = NOT RESET1 AND (Q1 OR SET)
The input variables SET and RESET1 as well as the output variable Q1 are type BOOL. Declaration example:
RSInst : RS ;
Example in IL:
CAL RSInst(SET:= VarBOOL1,RESET1:=VarBOOL2)
LD RSInst.Q1
ST VarBOOL3
Example in FBD:
Example in ST:
RSInst(SET:= VarBOOL1 , RESET1:=VarBOOL2 );
VarBOOL3 := RSInst.Q1 ;
SEMA
A Software Semaphore (Interruptible) BUSY = SEMA(CLAIM, RELEASE) means:
BUSY := X;
IF CLAIM THEN X:=TRUE;
ELSE IF RELEASE THEN BUSY := FALSE; X:= FALSE; END_IF
X is an internal BOOL variable that is FALSE when it is initialized. The input variables CLAIM and RELEASE as well as the output variable BUSY are type BOOL.
If BUSY is TRUE when SEMA is called up, this means that a value has already been assigned to SEMA (SEMA was called up with CLAIM = TRUE). If BUSY is FALSE, SEMA has not yet been called up or it has been released (called up with RELEASE = TRUE).
Declaration example:
SEMAInst : SEMA ;
Example in IL:
CAL SEMAInst(CLAIM:=VarBOOL1,RELEASE:=VarBOOL2)
LD SEMAInst.BUSY
ST VarBOOL3
Example in FBD:
Example in ST:
SEMAInst(CLAIM:= VarBOOL1 , RELEASE:=VarBOOL2 );
VarBOOL3 := SEMAInst.BUSY;
CoDeSys V2.3 |
10-43 |