Вы находитесь на странице: 1из 454

INTERBUS

User Manual
PROGRAM WORX
Functions and Function Blocks

Designation: IBS PROGRAM WORX 2.0 FUB UM E

Revision: B

Order No.: 90 00 05 1

This manual is valid for:


IBS PCWORX 2.0

© Phoenix Contact 11/1999

5958B
Please Observe the Following Notes:

In order to guarantee the safe use of your device, we recommend that you
read this manual carefully. The following notes give you information on
how to use this manual.

Qualifications of the User Group


The products described in this manual should be installed/operated/main-
tained only by qualified application programmers and software engineers,
who are familiar with automation safety concepts and applicable national
standards. Phoenix Contact assumes no liability for damage to any
products resulting from disregard of information contained in this manual.

Explanation of Symbols Used


The attention symbol refers to an operating procedure which, if not care-
fully followed, could result in damage to equipment or personal injury.

The note symbol informs you of conditions that must strictly be observed
to achieve error-free operation. It also gives you tips and advice on hard-
ware and software optimization to save you extra work.
The text symbol refers you to detailed sources of information (manuals,
data sheets, literature, etc.) on the subject matter, product, etc. This text
also provides helpful information for the orientation in the manual.

We Are Interested in Your Opinion


We are constantly striving to improve the quality of our documents.
Should you have any suggestions or recommendations for improving the
contents and layout of our documents, please send us your comments.
Please use the fax form at the end of the manual for this purpose.

5958B
PROGRAM WORX

Statement of Legal Authority


This manual, including all illustrations contained herein, is copyright pro-
tected. Use of this manual by any third party in departure from the copy-
right provision is forbidden. Reproduction, translation and electronic or
photographic archiving or alteration requires the express written consent
of Phoenix Contact. Violators are liable for damages.
Phoenix Contact reserves the right to make any technical changes that
serve the purpose of technical progress.
Windows 3.x, Windows 95, Windows 98, Windows NT and MS-DOS are
trademarks of Microsoft Corporation.
Genesis for Windows is a trademark of ICONICS Inc.
All other product names used are trademarks of the respective organiza-
tions.

Internet
You will find current information on products from Phoenix Contact on the
Internet at www.phoenixcontact.com.

5958B
Table of contents

1 IEC 61131 runtime system................................................................................1-3


1.1 Getting familiar with ProConOS ................................................. 1-3
1.2 The ProConOS memory........................................................... 1-10
1.3 PLC applications and ProConOS............................................. 1-16
1.4 Downloading, controlling and debugging ................................. 1-26
1.5 ProConOS data types .............................................................. 1-41
1.6 Functions and Function Blocks ................................................ 1-49

2 Type conversion functions ................................................................................2-5


2.1 B_BCD_TO_*............................................................................. 2-8
2.2 BCD_TO_* ............................................................................... 2-11
2.3 BOOL_TO_*............................................................................. 2-12
2.4 BYTE_TO_* ............................................................................. 2-19
2.5 D_BCD_TO_*........................................................................... 2-26
2.6 DINT_TO_* .............................................................................. 2-29
2.7 DWORD_TO_*......................................................................... 2-41
2.8 INT_TO_* ................................................................................. 2-48
2.9 REAL_TO_* ............................................................................. 2-58
2.10 SINT_TO_*............................................................................... 2-65
2.11 STRING_TO_* ......................................................................... 2-75
2.12 TIME_TO_* .............................................................................. 2-78
2.13 TRUNC_* ................................................................................. 2-79
2.14 W_BCD_TO_*.......................................................................... 2-80
2.15 WORD_TO_* ........................................................................... 2-83

3 Numerical functions ..........................................................................................3-3


3.1 ABS ............................................................................................ 3-4

5958B i
PROGRAM WORX

3.2 ACOS ......................................................................................... 3-5


3.3 ASIN........................................................................................... 3-6
3.4 ATAN.......................................................................................... 3-7
3.5 COS ........................................................................................... 3-8
3.6 EXP ............................................................................................ 3-9
3.7 LN............................................................................................. 3-10
3.8 LOG.......................................................................................... 3-11
3.9 SIN ........................................................................................... 3-12
3.10 SQRT ....................................................................................... 3-13
3.11 TAN .......................................................................................... 3-14

4 Arithmetic functions...........................................................................................4-3
4.1 ADD............................................................................................ 4-4
4.2 ADD_T_T ................................................................................... 4-5
4.3 DIV ............................................................................................. 4-6
4.4 DIV_T_AN .................................................................................. 4-7
4.5 EXPT.......................................................................................... 4-8
4.6 MOD........................................................................................... 4-9
4.7 MOVE....................................................................................... 4-10
4.8 MUL.......................................................................................... 4-11
4.9 MUL_T_AN .............................................................................. 4-12
4.10 NEG ......................................................................................... 4-13
4.11 SUB.......................................................................................... 4-14
4.12 SUB_T_T ................................................................................. 4-15

5 Bitwise Boolean functions .................................................................................5-3


5.1 AND............................................................................................ 5-3
5.2 NOT............................................................................................ 5-4
5.3 OR.............................................................................................. 5-5

ii 5958B
Table of contents

5.4 XOR ........................................................................................... 5-6

6 Bit-string functions ............................................................................................6-3


6.1 ROL............................................................................................ 6-4
6.2 ROL_* ........................................................................................ 6-5
6.3 ROR ........................................................................................... 6-6
6.4 ROR_*........................................................................................ 6-7
6.5 SHL ............................................................................................ 6-8
6.6 SHL_*......................................................................................... 6-9
6.7 SHR.......................................................................................... 6-10
6.8 SHR_* ...................................................................................... 6-11

7 Selection functions ............................................................................................7-3


7.1 LIMIT .......................................................................................... 7-4
7.2 LIMIT_*....................................................................................... 7-5
7.3 MAX ........................................................................................... 7-6
7.4 MAX_* ........................................................................................ 7-7
7.5 MIN............................................................................................. 7-8
7.6 MIN_* ......................................................................................... 7-9
7.7 SEL .......................................................................................... 7-10
7.8 SEL_* ....................................................................................... 7-11

8 Comparison functions .......................................................................................8-3


8.1 EQ .............................................................................................. 8-4
8.2 GE .............................................................................................. 8-5
8.3 GT .............................................................................................. 8-6
8.4 LE............................................................................................... 8-7
8.5 LT ............................................................................................... 8-8
8.6 NE .............................................................................................. 8-9

5958B iii
PROGRAM WORX

9 Character string functions .................................................................................9-3


9.1 *_TO_STRING ........................................................................... 9-4
9.2 CONCAT .................................................................................... 9-7
9.3 DELETE ..................................................................................... 9-9
9.4 EQ_STRING ............................................................................ 9-11
9.5 FIND......................................................................................... 9-12
9.6 GE_STRING ............................................................................ 9-13
9.7 GT_STRING............................................................................. 9-14
9.8 INSERT .................................................................................... 9-15
9.9 LE_STRING ............................................................................. 9-17
9.10 LEFT ........................................................................................ 9-18
9.11 LEN .......................................................................................... 9-20
9.12 LT_STRING ............................................................................. 9-21
9.13 MID........................................................................................... 9-22
9.14 NE_STRING............................................................................. 9-24
9.15 REPLACE ................................................................................ 9-25
9.16 RIGHT ...................................................................................... 9-27

10 Bistable function blocks ................................................................................10-3


10.1 SR ............................................................................................ 10-3
10.2 RS ............................................................................................ 10-5

11 Edge detection function blocks.....................................................................11-3


11.1 F_TRIG .................................................................................... 11-3
11.2 R_TRIG .................................................................................... 11-5

12 Counter function blocks................................................................................12-3


12.1 CTU.......................................................................................... 12-3
12.2 CTD.......................................................................................... 12-5

iv 5958B
Table of contents

12.3 CTUD ....................................................................................... 12-7

13 Timer function blocks ...................................................................................13-3


13.1 TP............................................................................................. 13-3
13.2 TP_R ........................................................................................ 13-5
13.3 TON.......................................................................................... 13-8
13.4 TON_R ................................................................................... 13-10
13.5 TOF ........................................................................................ 13-13
13.6 TOF_R ................................................................................... 13-15

14 ProConOS functions.....................................................................................14-3
14.1 Overview .................................................................................. 14-3
14.2 COLD_RESTART .................................................................... 14-3
14.3 CONTINUE .............................................................................. 14-5
14.4 HOT_RESTART....................................................................... 14-6
14.5 WARM_RESTART ................................................................... 14-7
14.6 RD_*_BY_SYM ........................................................................ 14-9
14.7 WR_*_BY_SYM ..................................................................... 14-11

15 ProConOS function blocks ...........................................................................15-3


15.1 Overview .................................................................................. 15-3
15.2 CLR_OUT ................................................................................ 15-4
15.3 DERIVAT.................................................................................. 15-5
15.4 GET_SYM ................................................................................ 15-8
15.5 INTEGRAL ............................................................................. 15-11
15.6 RD_BOOL_BY_SYM ............................................................. 15-14
15.7 RD_INPUT_GROUP .............................................................. 15-16
15.8 WR_BOOL_BY_SYM............................................................. 15-18
15.9 WR_OUTPUT_GROUP ......................................................... 15-21

5958B v
PROGRAM WORX

16 Bit manipulation functions ............................................................................16-3


16.1 Overview .................................................................................. 16-3
16.2 BIT_TEST ................................................................................ 16-4
16.3 GET_CHAR.............................................................................. 16-5
16.4 GET_LSB ................................................................................. 16-6
16.5 GET_MSB ................................................................................ 16-7
16.6 SET_LSB ................................................................................. 16-8
16.7 SET_MSB ................................................................................ 16-9
16.8 I_BIT_IN_*.............................................................................. 16-10
16.9 R_BIT_IN_* ............................................................................ 16-12
16.10 S_BIT_IN_* ............................................................................ 16-14
16.11 PARITY_*............................................................................... 16-16
16.12 STRING_TO_BUFFER .......................................................... 16-17
16.13 SWAP..................................................................................... 16-19

17 IB Communication Blocks ............................................................................17-3


17.1 Overview .................................................................................. 17-3
17.2 IB_CONTROL .......................................................................... 17-4
17.3 PCP_CLIENT ........................................................................... 17-7
17.4 PCP_CONNECT .................................................................... 17-11
17.5 PCP_READ............................................................................ 17-14
17.6 PCP_SERVER ....................................................................... 17-18
17.7 PCP_WRITE .......................................................................... 17-22
17.8 *_TO_BUF.............................................................................. 17-25
17.9 BUF_TO_*.............................................................................. 17-33

18 TCP/IP Communication Blocks ....................................................................18-3


18.1 Overview .................................................................................. 18-3
18.2 IP_CONNECT .......................................................................... 18-4

vi 5958B
Table of contents

18.3 IP_URCV.................................................................................. 18-6


18.4 IP_USEND ............................................................................... 18-8
18.5 IP_TIME ................................................................................. 18-10
18.6 Error Codes............................................................................ 18-13

19 Fast I/O Function Blocks for ILC 200 IB .......................................................19-3


19.1 Overview .................................................................................. 19-3
19.2 DIGITAL_IN.............................................................................. 19-5
19.3 DIGITAL_OUT.......................................................................... 19-7
19.4 DIO_CTU ................................................................................. 19-9
19.5 DIO_CTD ............................................................................... 19-12
19.6 DIO_EXT_CTU ...................................................................... 19-15
19.7 DIO_EXT_CTD ...................................................................... 19-20
19.8 DIO_PPWA ............................................................................ 19-25
19.9 DIO_PWM .............................................................................. 19-28
19.10 EVENT_INIT .......................................................................... 19-31
19.11 GET_EVENT.......................................................................... 19-34
19.12 Explanations........................................................................... 19-36
19.13 Error Codes............................................................................ 19-37

5958B vii
PROGRAM WORX

viii 5958B
Section 1
This section provides information on
– the IEC 61131 runtime system
– Data Types
– Functions and Function Blocks

IEC 61131 runtime system ...................................................................................1-3


1.1 Getting familiar with ProConOS ..................................................1-3
1.1.1 The PLC development system
PROGRAM WORX and ProConOS...............................1-3
1.1.2 Parts of ProConOS ........................................................1-4
1.1.3 Platforms for ProConOS ................................................1-5
1.1.4 Technical data................................................................1-6
1.1.5 Compliance with IEC 1131-3 .........................................1-6
1.2 The ProConOS memory............................................................1-10
1.2.1 What is the ProConOS memory?.................................1-10
1.2.2 Parts of the ProConOS runtime memory .....................1-10
1.2.3 The process data memory and variables in
PROGRAM WORX ......................................................1-11
1.3 PLC applications and ProConOS..............................................1-16
1.3.1 The PLC application in the ProConOS memory ..........1-16
1.3.2 Configurations and resources ......................................1-16
1.3.3 Tasks and ProConOS ..................................................1-17
1.3.4 User tasks ....................................................................1-18
1.3.5 Tasks and watchdogs ..................................................1-23
1.3.6 Tasks and programs ....................................................1-24
1.3.7 Tasks and preemptive scheduling ...............................1-25
1.4 Downloading, controlling and debugging ..................................1-26
1.4.1 Downloading ................................................................1-26
1.4.2 Operational states in ProConOS..................................1-27
1.4.3 Changing the operational states - overview.................1-28
1.4.4 Controlling and changing operational states................1-29
1.4.5 Debugging and online mode ........................................1-30
1.4.6 Debugging and operational states ...............................1-31
1.4.7 System flags ................................................................1-33

5958B 1-1
1.5 ProConOS data types ...............................................................1-41
1.5.1 Strings..........................................................................1-41
1.6 Functions and Function Blocks .................................................1-49
1.6.1 IEC 61131-3 functions .................................................1-49
1.6.2 IEC 1131-3 function blocks ..........................................1-49
1.6.3 ProConOS functions ....................................................1-50
1.6.4 ProConOS function blocks...........................................1-50
1.6.5 IB Communication Blocks ............................................1-51
1.6.6 Bit manipulation functions ............................................1-52

1-2 5958B
IEC 61131 runtime system

1 IEC 61131 runtime system

1.1 Getting familiar with ProConOS

1.1.1 The PLC development system PROGRAM WORX


and ProConOS

The development procedure of a PLC program with PROGRAM WORX


and the control of a process with ProConOS is shown in the following fig-
ure:

PROGRAM ProConOS I/O


WORX download
I/O Process

programming controlling signals I/O


5380A001

Figure 1-1 Components of the development system

The PLC program is first programmed in PROGRAM WORX and then it is


downloaded to ProConOS where it is stored in the ProConOS memory.
After this the PLC can be started. The process signals are transmitted via
the local or decentral I/O system and drivers to ProConOS. ProConOS
stores the input signals coming from the process in its memory. During the
working cycle the PLC program calculates the output signals on the base
of the input signals. Using the driver the output signals are transmitted from
the ProConOS memory to the I/Os and the process.

5958B 1-3
PROGRAM WORX

1.1.2 Parts of ProConOS

ProConOS consists of several parts as it is shown in the following figure:

PROGRAM ProConOS I/O


WORX • I/O interface
• Communication I/O Process
interface
• System manager I/O
programming • Error manager
• Debug kernel
• Compiler
ProConOS memory
5380A002

Figure 1-2 Parts of ProConOS

1.1.2.1 I/O interface


The I/O interface is used to communicate with any I/O system. Either local
I/O systems can be used or decentral I/O systems using a fieldbus like e.g.
INTERBUS. ProConOS is able to handle different I/O systems within one
application. The I/O interface uses the driver and passes the signals be-
tween the I/O systems and the memory for signal data. The synchroniza-
tion of the I/O update with the program execution is done.

1.1.2.2 Communication interface


Via the communication interface all different types of communication pro-
tocols between PROGRAM WORX and ProConOS are handled. Such
communication protocols are e.g. downloading the PLC program, debug-
ging or transmitting error messages from ProConOS to PROGRAM
WORX.

1.1.2.3 System manager


ProConOS includes a system manager which executes the different parts
of the PLC program. The system manager handles different tasks and co-
ordinates the execution of programs. Furthermore the system manager
reads and writes the variables from the I/O image when it is necessary.

1.1.2.4 Error manager


The error manager is able to detect and to handle several types of errors
which may occur during the program execution.

1-4 5958B
IEC 61131 runtime system

If an error occurs while the online communication to PROGRAM WORX ex-


ists, an error message is displayed in the error catalogue of PROGRAM
WORX. Via the control dialog the user can look at the error message.
In case of critical errors like exceeding the fixed time interval for the execu-
tion of a program, the error manager activates a system task. In those
cases the system program associated to the task is executed. If there are
no system tasks declared in PROGRAM WORX, the program execution is
stopped.

1.1.2.5 Debug-Kernel
The debug kernel of ProConOS offers multiple debug functions such as
overwriting and forcing variables, setting breakpoints, variable and address
status with powerflow. Debug is normally done while the process is run-
ning. Nevertheless it is also possible for correcting programming errors to
debug while the process is stopped by setting breakpoints. All debug oper-
ations are executed via the PROGRAM WORX user interface.

1.1.2.6 Compiler for PLC program


In PROGRAM WORX the compilation process leaves the program in a
PLC intermediate code. The ProConOS compiler translates the PLC inter-
mediate code into a machine-executable code.

1.1.2.7 ProConOS logic analyzer


The ProConOS logic analyzer records data over a certain sampling period.
This way the behavior of variable values over a certain time period can be
viewed in PROGRAM WORX. The ProConOS logic analyzer is optional.

1.1.2.8 PDD
For automation devices such as peripheries connected via a fieldbus sys-
tem ProConOS offers the Process Data Directory (PDD) enabling a sym-
bolic access to PLC variables. Therefore the PDD contains a list of vari-
ables which is created during download. Basing on the PDD interface the
symbolic variables can easily be read or written. PDD is optional.

1.1.3 Platforms for ProConOS

ProConOS runs as a software PLC on different processor systems such as


Intel or Motorola. A lot of adaptations of ProConOS to realtime multitasking
systems such as RTXDOS or VxWorks have already been done.

5958B 1-5
PROGRAM WORX

There are certain restrictions on different target specific versions. In this


manual the overall functionality of ProConOS is described. Not all functions
are supported by all ProConOS target versions.

1.1.4 Technical data

For organizing your PLC program it might be useful to know some of the
technical data relevant for ProConOS. The technical data sometimes differ
from hardware to hardware.

Please refer to the PC WORX datasheet for detailed information.

1.1.5 Compliance with IEC 1131-3

ProConOS is in a large degree compliant with IEC 61131-3. At the end of


this manual you find an annex containing a complete list of IEC compli-
ance.
In the general help for PROGRAM WORX and in the PROGRAM WORX
Reference Manual you find an introductory chapter to IEC 61131-3. Please
refer to this documentation for detailed information.
The restrictions which apply to ProConOS are described in the following
sections.

1.1.5.1 Restrictions for data types


– Elementary data types: LINT, LREAL, TIME-OF-DAY, DATE-AND-
TIME and LWORD are not yet implemented in ProConOS.
– User-defined data types can only be used within function blocks and
programs. It is not possible to use them in functions.
– User-defined data types cannot be initialized.
– User-defined data types cannot be forced or overwritten. Exception: in
the watchlist multi-element data types can be forced and overwritten.
– While debugging arrays and structures the variables have to be copied
into the watchlist. Copying these variables into the watchlist can only
be done in the variable worksheet and not in the code body worksheet.
– Alias and subrange data types are not yet available.

1-6 5958B
IEC 61131 runtime system

– Multi-dimensional arrays cannot be declared. But it is possible to de-


clare arrays of arrays as it is shown in the following example:

– While using located variables for arrays or structs of the data type
BOOL on inputs or outputs, an error message is displayed.
– Only the data type 'INT' can be used as an array index. Expressions
like 'i + 1' are not possible.
– In arrays the data type BOOL corresponds to one byte.
– While using located variables for arrays and structures it is up to the ap-
plication programmer to check if the logical addresses which are used
really exist. No check is done in PROGRAM WORX.
– It is not possible to declare an array within the declaration of a structure
as it is shown in the following example:

5958B 1-7
PROGRAM WORX

However it is possible to declare it as it is shown in the following example:

You have to declare each data type in a data type declaration using
TYPE ... END_TYPE.

1.1.5.2 Restrictions for strings


The data type STRING always has a size of 80 characters. If your variable
of the data type STRING has four letters, the string needs 85 bytes in the
ProConOS memory. But it is possible to declare a new data type with a
user defined string length as it is shown in the following example:

If you declare several strings of different bitsizes they are all treated as the
same data type. Therefore the code body in IL is correct.
– String functions and function blocks cannot be used in networks. You
can only use single functions and function blocks storing the result to
variables.

1-8 5958B
IEC 61131 runtime system

– Strings cannot be nested while editing in ST.


– Strings cannot be used in function POUs.
– While debugging strings in online mode it might be useful to change the
width of the column for online values choosing the menu item 'Value
width' in the submenu 'Online'.

1.1.5.3 Restrictions for ST


– In IF statements it is possible to compare Boolean variables as it is
shown in the following example (var1 being a Boolean variable):

IF var1=TRUE THEN ...;

However, it is recommended to use another representation because it


is faster in execution and compilation and less code will be generated.
Use following representation:

IF var1 THEN ....;

– In a FOR statement it can only be counted upwards. Therefore the in-


crement value after the keyword BY must always be positive.
– In a FOR statement the variable 'a' and the increment value can be
changed within the body of the statement. No error message or warn-
ing is displayed if you enter the following example:

FOR i=0 TO 10 BY5


DO i:=10;

Be very careful using such a statement structure.


– In a function call no assignments can be used. The following example
is not possible:

a:= SIN(b:=3);

– In an expression all operations are processed. Parts of an expression


which have no impacts on the result are also processed. In the follow-
ing example c>d is also processed if a<b is FALSE:

a:=a<b AND c>d;

5958B 1-9
PROGRAM WORX

1.2 The ProConOS memory

1.2.1 What is the ProConOS memory?

Typically a PLC has several types of physical memories for different pur-
poses. ProConOS supports various types of hardware-specific memory
configuration. The relation between the different parts of the ProConOS
memory and the physical memory of the hardware is set in most cases by
doing the adaptation of ProConOS.
For storing a PLC program in a way that it is still available having switched
off the PLC or after power failure Flash EPROM, hard disks or other non-
volatile memories can be used.
For storing retentive variables a battery-buffered RAM is often used while
this type of memory provides short access and remanent storage.
The ProConOS runtime memory is the memory where the whole PLC pro-
gram and all corresponding data are stored during runtime.

1.2.2 Parts of the ProConOS runtime memory

The ProConOS runtime memory consists of several parts which are dedi-
cated to different data types. The following figure shows the different parts
of the ProConOS runtime memory:

PLC program — Memory for the PLC program

Buffer — Buffer for internal system data


I

Q — Process data memory


M
RM
Bootproject — Non-volatile memory for bootproject
Zipped Project — Non-volatile memory for zipped project
5380C003

Figure 1-3 Parts of the ProConOS runtime memory

1-10 5958B
IEC 61131 runtime system

1.2.2.1 Buffer
The buffer is an internal part of the memory where ProConOS stores all in-
ternal system data. ProConOS uses this buffer e.g. to handle the commu-
nication with PROGRAM WORX. E.g. error messages which are going to
be transmitted to PROGRAM WORX are stored in the buffer.

1.2.2.2 Memory for the PLC program


In the memory for the PLC program all parts of the PLC program are stored
which are used during runtime. This means all programs, function blocks
and functions, tasks and configuration data.

1.2.2.3 Process data memory


In the process data memory all data are going to be stored. The process
data memory can be separated into several parts.
– Memory area 'I' for inputs read from the process.
– Memory area 'Q' for outputs written to the process.
– Memory area 'M' for all variables which are neither inputs nor outputs.
The memory for inputs and outputs is also called I/O image.
According to your hardware memory configuration you may have another
memory region called 'RM' for retentive data.

1.2.3 The process data memory and variables in PRO-


GRAM WORX

In PROGRAM WORX you can either use symbolic or located variables.


These two types of variables are stored in different areas in the process
data memory. In the following sections the way is described how to declare
the variables in PROGRAM WORX and where the variables are stored in
the memory. Hints for structuring the variable declarations are also given.

1.2.3.1 Symbolic variables


Symbolic variables are variables whose variable declaration consists of a
symbolic name and a data type. An initial value for initializing the variable
can be used optionally. An example for the declaration of a symbolic vari-
able is shown in the following figure:

5958B 1-11
PROGRAM WORX

Figure 1-4 Declaration of a symbolic variable

In the example the symbolic name of the variable is ’var1’ and its data type
is BOOL.
Doing such a variable declaration in PROGRAM WORX means that the
variable is stored somewhere in the memory area ’M’ of the ProConOS pro-
cess data memory. The logical memory address is not known by the appli-
cation programmer.
All required variables e.g. for temporaries should be declared as symbolic
variables. This is useful because you do not need to take care of unique
memory addresses. It will be automatically done by PROGRAM WORX.

1.2.3.2 Located variables


Located variables are variables whose variable declarations consist of a
symbolic name, the location and the data type. An initial value for initializing
the variable can be used optionally. An example for the declaration of three
located variables is shown in the following figure:

Figure 1-5 Declaration of located variables

In the example the symbolic names of the variables are ’var1’, ’var2’ and
’var3’ and their data types are BOOL. The location is declared using the
IEC 61131-3 keyword ’AT’ followed by ’%’. ’I’, ’Q’ and ’M’ represent the
memory areas ’I’, ’Q’ and ’M’. The prefix ’X’ represents the bitsize.
The variable ’var1’ e.g. is stored in the ProConOS memory area ’I’ at the
logical address ’2.2’ and with a size of one bit. The logical address and its
bitsize are set by the application programmer.

1-12 5958B
IEC 61131 runtime system

The logical addresses which can be used for ’I’ or ’Q’ variables are deter-
mined by the input and output devices (e.g. fieldbus) you are using. The
used logical addresses have to correspond with the areas fixed in the I/O
configuration of PROGRAM WORX.
The logical addresses which can be used for ’M’ variables being also called
flags are determined by the settings of the user areas in the dialog ’Data
Area’ of PROGRAM WORX.
The memory ’M’ where ’var3’ of the example is stored is separated into two
parts. One part is used for all located variables of the type ’M’. This part is
called the user part of the memory ’M’. The other part is used for all sym-
bolic variables. These symbolic variables are automatically stored by PRO-
GRAM WORX in free memory areas as mentioned in the previous chapter.
If located ’M’ variables are used, the checkbox ’Declare user memory in I/
O configuration automatically’ of the dialog ’Data Area’ should be checked.
Be very careful using located variables. It is up to you to check that no ad-
dress is used twice. No error message is displayed in PROGRAM WORX
if you are using an address twice!
Use only logical addresses of the user part of the memory area ’M’ while
declaring located variables of type ’M’! A data consistency can only be as-
sured this way!
It might be useful to declare all inputs and outputs as global variables. This
means they have to be declared as located variables in the global variable
declaration using the keyword ’VAR_GLOBAL’. In the ’VAR_EXTERNAL’
declaration of programs and function blocks they are declared as symbolic
variables. If the memory addresses change, you have to change them only
in the global variable declaration and leave all other declarations un-
changed.

1.2.3.3 Retentive variables


In PROGRAM WORX it is also possible to declare retentive variables. It de-
pends on your hardware memory configuration whether it is possible to
store retentive data.
Refer to your hardware documentation for information about non-volatile
memory for retentive data.
The memory for retentive data is a non-volatile memory which retains the
data in case of switching off or power failure. Retentive variables are de-
clared in PROGRAM WORX using the keyword VAR RETAIN in the corre-
sponding variable declaration. Retentive data have to be stored in the
memory region ’RM’ of the ProConOS process data memory.

5958B 1-13
PROGRAM WORX

If you are declaring retentive data in PROGRAM WORX without having a


non-volatile memory, it is not possible to download the project and an error
message is displayed in the error catalogue in PROGRAM WORX.

1.2.3.4 System flags


System flags provide information about the internal state of ProConOS dur-
ing runtime. The system flags have fixed memory addresses and can be
used as symbolic variables in PROGRAM WORX. All available system
flags and their symbolic names are explained in the chapter ’Downloading,
controlling and debugging’.

1.2.3.5 Shared memory flags


In many embedded systems where ProConOS is combined with other soft-
ware parts (e.g. CNC) it is useful that these parts have common data called
shared memory. If a ProConOS system provides shared memory flags,
these flags can be addressed using the optional flag selector ’3’. The fol-
lowing figure shows an example how to address a shared memory flag:

Figure 1-6 Addressing a shared memory flag

The logical address consists of the flag selector, the addressed BYTE and
the addressed bit.
Please note that the initialization of the shared memory flags is done sys-
tem-dependent and is normally NOT done by ProConOS during a cold or
warm start.
To initialize the shared memory flags during a cold or a warm start use the
function block MEMSET in the relating SPGs (warm start = SPG 0; cold
start = SPG 1). The procedure to install a system task in order to react on
SPGs is described in the chapter ‘PLC applications and ProConOS’ in this
manual.

1-14 5958B
IEC 61131 runtime system

Example:

Table 1-1 Example to initialize a shared memory flag or area

Variable Description
Error indicates an occurred error
valueToSet this variable includes the value which should be set to
the shared memory flag or area
numberOfByte number of bytes which should be set
startAddress start address of the shared memory area
Memset do not care about

For more detailed information to the function block MEMSET please refer
to the function block help of PROGRAM WORX.

How to use variables in PROGRAM WORX


For using variables in PROGRAM WORX you have to do the following
main steps:
• Declaring global variables in the global variable declaration in the sub-
tree ’Physical Hardware’ of the project tree.
• Declaring global variables as VAR_EXTERNAL in the variable declara-
tion of the POU where you want to use them.
• Declaring local variables in the variable declarations of the POU.
• Inserting the variables in the corresponding code body worksheets.

Refer to the specific help for PROGRAM WORX for detailed information.

5958B 1-15
PROGRAM WORX

1.3 PLC applications and ProConOS

1.3.1 The PLC application in the ProConOS memory

A PLC application is structured in the ProConOS memory as it is shown in


the following figure:

Resource

Tasks Variables Functions Function blocks


global local variables local variables
variables code body code body
incl. calls of incl. calls of
user task 1 user task 16 functions functions and
function blocks

Program Program
local variables local variables
code body code body
incl. calls incl. calls
5380A004

Figure 1-7 Structure of a PLC application in ProConOS

The main elements of a PLC application are explained in the following sec-
tions.

1.3.2 Configurations and resources

According to IEC 61131-3 a PLC system consists of several configuration


elements. The configuration element ’configuration’ can be compared to a
complete PLC since it includes all elements with some I/Os. A configuration
contains one or several resources. A resource corresponds to an applica-
tion for a PLC. It can be compared to a CPU.
A resource contains the task definitions and the definitions of all programs,
function blocks, functions and variables. ProConOS is able to handle sev-
eral tasks within one resource.

1-16 5958B
IEC 61131 runtime system

In ProConOS the configuration and the resource have the same function-
ality. Nevertheless it is necessary to declare one configuration and one re-
source in the subtree ’Physical Hardware’ of the project tree.

How to declare resources in PROGRAM WORX


For declaring a resource in PROGRAM WORX you have to do the following
main steps:
• Inserting the resource into the subtree ’Physical Hardware’ of the
project tree.
• Choosing the resource settings in the dialog ’Resource settings...’
which is called choosing the menu item ’Settings...’ in the context menu
of the resource.
Refer to the specific help of PROGRAM WORX for detailed information
about inserting configurations, resources and resource settings.

1.3.3 Tasks and ProConOS

ProConOS is embedded in a realtime operating system which is controlled


by task priorities. Three task levels are used in ProConOS:
– Supervisor task level
– User task level
– ProConOS task level

Priority
high supervisor task supervisor task level

user task user task level

user default task default task level

ProConOS task ProConOS task level


low
5380A005

Figure 1-8 Task levels in ProConOS

5958B 1-17
PROGRAM WORX

ProConOS itself consists of several tasks such as communication task,


debug task, memory management task and system control task. All these
tasks are running in a specific priority level called ProConOS task level.
User tasks are all tasks specified by the application programmer which rely
on the IEC 61131-3 programming languages and the execution control of
the programs under the control of tasks. These kinds of tasks run in the
specific user task level. This means that all user-defined priorities are not
absolute but relative to the user task level. The settings for these tasks
have to be done in PROGRAM WORX. The DEFAULT task also belongs
to the user task level. It is the user task with the lowest priority. The DE-
FAULT task is going to be executed if no other user task is currently run-
ning.
In ProConOS there is a special protected task level which is the supervisor
level. The supervisor task of ProConOS is a system task which runs on the
highest priority level. The supervisor task detects errors such as division by
zero or excess of execution time and activates the corresponding system
task.

1.3.4 User tasks

User tasks have to be declared by the programmer. In ProConOS several


user tasks can be used. The different task types offer different characteris-
tics for different application purposes.

1.3.4.1 DEFAULT task


The default task is the task with the lowest priority which is executed if no
other user task is running. The default task is a cyclic task. This means that
having finished one cycle of the default task always the next cycle is
started. The name of the default task is DEFAULT. To insert a DEFAULT
task in PROGRAM WORX just enter the name in capital letters and choose
as task type ’CYCLIC’.
The cycle time for the DEFAULT task is basically determined by the CPU
load, the size of the associated programs and the system tick. If the system
tick is 1 ms the cycle time for the DEFAULT task is greater or equal than 2
ms. The cycle time of the DEFAULT task and the system tick are displayed
in the dialog ’Resource: resource name’ which can be called pressing the
button ’Info’ in the control dialog.

1-18 5958B
IEC 61131 runtime system

1.3.4.2 Cyclic tasks


Cyclic tasks are executed in a fixed time interval. They are executed ac-
cording to their priority which has to be set in the dialog ’Task settings...’.
This dialog is called choosing the menu item ’Settings...’ in the context
menu of the task in the subtree ’Physical Hardware’ of the project tree. The
priority value range is from 0 to 31 being 0 the highest priority.
If the watchdog time of a cyclic task is higher than the configured interval
time and the execution of the task is not finished before the end of the con-
figured interval time is reached, one or more execution cycles are skipped.

1.3.4.3 Event tasks


An event task is activated if the corresponding hardware event occurs.
Hardware events have a number which has to be entered in the dialog
’Task settings...’ as the event number. ProConOS is able to put up to 16
events into a queue. Therefore if new events occur before the associated
event task is executed, they do not get lost and are executed later.

1.3.4.4 System tasks


System tasks can be used in ProConOS and PROGRAM WORX. The sys-
tem tasks are initial tasks and error tasks. System tasks are going to be ex-
ecuted if the PLC is started or if an error occurs. In both cases ProConOS
knows which system program has to be executed.
System tasks are not supervised by the watchdog, because they are not
executed in the context of a user task.
System programs or SPGs are programs which are called automatically by
ProConOS if an error or a change of the operational state of the PLC oc-
curs. Different types of system programs are available as it is shown in the
following table:

Table 1-2 System programs

No. Name Meaning Actions


SPG 0 WARM_START is executed if a warm start is – retentive data are not initialized
done – non-retentive data are initialized
– the open function of the I/O driver
is executed
– user tasks are activated
– PLC passes into the state 'RUN'

5958B 1-19
PROGRAM WORX

Table 1-2 System programs

No. Name Meaning Actions


SPG 1 COLD_START is executed if a cold start is – all data are initialized
done – the open function of the I/O driver
is executed
– user tasks are activated
– PLC passes into the state 'RUN'
SPG 2 TO_STOP is executed if the program exe- – user tasks are deactivated
cution is stopped – all outputs are updated
– the close function of the I/O driv-
er is executed
– PLC passes into the state 'STOP'
SPG 10 WATCHDOG is executed if the execution of – user tasks are deactivated
a task has not been finished – all outputs are updated
within its watchdog time
– the close function of the I/O driv-
er is executed
– PLC passes into the state 'STOP'
SPG 11 ZERODIV is executed if a division by zero – user tasks are deactivated
occurs during the program ex- – all outputs are updated
ecution
– the close function of the I/O driv-
er is executed
– PLC passes into the state 'STOP'
SPG 12 STACKOVER is executed if a stack overflow – user tasks are deactivated
happens. Only executed if the – all outputs are updated
check box 'Stack check' has
– the close function of the I/O driv-
been activated in the dialog
er is executed
'Resource settings...' in PRO-
GRAM WORX – PLC passes into the state 'STOP'

SPG 13 BADCAL is executed if a firmware POU – user tasks are deactivated


is called which does not exist – all outputs are updated
– the close function of the I/O driv-
er is executed
– PLC passes into the state 'STOP'

1-20 5958B
IEC 61131 runtime system

Table 1-2 System programs

No. Name Meaning Actions


SPG 14 IOERROR is executed if an error in the I/O – PLC continues
driver occurs while the process
is running
SPG 16 MATHERR is executed if a floating point – user tasks are deactivated
error in an arithmetic function – all outputs are updated
occurs
– the close function of the I/O driv-
er is executed
– PLC passes into the state 'STOP'
SPG 17 CPU_OVERLOAD is executed if a CPU overload – user tasks are deactivated
occurs – all outputs are updated
– the close function of the I/O driv-
er is executed
– PLC passes into the state 'STOP'
SPG 18 INITIODRV_ERR is executed if an error occurs – PLC is not started
while initializing the I/O driver
during a cold or a warm start
SPG 19 BOUNDS_ERR is executed if the bounds of an – user tasks are deactivated
array or structure have been – all outputs are updated
exceeded. Only executed if the
– the close function of the I/O driv-
check box 'Index check' or the
er is executed
check box 'Array boundary
check' has been activated in – PLC passes into the state 'STOP'
the dialog 'Resource set-
tings...' in PROGRAM WORX
SPG 20 BUS_ERR is executed if variables with lo- – user tasks are deactivated
cation and data type ≥ 2 bytes – all outputs are updated
have been used with odd ad-
– the close function of the I/O driv-
dresses or if there has been an
er is executed
internal error in PROGRAM
WORX. Only in case of Motor- – PLC passes into the state 'STOP'
ola platforms.

5958B 1-21
PROGRAM WORX

Table 1-2 System programs

No. Name Meaning Actions


SPG 21 STRING_ERR is executed if an error during a – The behavior of a string excep-
string operation appears, e.g. a tion has changed! In the default
string should be replaced by configuration the SPG 21 is
another but it is not found. called after a string exception oc-
curs and an entry in the error cat-
alogue is made including the
module and the line number. The
PLC keeps in the state 'RUN'.
– In a customer specific Pro-
ConOS the behavior may be de-
fined as the following:
– all user tasks are deactivated
– all outputs are updated
– the close function of the I/O driv-
er is executed
– PLC passes into the state 'STOP'

How to declare user tasks in PROGRAM WORX


For declaring user tasks in PROGRAM WORX you have to do the following
main steps:
• Inserting the task in the subtree ’Physical Hardware’ of the project tree.
• Choosing the task settings in the dialog ’Task settings...’ which is called
choosing the menu item ’Settings...’ in the context menu of the task.
• Associating programs to the task.
Refer to the specific help of PROGRAM WORX for detailed information
about inserting tasks and task settings.

How to use system tasks and SPGs in case of ProConOS errors


If a runtime error occurs in ProConOS such as a division by zero or a stack
overflow, the corresponding SPG is automatically executed without any
programming effort done by the application programmer.
If an additional functionality is needed e.g. all outputs should be set to zero,
the application programmer has got the possibility to edit the corresponding
code in PROGRAM WORX.

1-22 5958B
IEC 61131 runtime system

The function block CLR_OUT can be used to set all outputs to zero. The
functions COLD_RESTART, WARM_RESTART, HOT_RESTART and
CONTINUE can be used to restart or continue the program execution.
These functions and function blocks are described in the context-sensitive
help.
For editing the additional functionality in PROGRAM WORX you have to do
the following main steps:
• Editing a program with the code body containing the additional func-
tionality in the subtree ’Logical POUs’ of the project tree.
• Inserting a task of the type ’SYSTEM’ in the subtree ’Physical Hard-
ware’ of the project tree.
• Calling the dialog ’Task settings...’ to choose the SPG where you want
to add the functionality.
• Associating the program to the system task.

1.3.5 Tasks and watchdogs

In ProConOS each user defined task has got its own adjustable watchdog.
This watchdog checks if the task execution has been finished at the end of
the watchdog time interval. If it has not been finished, the system task SPG
10 ’WATCHDOG’ is executed and the PLC passes into the state ’STOP’ if
no other actions are programmed there. An entry in the error catalogue of
ProConOS is also made. The watchdog time interval starts when the task
is ready for execution. The watchdog time interval is set in the dialog ’Task
settings...’ in PROGRAM WORX which is described in the section ’Task
settings and their meaning’ of this chapter.
If the task execution time and the watchdog time have nearly the same
value and a high CPU load is given, it might be possible that the watchdog
time exceeds while realizing some online operations.
One cause for this behavior may be that you have activated the address
status with powerflow while debugging in online mode.
Online operations which cause a reading or writing access on the hard disk
may also interrupt the task execution for a short time. These online opera-
tions are e.g.:
– Calling the dialog 'Resource:resource name' doing a left mouse click
on the button 'Info' in the control dialog
– Download bootproject
– Download zipped project.

5958B 1-23
PROGRAM WORX

In the following figure it is shown that a task exceeds its watchdog time be-
cause the execution of the task is shortly interrupted for several times.

Figure 1-9 Interruption of task execution

In the example the watchdog time of the shown task is set to 10 ms. In the
figure the task exceeds its watchdog time at 20 ms. If the watchdog time of
the task is set to 20 ms, it is executed for the next time at 30 ms. In this case
one task execution at 20 ms is skipped.

1.3.6 Tasks and programs

Programs are program organization units or POUs as defined in IEC


61131-3. The code bodies for programs are edited in PROGRAM WORX.
Within these programs other programs, function blocks or functions can be
called.
Programs have to be associated to a task. Associating a program to a task
means that the program is executed when the task is activated. In Pro-
ConOS and PROGRAM WORX it is possible to associate several pro-
grams to one task. In those cases the first program in the task directory is
executed first. Then the program below is executed and so on.
Please refer to the PROGRAM WORX Reference Manual for detailed in-
formation about programs.

How to use programs in PROGRAM WORX


For using programs in PROGRAM WORX you have to do the following
main steps:
• Inserting the program in the subtree ’Logical POUs’ of the project tree.

1-24 5958B
IEC 61131 runtime system

• Editing the code body.


• Doing the variable declaration.
• Compiling the program.
• Associating the program to a task.

1.3.7 Tasks and preemptive scheduling

Let us imagine a PLC application with three user tasks and the default task.
The tasks have the following properties:

Fast task: cyclic task with time interval of 10 ms, attached is


program P1
Event task: event task, attached is program P2
Main task: cyclic task with time interval of 25 ms, attached are
programs P3 and P4
Default task: cyclic task without fixed time interval, attached are
programs P5 and P6
System tasks: ProConOS system tasks e.g. for communication
debug etc.

The resulting task scheduling is shown in the following figure:

Task Priority

System Puls

Fast Task P1 P1 P1 P1 P1

Event Task P2 P2

Main Task P3 P4 P3 P4 P4

DEFAULT- P5 P6 P6 P5 P6
Task
ProConOS
System Tasks Time
0 ms
10 20 30 40 50

Task ready Task signals (Task will change to state 'ready') 5380C006

Figure 1-10 Tasks and preemptive scheduling

5958B 1-25
PROGRAM WORX

At first the fast task having the highest priority is executed. Then the task
with the next lower priority is executed which is the main task. The pro-
grams associated to the task are executed according to their appearance
in the project tree. Afterwards the Default task is executed, being the user
task with the lowest priority. The Default task is interrupted by the fast task
at 10 ms being the time interval for the execution of the fast task. The data
of the Default task are written to the stack. Having executed the fast task,
the data for the Default task are read from the stack and the execution is
finished. The ProConOS system tasks are executed if no other task is ex-
ecuted.
This task switching with interrupting tasks with lower priority is called pre-
emptive scheduling.

1.4 Downloading, controlling and debugging

1.4.1 Downloading

Before downloading an application to ProConOS you have to compile it in


PROGRAM WORX. Downloading means sending the project to the target.
Downloading is done by pressing the button ’Download’ in the control dia-
log in PROGRAM WORX and by pressing the corresponding button in the
dialog ’Download’ which appears automatically.
Several possibilities of download can be used with ProConOS:
– Downloading a project
– Downloading a zipped project
– Downloading a bootproject
Downloading a project means that the full project including POUs and the
configuration data are downloaded to the ProConOS memory of the target.
The PLC passes into the state 'STOP'. Switching off the PLC or in case of
power failure, the project does not remain in the memory. To start the pro-
gram execution after download you have two possibilities: cold start and
warm start. During a cold start all data are initialized, during a warm start
only non-retentive data are initialized.

1-26 5958B
IEC 61131 runtime system

Downloading a zipped project means that the project is zipped first and
then downloaded to the PLC. The zipped project can be uploaded via the
dialog ’Upload’ in PROGRAM WORX. The zipped project should be down-
loaded for documentation purposes if the application development has
been finished and taken into operation.
Downloading a bootproject means downloading a full project including
POUs and the configuration data to a non-volatile memory of the target.
Having switched off the PLC or in case of power failure, the bootproject re-
mains in the non-volatile memory. In case of switching the PLC on, the
bootproject is loaded and the program execution is automatically started.
Refer to the specific help for PROGRAM WORX for information about
downloading.

1.4.2 Operational states in ProConOS

ProConOS works with four different operational states:

Table 1-3 Operational states in ProConOS

Operational state Description of the operational state


POWER ON – power supply is on
– no program is loaded
STOP – program is loaded
– user tasks are inactive
– inputs of the I/O image are not updated
– output signals are not transmitted to the I/Os
RUN – program execution is activated
– user tasks are active
– inputs of the I/O image are updated according to the
I/O configuration
– outputs of the I/O image are updated according to
the I/O configuration and the program execution
HALT – program execution is halted at a breakpoint
– user tasks are inactive
– inputs of the I/O image are not updated
– outputs of the I/O image are not updated

5958B 1-27
PROGRAM WORX

The current state of the PLC is displayed either on the top of the control di-
alog or in the dialog ’Resource: resource name’ in PROGRAM WORX.
If ’debug’ is displayed behind the current state in the control dialog, it
means that breakpoints have been set or variables have been forced.

1.4.3 Changing the operational states - overview

Using the control dialog in PROGRAM WORX you can change the opera-
tional state of the PLC. The following figure show from which state you can
switch to another. The names of the buttons in the control dialog are written
next to the arrows. The buttons for changes which cannot be done in the
current state are grayed in the control dialog.

Power on
Cold start with
Reset Download bootproject
project

Stop
Cold
Stop Run
Warm
Hot
Breakpoint
Restart
set

Halt
5380A007

Figure 1-11 Changing into different operational state

1-28 5958B
IEC 61131 runtime system

1.4.4 Controlling and changing operational states

Via the graphical user interface of PROGRAM WORX it is possible to con-


trol the PLC starting and stopping the program execution. The following
section describe how to change the states and what happens on Pro-
ConOS.

Starting the program execution

State is changed Button to press Description of what happens


from ➠ to in the control
dialog
Stop ➠ Run – a cold start is done
– all data are initialized
– SPG 1 is called
– all user tasks are activated
– the program execution is
activated
Stop ➠ Run – a warm start is done
– only non-retentive data are
initialized
– SPG 0 is called
– all user tasks are activated
– the program execution is
activated
Stop ➠ Run – a hot start is done
– no data are initialized
– all user tasks are activated
– the program execution is
activated
– Not available in case of
starting the program execu-
tion for the first time after
downloading

5958B 1-29
PROGRAM WORX

Stopping the program execution

State is changed Button to press Description of what happens


from ➠ to in the control
dialog
Run ➠ Stop – all user tasks are set inac-
tive having finished their
working cycle
– SPG 2 is called
– the outputs of the I/O image
are written
– the program execution is
stopped
– according to the I/O driver
the physical outputs are
written or not

General reset

State is changed Button to press Description of what happens


from ➠ to in the control
dialog
Stop ➠ Power on – the project is deleted
– a general reset is done

1.4.5 Debugging and online mode

While the PLC is running, several functions for debugging your PLC pro-
gram can be used in ProConOS.
The following debug possibilities are available for ProConOS:
– Viewing the current variable values represented with colors in the work-
sheets in online mode
– Switching between variable status and address status with powerflow
– Forcing and overwriting variables
– Setting and resetting breakpoints

1-30 5958B
IEC 61131 runtime system

All these functions can be handled via the graphical user interface of PRO-
GRAM WORX where you can open the worksheets in online mode using
the instance tree. The ways how to proceed are described in the specific
help for PROGRAM WORX.
Using the address status with powerflow means that the program execution
of the first task inserted in the project tree is interrupted just for a short time
to read the current values of all variables. In case of a great number of ad-
dresses to be read the realtime conditions may not be met.

1.4.6 Debugging and operational states

Debugging with set breakpoints

Operational Button to press Description of what happens


state in the control
dialog
Halt [Debug] – only available if a breakpoint has
been set
– goes to the next breakpoint and
halts the program execution at
this point
Halt [Debug] – only available if a breakpoint has
been set
– goes to the next line or object
and halts the program execution
at this point
– if a function or function block call
is reached, the function or func-
tion block code body is opened
for debugging

5958B 1-31
PROGRAM WORX

Operational Button to press Description of what happens


state in the control
dialog
Halt [Debug] – only available if a breakpoint has
been set
– goes to the next line or object
and halts the program execution
at this point
– if a function or function block call
is reached, the call is stepped
over and the next line is high-
lighted
– if the end of a program is
reached, the next STEP com-
mand starts the program execu-
tion at the begin of the program
the program is stopped at the
next breakpoint
– if the end of a function or function
block is reached , the next STEP
command continues the pro-
gram debugging at the caller of
the function or function block

1-32 5958B
IEC 61131 runtime system

Stopping the PLC while debugging

State is changed Button to press Description of what happens


from ➠ to in the control
dialog
Halt [Debug] ➠ – all user tasks are set inac-
Stop [Debug] tive having finished their
working cycle
– SPG 2 is called
– the outputs of the I/O image
are written
– the program execution is
stopped
– according to the I/O driver
the physical outputs are
written or not

1.4.7 System flags

System flags are flags giving information about the system state such as
forced variables, CPU performance etc. These flags have fixed memory
addresses and can be used by the PLC program to get this information.
All system flags in the following table are already declared as global vari-
ables in the global variable worksheet if you are creating a project in PRO-
GRAM WORX. To use them in POUs just declare a symbolic variable in the
variable worksheet of the POU using the keyword VAR_EXTERNAL and
the name of the system flag as variable name.
The system flags are shown in the following tables:

Table 1-4 ProConOS system flags

Name Data type Logical address Description


PLCMODE_ON BOOL AT %MX1.0.0 TRUE :=
current PLC mode is POWER ON
PLCMODE_RUN BOOL AT %MX1.0.1 TRUE := current PLC mode is RUN
PLCMODE_STOP BOOL AT %MX1.0.2 TRUE := current PLC mode is STOP

5958B 1-33
PROGRAM WORX

Table 1-4 ProConOS system flags

Name Data type Logical address Description


PLCMODE_HALT BOOL AT %MX1.0.3 TRUE := current PLC mode is HALT
PLCDEBUG_BPSET BOOL AT %MX1.1.4 TRUE :=
one or more breakpoints are set
PLCDEBUG_FORCE BOOL AT %MX1.2.0 TRUE :=
one or more variables are forced
PLCDEBUG_POWERFLOW BOOL AT %MX1.2.3 TRUE := powerflow is active
PLC_TICKS_PER_SEC INT AT %MW1.44 Number of system ticks per second
used by ProConOS as system time
base. This value defines the time res-
olution of ProConOS for timer func-
tion blocks like TON, TOF or TP and
the shortest cycle time of the default
task and cyclic tasks
PLC_SYS_TICK_CNT DINT AT %MD1.52 Number of counted ProConOS sys-
tem ticks

Information on the INTERBUS master’s diagnostic status register and di-


agnostic parameter register can be accessed via the following system vari-
ables:

Table 1-5 INTERBUS Master system flags

Name Data type Logical address Description


MASTER_DIAG_STATUS_ BOOL AT %MX1.60001.0 TRUE :=
REG_USER an user error occurs
MASTER_DIAG_STATUS_ BOOL AT %MX1.60001.1 TRUE :=
REG_PF an peripheral fault occurs
MASTER_DIAG_STATUS_ BOOL AT %MX1.60001.2 TRUE :=
REG_BUS an remote bus (RB) - or local bus (LB)
- fault occurs
MASTER_DIAG_STATUS_ BOOL AT %MX1.60001.3 TRUE :=
REG_CTRL Controller board error

1-34 5958B
IEC 61131 runtime system

Table 1-5 INTERBUS Master system flags

Name Data type Logical address Description


MASTER_DIAG_STATUS_ BOOL AT %MX1.60001.4 TRUE :=
REG_DTC Detection (bus error localization is run-
ning)
MASTER_DIAG_STATUS_ BOOL AT %MX1.60001.5 TRUE :=
REG_RUN Data cycles are running
MASTER_DIAG_STATUS_ BOOL AT %MX1.60001.6 TRUE :=
REG_ACT the bus is active (only ID cycles are
running)
MASTER_DIAG_STATUS_ BOOL AT %MX1.60001.7 TRUE :=
REG_RDY Controller board is ready
MASTER_DIAG_STATUS_ BOOL AT %MX1.60000.0 TRUE :=
REG_BSA one or more bus segments are
switched off
MASTER_DIAG_STATUS_ BOOL AT %MX1.60000.1 TRUE :=
REG_SYSFAIL system failure of the host system (lock
the output data)
MASTER_DIAG_STATUS_ BOOL AT %MX1.60000.2 TRUE :=
REG_RES result of a standard function (1 = neg-
ative)
MASTER_DIAG_STATUS_ BOOL AT %MX1.60000.3 TRUE :=
REG_SYNCRES synchronization error (only in synchro-
nous mode of operation)
MASTER_DIAG_STATUS_ BOOL AT %MX1.60000.4 TRUE :=
REG_DCR data cycle error (only in synchronous
mode of operation)
MASTER_DIAG_STATUS_ BOOL AT %MX1.60000.5 TRUE :=
REG_WARN bus warning time has run out
(parameterizable)
MASTER_DIAG_STATUS_ BOOL AT %MX1.60000.6 TRUE :=
REG_QUAL bus quality has deteriorated

5958B 1-35
PROGRAM WORX

Table 1-5 INTERBUS Master system flags

Name Data type Logical address Description


MASTER_DIAG_STATUS_ BOOL AT %MX1.60000.7 TRUE :=
REG_SSINFO there is still a message in the standard
signal interface
MASTER_DIAG_PARAM_ WORD AT %MW1.60002 Additional information about the errors
REG displayed in the diagnostic status reg-
ister, for example error code, error lo-
cation etc.

Table 1-6 INTERBUS Slave system flags

Name Data type Logical address Description


SLAVE_DIAG_STATUS_ BOOL AT %MX1.60010.0 TRUE :=
REG_DTA_TRNS data is exchanged with the INTERBUS
slave
SLAVE_DIAG_STATUS_ BOOL AT %MX1.60010.1 TRUE :=
REG_FAIL data cannot be exchanged with the slave
due to an error. The higher level INTER-
BUS is currently not active due to a bus
error, for example. The slave’s outputs
will be reset to zero.
SLAVE_DIAG_STATUS_ BOOL AT %MX1.60010.2 TRUE :=
REG_INIT slave has been successfully initialized.
However, INTERBUS data cycles will not
yet be executed.
SLAVE_DIAG_STATUS_ BOOL AT %MX1.60010.3 TRUE :=
REG_POWER_ON slave is supplied with power or not.
SLAVE_DIAG_STATUS_ BOOL AT %MX1.60010.4 TRUE :=
REG_RDY slave is ready for operation.

These system variables describe the state of controller boards that are
being used as slaves in a higher level INTERBUS ring. The variables are
based on the slave’s diagnostic status register only.

1-36 5958B
IEC 61131 runtime system

Table 1-7 Coprozessor system flags

Name Data type Logical address Description


COP_DIAG_STATUS_ BOOL AT %MX1.60021.0 TRUE :=
REG_PON coprocessor is ready for operation.
COP_DIAG_STATUS_ BOOL AT %MX1.60020.0 TRUE :=
REG_RT_ERR a run-time error has occurred on the co-
processor.
COP_DIAG_STATUS_ BOOL AT %MX1.60020.1 TRUE :=
REG_FAT_ERR a fatal error has occurred on the copro-
cessor. Division by zero, for example, can
lead to critical failure.
COP_DIAG_STATUS_ BOOL AT %MX1.60020.2 TRUE :=
REG_WARN a warning has been issued on the copro-
cessor. A low buffer battery, for example,
can lead to a warning.

These system variables show the states of the diagnostic status register on
the controller board’s coprocessor. These system variables are only avail-
able when your controller board is equipped with a coprocessor.

Table 1-8 Digital Inputs on the FC 486DX and FC/DI controller boards

Name Data type Logical address Description


ONBOARD_INPUT WORD AT %MW 1.60030 This system variable shows the states of
the digital inputs.

5958B 1-37
PROGRAM WORX

Table 1-9 Remote Field Controller for IP65 Local Bus

Name Data type Logical address Description


RFC_EMERGENCY_ BOOL AT %MX1.60032.0 TRUE :=
STOP_NOT_SET there is a short circuit on the
Emergency_off circuit on the Remote
Field Controller.
RFC_POWER_SWITCHED BOOL AT %MX1.60032.1 TRUE :=
_ON clips have the 24 Volts.
(The Remote Field Controller is
equipped with clips from which a 24-
Volt current can be tapped.)
RFC_PUSH_BUTTON_ BOOL AT %MX1.60032.2 TRUE :=
START the button of the Remote Field Control-
ler has been pressed.
RFC_OHP_LOGGED_ON BOOL AT %MX1.60032.3 TRUE :=
an operator hand panel is connected to
the appropriate socket.
RFC_SWITCH_ON_ BOOL AT %MX3.60032.0 TRUE :=
POWER sets the 24 Volts on the clips to active.
RFC_LED_START BOOL AT %MX3.60032.1 TRUE :=
activates the start-LED on the Remote
Field Controller.

In addition to these system flags visible in the declaration of global vari-


ables system flags containing task and error information can be used for
special purposes.

1-38 5958B
IEC 61131 runtime system

1.4.7.1 User task information


The system flags shown in the following table are available for each user
task:

Table 1-10 User task information

Name Data type Logical address Description


CURDURATION INT AT %MW1.1032 Current task duration including preemptive
scheduling in ticks
MINDURATION INT AT %MW1.1034 Minimum task duration in ticks
MAXDURATION INT AT %MW1.1036 Maximum task duration in ticks
CURDELAY INT AT %MW1.1040 Current task delay in ticks
MINDELAY INT AT %MW1.1042 Minimum task delay in ticks
MAXDELAY INT AT %MW1.1044 Maximum task delay in ticks

If there is more than one user task, the logical address for the next user
task information is calculated by 1032 + N*64 where N is the task number.
In this case the current task duration for the next user task is located at
1096.
To use these system flags the logical address is to be inserted in the field
’AT’ in the dialog ’Declaration of variables or FB instances’ in PROGRAM
WORX.
Example: If you want to declare the system flag CURDURATION you have
to insert in the field ’AT’:
% MW1.1032

5958B 1-39
PROGRAM WORX

1.4.7.2 Error catalogue information


The system flags of the error catalogue are shown in the following table:

Table 1-11 Error catalogue information

Name Data type Logical address Description


PLC_MAX_ERR INT 60 Maximum size of the ProConOS error cata-
logue
PLC_ERR_CNT INT 62 Current amount of errors beginning at loca-
tion %MD 1.64
ERROR DWORD 64 First error number
ERROR_N DWORD 68 Next logical address of error number is calcu-
lated by 64 + N*4 where N is the error index

To use these system flags do the corresponding variable declaration in the


global variable worksheet of the resource.
These system flags which have not already been declared in the global
variable declaration are not available for all ProConOS adaptations.

1-40 5958B
IEC 61131 runtime system

1.5 ProConOS data types

1.5.1 Strings

In this chapter information is given how to use string data types in PLC pro-
grams. It is especially described how to format strings with the provided
PROGRAM WORX string functions.

1.5.1.1 Error treatment of string errors


The default handling after an occurred string error has changed in the Pro-
ConOS version 3.0. As described in the chapter "PLC application and Pro-
ConOS" in this manual only the SPG 21 is called after a string error occurs
and an entry in the error catalogue is made including the module and the
line number. In a customer-specific ProConOS version this behavior may
be different.
As the default configuration only the exception (SPG 21) is generated. If
a string error occurs the PLC is not stopped.
The error reaction of the string functions is described in the following table.

Table 1-12 Error reaction of string functions

String function Error condition Error reaction


LEFT L > len(IN) OUT =‘‘
L > maxlen(OUT)
RIGHT L > len(IN) OUT =‘‘
L > maxlen(OUT)
MID L > maxlen(OUT) OUT =‘‘
P<0
P+L > len(IN)
CONCAT len(IN1) + len(IN2) > maxlen(OUT) OUT =‘‘
IN2 == OUT

5958B 1-41
PROGRAM WORX

Table 1-12 Error reaction of string functions

String function Error condition Error reaction


INSERT len(IN1) + len(IN2) > maxlen(OUT) OUT =‘‘
P<0
P > len(IN1)
IN2 == OUT
DELETE len(IN) – L > maxlen(OUT) OUT =‘‘
P+L > len(IN)
P<0
REPLACE len(IN) – L + len(IN2) > max- OUT =‘‘
len(OUT)
IN2 == OUT
P+L > len(IN1)
P<0
FIND -- --
ASSIGN len(IN) > maxlen(OUT) OUT =‘‘
(:=,MOVE, ST)
*_TO_STRING please refer to chapter OUT =‘‘
*_TO_STRING
STRING_TO_* please refer to chapter Value = 0
STRING_TO*

The identifiers L,P,IN,... represent the parameter of the string functions in


the IEC language FBD. ‘len(...)’ represents the actual string length and
‘maxlen(...)’ the maximum string length allowed (maxlen(Default string) =
80).

1.5.1.2 STRING_TO_*
The functions STRING_TO_* are used to generate a number from a string
which includes a value. In the following some rules for numeric literals are
described. These numeric literals can be connected to the several
STRING_TO_* functions.

1-42 5958B
IEC 61131 runtime system

General rules
digit ::= ‘0‘ | ‘1‘ | ‘2‘ | ‘3‘ | ‘4‘ | ‘5‘ | ‘6‘ | ‘7‘ | ‘8‘ | ‘9‘
hexDigit ::= digit | ‘A‘ | ‘B‘ | ‘C‘ | ‘D‘ | ‘E‘ | ‘F‘ |‘a‘ | ‘b‘ | ‘c‘ | ‘d‘ | ‘e‘ | ‘f‘
integer ::= digit{[‘_‘] digit}
realInteger ::= digit{digit}
signedRealInteger ::= [‘+‘|‘-‘] realInteger
exponent ::= (‘E‘| ‘e‘)signedRealInteger
bitStream ::= BYTE | WORD | DWORD
unsignedTyp ::= USINT | UINT | UDINT
signedTyp ::= SINT | INT | DINT
timeTyp ::= ‘T‘ | ‘t‘ | ‘TIME‘ | ‘time‘

Allowed literal for the functions STRING_TO_BYTE, _WORD and


_DWORD
hexInteger := 16#hexDigit{[‘_‘] hexDigit}
bitStreamLiteral ::= [bitStream ‘#‘]digit{[‘_‘] digit}

Allowed literal for the functions STRING_TO_SINT, _INT and _DINT


signedLiteral ::= [signedTyp ‘#‘] [‘+‘|‘-‘] integer

Allowed literal for the functions STRING_TO_USINT, _UINT and _DINT


unsignedLiteral ::= [unsignedTyp ‘#‘] digit{[‘_‘] digit}

Allowed literal for the function STRING_TO_REAL


realLiteral ::= [‘REAL‘ ‘#‘] signedRealInteger‘.‘realInteger [exponent]

Allowed literal for the function STRING_TO_TIME


durationLiteral ::= timeTyp ‘#‘ digit{digit} [‘ms‘ | ‘MS‘]

5958B 1-43
PROGRAM WORX

Errors which may occur during the value transformation


– The connected string represents a literal which is not valid for this data
type.
Example:

– The value is out of the range for the specified data type.
Example:

– The value does not fit to the literal.


Example:

– The connected string is empty.


Example:

1-44 5958B
IEC 61131 runtime system

Error reaction
In the error conditions, described above, the result variable gets the value
‘0’. If the connected string is empty (even no blanks), the program will not
be interrupted. In all other cases it is checked whether the exception han-
dling is enabled and the error process is started, like described in the chap-
ter ‘Error treatment of string errors’.

Specialty of transformation
It is searched for the first occurrence of the character ‘#’ in the connected
string. If this character is found, an evaluation of the type or format identifier
in front of this character is done. In principle it is possible to transform a
number which is embedded in a string.

Example: ‘Jack is INT#40 years old’ Result: 40

The further evaluation is done as the character ‘#’ is not included in the
string. If this character is not found in the string, the evaluation starts at the
beginning of the string. All white spaces are skipped, till the first character
is found which is not a white space. The evaluation starts under regard of
the described rules.
The evaluation is stopped if a character is found which is not a valid literal.
The evaluation of the strings ‘INT#50 J‘ and ‘INT#50J‘ gives the re-
sult value 50, both.
Following ASCII codes are regarded as ‘white spaces‘:

Character Value
horizontal tab 9 (09h)
line feed 10 (0Ah)
vertical tab 11 (0Bh)
form feed 12 (0Ch)
carriage return 13 (0Dh)
blank 32 (20h)

5958B 1-45
PROGRAM WORX

1.5.1.3 *TO_STRING
The functions *_TO_STRING are used to put the value of a number into a
string. For having the possibility to create the text according to special con-
ceptions, the functions get a format string which may include the conver-
sion instructions.

Principle construction of the conversion instructions


digit ::= ‘0‘ | ‘1‘ | ‘2‘ | ‘3‘ | ‘4‘ | ‘5‘ | ‘6‘ | ‘7‘ | ‘8‘ | ‘9‘
convertStr ::= ‘%‘[width][‘.‘precision][‘l‘] typ
width ::= [0] digit {digit}
precision ::= digit {digit}
typ ::=‘d‘ | ‘u‘ | ‘x‘ | ‘X‘ | ‘e‘ | ‘E‘ | ‘f‘

Valid conversion instructions of BYTE_, WORD_ and


DWORD_TO_STRING
convStr ::= ‘%‘[width][‘.‘precision][‘l‘](‘u‘ | ‘x‘ | ‘X‘)

Valid conversion instructions of SINT_, INT_ and DINT_TO_STRING


convStr ::= ‘%‘[width][‘.‘precision][‘l‘](‘d‘)

Valid conversion instructions of USINT_, UINT_ and


UDINT_TO_STRING
convStr ::= ‘%‘[width][‘.‘precision][‘l‘](‘u‘)

Valid conversion instructions of REAL_TO_STRING


convStr ::= ‘%‘[width][‘.‘precision][‘l‘](‘e‘ | ‘E‘ | ‘f‘)

Valid conversion instructions of TIME_TO_STRING


convStr ::= ‘%‘[width][‘.‘precision][‘l‘](‘u‘)

1-46 5958B
IEC 61131 runtime system

Description of the optional instructions

Width The optional instruction ‘width‘ indicates, how much characters are to put
out at minimal. If necessary the output is filled up with ‘0’ (if a 0 is set before
‘width’) or with white spaces.

Precision The optional instruction ‘precision‘ indicates, how much characters are to
put out at maximal, respectively the amount of significant decimal positions
for the data type REAL.

Construction of the format string


Every conversion instruction may be embedded into a string. So the format
string may look like the following.
‘Jack is INT#%ld years old‘.
In this example the conversion instruction is shown in italic letters.
If the character ‘%’ should be shown in the string, the character must be put
into the format string, twice.

Standard format strings for BYTE_, WORD_ and


DWORD_TO_STRING
‘16#lX‘

Standard format strings for SINT_, INT_ and DINT_TO_STRING


‘%ld‘

Standard format strings for USINT_, UINT_ and UDINT_TO_STRING


‘%lu‘

Standard format strings for REAL_TO_STRING


‘%lE‘

Standard format strings for TIME_TO_STRING


‘T#%lu ms‘

The standard format strings are valid if an empty string is connected as for-
mat string.

5958B 1-47
PROGRAM WORX

Errors which may occur during the transformation


– Illegal or no conversion instruction
Example:

– The result string exceeds the maximal allowed length of the connected
output string.

Error reaction
In the error conditions, described above, the output string is cleared. Then
it is checked whether the exception handling is enabled and the error pro-
cess is started, like described in the chapter ‘Error treatment of string er-
rors’.

Compatibility
In contrast to former versions of ProConOS the connected format string is
checked on validation. This check may result to string errors if using old
projects. These errors occur, if conversion instructions are used, which are
not supported by the current implementation.

1-48 5958B
IEC 61131 runtime system

1.6 Functions and Function Blocks

For detailed information about supported functions and function blocks


please refer to the following sections of this manual.

1.6.1 IEC 61131-3 functions

Functions are POUs with multiple input parameters and exactly one output
parameter. They do not have any internal memory. Consequently, calling
a function with the same values always the same return values result. The
return values can be either single or multi-element variables such as arrays
or structures. The abbreviation for functions is FU.
IEC 1131-3 describes standard functions which can be used while editing
your PLC program. According to your hardware and PLC type it is possible
that not all standard functions are available or that firmware functions have
been added.
IEC 1131-3 lists different types of standard functions:
– Type conversion functions
– Numerical functions
– Arithmetic functions
– Bitwise Boolean functions
– Bit-string functions
– Selection functions
– Comparison functions
– Character string functions

1.6.2 IEC 1131-3 function blocks

Function blocks are POUs with multiple input and output parameters. They
do have an internal memory. The value that a function block returns de-
pends on the value of its internal memory. The abbreviation for function
blocks is FB.
IEC 1131-3 describes standard function blocks which can be used while
editing your PLC program. According to your hardware and PLC type it is
possible that not all standard function blocks are available or that firmware
function blocks have been added.

5958B 1-49
PROGRAM WORX

IEC 1131-3 lists different types of standard function blocks:


– Bistable function blocks
– Edge detection function blocks
– Counters function blocks
– Timer function blocks

1.6.3 ProConOS functions

In addition to the IEC standard functions ProConOS functions can be used.


For ProConOS the following functions are available:

– COLD_RESTART executes a cold restart


– CONTINUE continues the program execution
– HOT_RESTART executes a hot restart
– RD_*_BY_SYM reads a value from a symbolic variable in PDD
– WARM_RESTART executes a warm restart
– WR_*_BY_SYM writes a value to a symbolic variable in PDD

1.6.4 ProConOS function blocks

In addition to the IEC standard function blocks ProConOS function blocks


can be used.
For ProConOS the following function blocks are available:

– CLR_OUT sets all outputs of the I/O image to zero


– DERIVAT differentiation with respect to time
– GET_SYM searches for the symbolic name of a variable
in PDD
– INTEGRAL integration over time
– PID Proportion + Integral + Derivative control
(3. order)
– FPID Proportion + Integral + Derivative control
(2. order)

1-50 5958B
IEC 61131 runtime system

– RD_BOOL_BY_SYM reads a value from a symbolic variable in


PDD
– RD_INPUT_GROUP reads the values of an input group in the I/O
image
– WR_BOOL_BY_SYM writes a value to a symbolic variable in PDD
– WR_OUTPUT_GROUP writes the values of an output group in the
I/O image

1.6.5 IB Communication Blocks

The IB Communication Blocks provide you with the functions of Firmware


and PCP services. The following IB communication blocks are available:
– PCP_CONNECT
– PCP_READ
– PCP_WRITE
– PCP_CLIENT
– PCP_SERVER
– IB_CONTROL
You can establish communication connections which directly deliver data
to PCP objects of single devices with PCP_READ and PCP_WRITE blocks
or which run PCP services with PCP SERVER/CLIENT blocks.
You can use the IB_CONTROL block to run a Firmware service.
Each block is both a sending and a receiving block. This means, that a
block sending a request can also receive the respective confirmation.
When objects are written or read directly you can also check if the action is
successful.
The PCP_CONNECT, PCP_WRITE, and PCP_READ blocks correspond
to the blocks specified in IEC 61131-5. The PCP_READ and PCP_WRITE
blocks have been extended by the parameter DATA_CNT.
The PCP_SERVER, PCP_CLIENT, and IB_CONTROL blocks are specific
to INTERBUS.
You can use IB Communication Blocks only on Controller Boards with
Firmware >=4.4a.

5958B 1-51
PROGRAM WORX

1.6.6 Bit manipulation functions

In addition to the standard functions firmware functions can be used if you


have announced the firmware library in your PROGRAM WORX project.

Announcing libraries is described in the general help.

The following bit manipulation functions are available:

– BIT_TEST reads the value of a single bit in a bit string


– GET_CHAR extracts one character out of a string
– GET_LSB reads the value of the less significant BYTE
of a bit string
– GET_MSB reads the value of the most significant
BYTE of a bit string
– I_BIT_IN_* inverts a single bit in a bit string
– PARITY_* checks if the number of set bits is even or
odd
– R_BIT_IN_* resets a single bit in a bit string
– S_BIT_IN_* sets a single bit in a bit string
– SET_LSB writes a value on the less significant BYTE
of a bit string
– SET_MSB writes a value on the most significant BYTE
of a bit string
– STRING_TO_BUFFER copies characters of a string to a buffer
– SWAP exchanges the most and the less significant
BYTE of a bit string

1-52 5958B
Section 2
This section provides information on
– how to use type conversion functions

Type conversion functions ....................................................................................2-5


2.1 B_BCD_TO_*..............................................................................2-8
2.1.1 B_BCD_TO_SINT..........................................................2-8
2.1.2 B_BCD_TO_INT ............................................................2-9
2.1.3 B_BCD_TO_DINT........................................................2-10
2.2 BCD_TO_* ................................................................................2-11
2.2.1 BCD_TO_DINT ............................................................2-11
2.3 BOOL_TO_*..............................................................................2-12
2.3.1 BOOL_TO_BYTE.........................................................2-12
2.3.2 BOOL_TO_WORD.......................................................2-13
2.3.3 BOOL_TO_DWORD ....................................................2-14
2.3.4 BOOL_TO_SINT..........................................................2-15
2.3.5 BOOL_TO_INT ............................................................2-16
2.3.6 BOOL_TO_DINT..........................................................2-17
2.3.7 BOOL_TO_REAL.........................................................2-18
2.4 BYTE_TO_* ..............................................................................2-19
2.4.1 BYTE_TO_BOOL.........................................................2-19
2.4.2 BYTE_TO_WORD .......................................................2-20
2.4.3 BYTE_TO_DWORD.....................................................2-21
2.4.4 BYTE_TO_SINT ..........................................................2-22
2.4.5 BYTE_TO_INT.............................................................2-23
2.4.6 BYTE_TO_DINT ..........................................................2-24
2.4.7 BYTE_TO_REAL .........................................................2-25
2.5 D_BCD_TO_*............................................................................2-26
2.5.1 D_BCD_TO_SINT........................................................2-26
2.5.2 D_BCD_TO_INT ..........................................................2-27
2.5.3 D_BCD_TO_DINT .......................................................2-28

5958B 2-1
2.6 DINT_TO_* ...............................................................................2-29
2.6.1 DINT_TO_BCD ............................................................2-29
2.6.2 DINT_TO_B_BCD........................................................2-30
2.6.3 DINT_TO_W_BCD.......................................................2-31
2.6.4 DINT_TO_D_BCD .......................................................2-32
2.6.5 DINT_TO_BOOL..........................................................2-33
2.6.6 DINT_TO_BYTE ..........................................................2-34
2.6.7 DINT_TO_WORD ........................................................2-35
2.6.8 DINT_TO_DWORD......................................................2-36
2.6.9 DINT_TO_SINT ...........................................................2-37
2.6.10 DINT_TO_INT..............................................................2-38
2.6.11 DINT_TO_REAL ..........................................................2-39
2.6.12 DINT_TO_TIME ...........................................................2-40
2.7 DWORD_TO_*..........................................................................2-41
2.7.1 DWORD_TO_BOOL ....................................................2-41
2.7.2 DWORD_TO_BYTE.....................................................2-42
2.7.3 DWORD_TO_WORD...................................................2-43
2.7.4 DWORD_TO_SINT......................................................2-44
2.7.5 DWORD_TO_INT ........................................................2-45
2.7.6 DWORD_TO_DINT......................................................2-46
2.7.7 DWORD_TO_REAL.....................................................2-47
2.8 INT_TO_* ..................................................................................2-48
2.8.1 INT_TO_B_BCD ..........................................................2-48
2.8.2 INT_TO_W_BCD .........................................................2-49
2.8.3 INT_TO_D_BCD ..........................................................2-50
2.8.4 INT_TO_BOOL ............................................................2-51
2.8.5 INT_TO_BYTE.............................................................2-52
2.8.6 INT_TO_WORD...........................................................2-53
2.8.7 INT_TO_DWORD ........................................................2-54
2.8.8 INT_TO_SINT ..............................................................2-55
2.8.9 INT_TO_DINT..............................................................2-56
2.8.10 INT_TO_REAL.............................................................2-57

2-2 5958B
2.9 REAL_TO_* ..............................................................................2-58
2.9.1 REAL_TO_BOOL.........................................................2-58
2.9.2 REAL_TO_BYTE .........................................................2-59
2.9.3 REAL_TO_WORD .......................................................2-60
2.9.4 REAL_TO_DWORD.....................................................2-61
2.9.5 REAL_TO_SINT ..........................................................2-62
2.9.6 REAL_TO_INT.............................................................2-63
2.9.7 REAL_TO_DINT ..........................................................2-64
2.10 SINT_TO_*................................................................................2-65
2.10.1 SINT_TO_B_BCD........................................................2-65
2.10.2 SINT_TO_W_BCD.......................................................2-66
2.10.3 SINT_TO_D_BCD........................................................2-67
2.10.4 SINT_TO_BOOL..........................................................2-68
2.10.5 SINT_TO_BYTE ..........................................................2-69
2.10.6 SINT_TO_WORD ........................................................2-70
2.10.7 SINT_TO_DWORD......................................................2-71
2.10.8 SINT_TO_INT ..............................................................2-72
2.10.9 SINT_TO_DINT ...........................................................2-73
2.10.10 SINT_TO_REAL ..........................................................2-74
2.11 STRING_TO_* ..........................................................................2-75
2.12 TIME_TO_* ...............................................................................2-78
2.12.1 TIME_TO_DINT ...........................................................2-78
2.13 TRUNC_* ..................................................................................2-79
2.14 W_BCD_TO_*...........................................................................2-80
2.14.1 W_BCD_TO_SINT.......................................................2-80
2.14.2 W_BCD_TO_INT .........................................................2-81
2.14.3 W_BCD_TO_DINT.......................................................2-82
2.15 WORD_TO_* ............................................................................2-83
2.15.1 WORD_TO_BOOL.......................................................2-83
2.15.2 WORD_TO_BYTE .......................................................2-84
2.15.3 WORD_TO_DWORD...................................................2-85
2.15.4 WORD_TO_SINT ........................................................2-86
2.15.5 WORD_TO_INT...........................................................2-87

5958B 2-3
2.15.6 WORD_TO_DINT ........................................................2-88
2.15.7 WORD_TO_REAL .......................................................2-89

2-4 5958B
Type conversion functions

2 Type conversion functions


The following type conversion functions are available:

Table 2-1 Type conversion functions

Function Short description


B_BCD_TO_SINT Type conversion from BCD code to SINT
B_BCD_TO_INT Type conversion from BCD code to INT
B_BCD_TO_DINT Type conversion from BCD code to DINT
BCD_TO_DINT Type conversion from BCD code to DINT
BOOL_TO_BYTE Type conversion from BOOL to BYTE
BOOL_TO_WORD Type conversion from BOOL to WORD
BOOL_TO_DWORD Type conversion from BOOL to DWORD
BOOL_TO_SINT Type conversion from BOOL to SINT
BOOL_TO_INT Type conversion from BOOL to INT
BOOL_TO_DINT Type conversion from BOOL to DINT
BOOL_TO_REAL Type conversion from BOOL to REAL
BYTE_TO_BOOL Type conversion from BYTE to BOOL
BYTE_TO_WORD Type conversion from BYTE to WORD
BYTE_TO_DWORD Type conversion from BYTE to DWORD
BYTE_TO_SINT Type conversion from BYTE to SINT
BYTE_TO_INT Type conversion from BYTE to INT
BYTE_TO_DINT Type conversion from BYTE to DINT
BYTE_TO_REAL Type conversion from BYTE to REAL
D_BCD_TO_SINT Type conversion from BCD code to SINT
D_BCD_TO_INT Type conversion from BCD code to INT
D_BCD_TO_DINT Type conversion from BCD code to DINT
DINT_TO_BCD Type conversion from DINT to BCD code

5958B 2-5
PROGRAM WORX

Table 2-1 Type conversion functions

Function Short description


DINT_TO_B_BCD Type conversion from DINT to BCD code
DINT_TO_W_BCD Type conversion from DINT to BCD code
DINT_TO_D_BCD Type conversion from DINT to BCD code
DINT_TO_BOOL Type conversion from DINT to BOOL
DINT_TO_BYTE Type conversion from DINT to BYTE
DINT_TO_WORD Type conversion from DINT to WORD
DINT_TO_DWORD Type conversion from DINT to DWORD
DINT_TO_SINT Type conversion from DINT to SINT
DINT_TO_INT Type conversion from DINT to INT
DINT_TO_REAL Type conversion from DINT to REAL
DINT_TO_TIME Type conversion from DINT to TIME
DWORD_TO_BOOL Type conversion from DWORD to BOOL
DWORD_TO_BYTE Type conversion from DWORD_TO_BYTE
DWORD_TO_WORD Type conversion from DWORD to WORD
DWORD_TO_SINT Type conversion from DWORD to SINT
DWORD_TO_INT Type conversion from DWORD to INT
DWORD_TO_DINT Type conversion from DWORD to DINT
DWORD_TO_REAL Type conversion from DWORD to REAL
INT_TO_B_BCD Type conversion from INT to BCD code
INT_TO_W_BCD Type conversion from INT to BCD code
INT_TO_D_BCD Type conversion from INT to BCD code
INT_TO_BOOL Type conversion from INT to BOOL
INT_TO_BYTE Type conversion from INT to BYTE
INT_TO_WORD Type conversion from INT to WORD
INT_TO_DWORD Type conversion from INT to DWORD

2-6 5958B
Type conversion functions

Table 2-1 Type conversion functions

Function Short description


INT_TO_SINT Type conversion from INT to SINT
INT_TO_DINT Type conversion from INT to DINT
INT_TO_REAL Type conversion from INT to REAL
REAL_TO_BOOL Type conversion from REAL to BOOL
REAL_TO_BYTE Type conversion from REAL to BYTE
REAL_TO_WORD Type conversion from REAL to WORD
REAL_TO_DWORD Type conversion from REAL to DWORD
REAL_TO_SINT Type conversion from REAL to SINT
REAL_TO_INT Type conversion from REAL to INT
REAL_TO_DINT Type conversion from REAL to DINT
SINT_TO_B_BCD Type conversion from SINT to BCD code
SINT_TO_W_BCD Type conversion from SINT to BCD code
SINT_TO_D_BCD Type conversion from SINT to BCD code
SINT_TO_BOOL Type conversion from SINT to BOOL
SINT_TO_BYTE Type conversion from SINT to BYTE
SINT_TO_WORD Type conversion from SINT to WORD
SINT_TO_DWORD Type conversion from SINT to DWORD
SINT_TO_INT Type conversion from SINT to INT
SINT_TO_DINT Type conversion from SINT to DINT
SINT_TO_REAL Type conversion from SINT to REAL
STRING_TO_* Type conversion from STRING
TIME_TO_DINT Type conversion from TIME to DINT
TRUNC_* Truncation
W_BCD_TO_SINT Type conversion from BCD code to SINT
W_BCD_TO_INT Type conversion from BCD code to INT

5958B 2-7
PROGRAM WORX

Table 2-1 Type conversion functions

Function Short description


W_BCD_TO_DINT Type conversion from BCD code to DINT
WORD_TO_BOOL Type conversion from WORD to BOOL
WORD_TO_BYTE Type conversion from WORD to BYTE
WORD_TO_DWORD Type conversion from WORD to DWORD
WORD_TO_SINT Type conversion from WORD to SINT
WORD_TO_INT Type conversion from WORD to INT
WORD_TO_DINT Type conversion from WORD to DINT
WORD_TO_REAL Type conversion from WORD to REAL

2.1 B_BCD_TO_*

2.1.1 B_BCD_TO_SINT

Description This type conversion function changes a BCD input value (binary-coded
decimal number) of the data type BYTE into an output value of the data
type SINT.
If an incorrect input value (permissible value range 0 to 9) is applied the
output value is converted to -1. For example the input value 16#0A results
in the output value -1.
In case of values which are not within the valid scope of the output data
type it has to be considered that there will be an overflow.

Parameter Data type Description


IN BYTE input value
OUT SINT output value

2-8 5958B
Type conversion functions

Example
LD 16#80 (*loads 16#80 in accu*)
B_BCD_TO_SINT (*converts BCD input value of data type BYTE to
SINT*)
ST var2 (*stores 80 in var2*)

Representation
IL ST FBD

LD IN OUT:=
B_BCD_TO_SINT B_BCD_TO_SINT(IN);
ST OUT

2.1.2 B_BCD_TO_INT

Description This type conversion function changes a BCD input value (binary-coded
decimal number) of the data type BYTE into an output value of the data
type INT.
If an incorrect input value (permissible value range 0 to 9) is applied the
output value is converted to -1. For example the input value 16#0A results
in the output value -1.
In case of values which are not within the valid scope of the output data
type it has to be considered that there will be an overflow.

Parameter Data type Description


IN BYTE input value
OUT INT output value

Example
LD 16#80 (*loads 16#80 in accu*)
B_BCD_TO_INT (*converts BCD input value of data type BYTE to INT*)
ST var2 (*stores 80 in var2*)

5958B 2-9
PROGRAM WORX

Representation
IL ST FBD

LD IN OUT:=
B_BCD_TO_INT B_BCD_TO_INT(IN);
ST OUT

2.1.3 B_BCD_TO_DINT

Description This type conversion function changes a BCD input value (binary-coded
decimal number) of the data type BYTE into an output value of the data
type DINT.
If an incorrect input value (permissible value range 0 to 9) is applied the
output value is converted to -1. For example the input value 16#0A results
in the output value -1.
In case of values which are not within the valid scope of the output data
type it has to be considered that there will be an overflow.

Parameter Data type Description


IN BYTE input value
OUT DINT output value

Example
LD 16#80 (*loads 16#80 in accu*)
B_BCD_TO_DINT (*converts BCD input value of data type BYTE to
DINT*)
ST var2 (*stores 80 in var2*)

Representation
IL ST FBD

LD IN OUT:=
B_BCD_TO_DINT B_BCD_TO_DINT(IN);
ST OUT

2-10 5958B
Type conversion functions

2.2 BCD_TO_*

2.2.1 BCD_TO_DINT

Description This type conversion function changes a BCD input value (binary-coded
decimal number) of the data type DWORD into an output value of the data
type DINT.
If an incorrect input value (permissible value range 0 to 9) is applied the
output value is converted to -1. For example the input value 16#0A0B0A0B
results in the output value -1.
In case of values which are not within the valid scope of the output data
type it has to be considered that there will be an overflow.

Parameter Data type Description


IN DWORD input value
OUT DINT output value

Example
LD 16#99999999 (*loads 16#99999999 in accu*)
BCD_TO_DINT (*converts BCD input value (data type DWORD) to DINT*)
ST var2 (*stores 99999999 in var2*)

Representation
IL ST FBD

LD IN OUT:=
BCD_TO_DINT BCD_TO_DINT(IN);
ST OUT

5958B 2-11
PROGRAM WORX

2.3 BOOL_TO_*

2.3.1 BOOL_TO_BYTE

Description This type conversion function changes an input value of the data type
BOOL into an output value of the data type BYTE.
If the input value is FALSE, the output value is converted to 16#00. The
input value TRUE results in the output value 16#01.

Parameter Data type Description


IN BOOL input value
OUT BYTE output value

Example
LD TRUE (*loads TRUE in accu*)
BOOL_TO_BYTE (*converts BOOL to BYTE*)
ST var2 (*stores 16#01 in var2*)

Representation
IL ST FBD

LD IN OUT:=
BOOL_TO_BYTE BOOL_TO_BYTE(IN);
ST OUT

2-12 5958B
Type conversion functions

2.3.2 BOOL_TO_WORD

Description This type conversion function changes an input value of the data type
BOOL into an output value of the data type WORD.
The input value is converted to the lowest-order bits of the output. The high-
est-order bits are set to zero. If the input value is FALSE, the output value
is converted to 16#0000. The input value TRUE results in the output value
16#0001.

Parameter Data type Description


IN BOOL input value
OUT WORD output value

Example
LD TRUE (*loads TRUE in accu*)
BOOL_TO_WORD (*converts BOOL to WORD*)
ST var2 (*stores 16#0001 in var2*)

Representation
IL ST FBD

LD IN OUT:=
BOOL_TO_WORD BOOL_TO_WORD(IN);
ST OUT

5958B 2-13
PROGRAM WORX

2.3.3 BOOL_TO_DWORD

Description This type conversion function changes an input value of the data type
BOOL into an output value of the data type DWORD.
The input value is converted to the lowest-order bits of the output. The high-
est-order bits are set to zero. If the input value is FALSE, the output value
is converted to 16#00000000. The input value TRUE results in the output
value 16#00000001.

Parameter Data type Description


IN BOOL input value
OUT DWORD output value

Example
LD TRUE (*loads TRUE in accu*)
BOOL_TO_DWORD (*converts BOOL to DWORD*)
ST var2 (*stores 16#00000001 in var2*)

Representation
IL ST FBD

LD IN OUT:=
BOOL_TO_DWORD BOOL_TO_DWORD(IN);
ST OUT

2-14 5958B
Type conversion functions

2.3.4 BOOL_TO_SINT

Description This type conversion function changes an input value of the data type
BOOL into an output value of the data type SINT.
If the input value is FALSE, the output value is converted to 0. The input
value TRUE results in the output value 1.

Parameter Data type Description


IN BOOL input value
OUT SINT output value

Example
LD TRUE (*loads TRUE in accu*)
BOOL_TO_SINT (*converts BOOL to SINT*)
ST var2 (*stores 1 in var2*)

Representation
IL ST FBD

LD IN OUT:=
BOOL_TO_SINT BOOL_TO_SINT(IN);
ST OUT

5958B 2-15
PROGRAM WORX

2.3.5 BOOL_TO_INT

Description This type conversion function changes an input value of the data type
BOOL into an output value of the data type INT.
If the input value is FALSE, the output value is converted to 0. The input
value TRUE results in the output value 1.

Parameter Data type Description


IN BOOL input value
OUT INT output value

Example
LD TRUE (*loads TRUE in accu*)
BOOL_TO_INT (*converts BOOL to INT*)
ST var2 (*stores 1 in var2*)

Representation
IL ST FBD

LD IN OUT:=
BOOL_TO_INT BOOL_TO_INT(IN);
ST OUT

2-16 5958B
Type conversion functions

2.3.6 BOOL_TO_DINT

Description This type conversion function changes an input value of the data type
BOOL into an output value of the data type DINT.
If the input value is FALSE, the output value is converted to 0. The input
value TRUE results in the output value 1.

Parameter Data type Description


IN BOOL input value
OUT DINT output value

Example
LD TRUE (*loads TRUE in accu*)
BOOL_TO_DINT (*converts BOOL to DINT*)
ST var2 (*stores 1 in var2*)

Representation
IL ST FBD

LD IN OUT:=
BOOL_TO_DINT BOOL_TO_DINT(IN);
ST OUT

5958B 2-17
PROGRAM WORX

2.3.7 BOOL_TO_REAL

Description This type conversion function changes an input value of the data type
BOOL into an output value of the data type REAL.
If the input value is FALSE, the output value is converted to
1.0000000 E+00. The input value TRUE results in the output value
0.0000000 E+00.

Parameter Data type Description


IN BOOL input value
OUT REAL output value

Example
LD TRUE (*loads TRUE in accu*)
BOOL_TO_REAL (*converts BOOL to REAL*)
ST var2 (*stores 1.0000000 E+00 in var2*)

Representation
IL ST FBD

LD IN OUT:=
BOOL_TO_REAL BOOL_TO_REAL(IN);
ST OUT

2-18 5958B
Type conversion functions

2.4 BYTE_TO_*

2.4.1 BYTE_TO_BOOL

Description This type conversion function changes an input value of the data type
BYTE into an output value of the data type BOOL.
Any input value unequal to 16#00 results in the output value TRUE.

Parameter Data type Description


IN BYTE input value
OUT BOOL output value

Example
LD 16#00 (*loads 16#00 in accu*)
BYTE_TO_BOOL (*converts BYTE to BOOL*)
ST var2 (*stores 0 (FALSE) in var2*)

Representation
IL ST FBD

LD IN OUT:=
BYTE_TO_BOOL BYTE_TO_BOOL(IN);
ST OUT

5958B 2-19
PROGRAM WORX

2.4.2 BYTE_TO_WORD

Description This type conversion function changes an input value of the data type
BYTE into an output value of the data type WORD.
The bit pattern of the input is converted to the lowest-order bits of the out-
put. For example the input value 16#FF results in the output value
16#00FF.

Parameter Data type Description


IN BYTE input value
OUT WORD output value

Example
LD 16#00 (*loads 16#00 in accu*)
BYTE_TO_WORD (*converts BYTE to WORD*)
ST var2 (*stores 16#0000 in var2*)

Representation
IL ST FBD

LD IN OUT:=
BYTE_TO_WORD BYTE_TO_WORD(IN);
ST OUT

2-20 5958B
Type conversion functions

2.4.3 BYTE_TO_DWORD

Description This type conversion function changes an input value of the data type
BYTE into an output value of the data type DWORD.
The bit pattern of the input is converted to the lowest-order bits of the out-
put. For example the input value 16#FF results in the output value
16#000000FF.

Parameter Data type Description


IN BYTE input value
OUT DWORD output value

Example
LD 16#00 (*loads 16#00 in accu*)
BYTE_TO_DWORD (*converts BYTE to WORD*)
ST var2 (*stores 16#00000000 in var2*)

Representation
IL ST FBD

LD IN OUT:=
BYTE_TO_DWORD BYTE_TO_DWORD(IN);
ST OUT

5958B 2-21
PROGRAM WORX

2.4.4 BYTE_TO_SINT

Description This type conversion function changes an input value of the data type
BYTE into an output value of the data type SINT.
A signed conversion is performed. For output data types greater than the
input data type a sign-conformed expansion is additionally performed.

Parameter Data type Description


IN BYTE input value
OUT SINT output value

If the input value is outside the permissible range of the output value, the
output value will be as follows:
input output
128 (80HEX) ... 255 (FFHEX) 128 ... -1

Example
LD 16#7F (*loads 16#7F in accu*)
BYTE_TO_SINT (*converts BYTE to SINT*)
ST var2 (*stores 127 in var2*)

Representation
IL ST FBD

LD IN OUT:=
BYTE_TO_SINT BYTE_TO_SINT(IN);
ST OUT

2-22 5958B
Type conversion functions

2.4.5 BYTE_TO_INT

Description This type conversion function changes an input value of the data type
BYTE into an output value of the data type INT.
A signed conversion is performed. For output data types greater than the
input data type a sign-conformed expansion is additionally performed.

Parameter Data type Description


IN BYTE input value
OUT INT output value

If the input value is outside the permissible range of the output value, the
output value will be as follows:
input output
128 (80HEX) ... 255 (FFHEX) -128 ... -1

Example
LD 16#7F (*loads 16#7F in accu*)
BYTE_TO_INT (*converts BYTE to INT*)
ST var2 (*stores 127 in var2*)

Representation
IL ST FBD

LD IN OUT:=
BYTE_TO_INT BYTE_TO_INT(IN);
ST OUT

5958B 2-23
PROGRAM WORX

2.4.6 BYTE_TO_DINT

Description This type conversion function changes an input value of the data type
BYTE into an output value of the data type DINT.
A signed conversion is performed. For output data types greater than the
input data type a sign-conformed expansion is additionally performed.

Parameter Data type Description


IN BYTE input value
OUT DINT output value

If the input value is outside the permissible range of the output value, the
output value will be as follows:
input output
128 (80HEX) ... 255 (FFHEX) -128 ... -1

Example
LD 16#7F (*loads 16#7F in accu*)
BYTE_TO_DINT (*converts BYTE to DINT*)
ST var2 (*stores 127 in var2*)

Representation
IL ST FBD

LD IN OUT:=
BYTE_TO_DINT BYTE_TO_DINT(IN);
ST OUT

2-24 5958B
Type conversion functions

2.4.7 BYTE_TO_REAL

Description This type conversion function changes an input value of the data type
BYTE into an output value of the data type REAL.
The MSB (most significant bit) of the BYTE value is interpreted as sign bit.
BYTE values greater than 16#7F result in negative values of the output
data type. For example the input value 16#80 results in the output value -
1.2800000 E+02.

Parameter Data type Description


IN BYTE input value
OUT REAL output value

Example
LD 16#7F (*loads 16#7F in accu*)
BYTE_TO_REAL (*converts BYTE to INT*)
ST var2 (*stores 1.2700000 E+02 in var2*)

Representation
IL ST FBD

LD IN OUT:=
BYTE_TO_REAL BYTE_TO_REAL(IN);
ST OUT

5958B 2-25
PROGRAM WORX

2.5 D_BCD_TO_*

2.5.1 D_BCD_TO_SINT

Description This type conversion function changes a BCD input value (binary-coded
decimal number) of the data type DWORD into an output value of the data
type SINT.
If an incorrect input value (permissible value range 0 to 9) is applied the
output value is converted to -1. For example the input value 16#0A0B0A0B
results in the output value -1.
In case of values which are not within the valid scope of the output data
type it has to be considered that there will be an overflow.

Parameter Data type Description


IN DWORD input value
OUT SINT output value

Example
LD 16#00000099 (*loads 16#00000099 in accu*)
W_BCD_TO_SINT (*converts BCD input value (data type DWORD) to
SINT*)
ST var2 (*stores 99 in var2*)

Representation
IL ST FBD

LD IN OUT:=
D_BCD_TO_SINT D_BCD_TO_SINT(IN);
ST OUT

2-26 5958B
Type conversion functions

2.5.2 D_BCD_TO_INT

Description This type conversion function changes a BCD input value (binary-coded
decimal number) of the data type DWORD into an output value of the data
type INT.
If an incorrect input value (permissible value range 0 to 9) is applied the
output value is converted to -1. For example the input value 16#0A0B0A0B
results in the output value -1.
In case of values which are not within the valid scope of the output data
type it has to be considered that there will be an overflow.

Parameter Data type Description


IN DWORD input value
OUT INT output value

Example
LD 16#00009999 (*loads 16#00009999 in accu*)
D_BCD_TO_INT (*converts BCD input value (data type DWORD) to
INT*)
ST var2 (*stores 9999 in var2*)

Representation
IL ST FBD

LD IN OUT:=
D_BCD_TO_INT D_BCD_TO_INT(IN);
ST OUT

5958B 2-27
PROGRAM WORX

2.5.3 D_BCD_TO_DINT

Description This type conversion function changes a BCD input value (binary-coded
decimal number) of the data type DWORD into an output value of the data
type DINT.
If an incorrect input value (permissible value range 0 to 9) is applied the
output value is converted to -1. For example the input value 16#0A0B0A0B
results in the output value -1.
In case of values which are not within the valid scope of the output data
type it has to be considered that there will be an overflow.

Parameter Data type Description


IN DWORD input value
OUT DINT output value

Example
LD 16#99999999 (*loads 16#99999999 in accu*)
D_BCD_TO_DINT (*converts BCD input value (data type DWORD) to
DINT*)
ST var2 (*stores 99999999 in var2*)

Representation
IL ST FBD

LD IN OUT:=
D_BCD_TO_DINT D_BCD_TO_DINT(IN);
ST OUT

2-28 5958B
Type conversion functions

2.6 DINT_TO_*

2.6.1 DINT_TO_BCD

Description This type conversion function changes an input value of the data type DINT
into a BCD output value (binary-code decimal number) of the data type
DWORD.
Negative input values are always converted to 16#FFFFFFFF. For examp-
le the input value -128 results in the output value 16#FFFFFFFF.
In case of input values which are not within the valid scope of the output
data type (BCD) the output value is always converted to 16#FFFFFFFF.
The maximum permissible BCD value range is 99999999.

Parameter Data type Description


IN DINT input value
OUT DWORD output value

Example
LD 99999999 (*loads 99999999 in accu*)
DINT_TO_BCD (*converts DINT to BCD value of data type DWORD*)
ST var2 (*stores 16#99999999 in var2*)

Representation
IL ST FBD

LD IN OUT:=
DINT_TO_BCD DINT_TO_BCD(INT);
ST OUT

5958B 2-29
PROGRAM WORX

2.6.2 DINT_TO_B_BCD

Description This type conversion function changes an input value of the data type DINT
into a BCD output value (binary-code decimal number) of the data type
BYTE.
Negative input values are always converted to 16#FF. For example the in-
put value -128 results in the output value 16#FF.
In case of input values which are not within the valid scope of the output
data type (BCD) the output value is always converted to 16#FF. The maxi-
mum permissible BCD value range is 99999999.

Parameter Data type Description


IN DINT input value
OUT BYTE output value

Example
LD 99999999 (*loads 99999999 in accu*)
DINT_TO_B_BCD (*converts DINT to BCD value of data type BYTE*)
ST var2 (*stores 16#99 in var2*)

Representation
IL ST FBD

LD IN OUT:=
DINT_TO_B_BCD DINT_TO_B_BCD(IN);
ST OUT

2-30 5958B
Type conversion functions

2.6.3 DINT_TO_W_BCD

Description This type conversion function changes an input value of the data type DINT
into a BCD output value (binary-code decimal number) of the data type
WORD.
Negative input values are always converted to 16#FFFF. For example the
input value -128 results in the output value 16#FFFF.
In case of input values which are not within the valid scope of the output
data type (BCD) the output value is always converted to 16#FFFF. The ma-
ximum permissible BCD value range is 99999999.

Parameter Data type Description


IN DINT input value
OUT WORD output value

Example
LD 99999999 (*loads 99999999 in accu*)
DINT_TO_W_BCD (*converts DINT to BCD value of data type WORD*)
ST var2 (*stores 16#9999 in var2*)

Representation
IL ST FBD

LD IN OUT:=
DINT_TO_W_BCD DINT_TO_W_BCD(IN);
ST OUT

5958B 2-31
PROGRAM WORX

2.6.4 DINT_TO_D_BCD

Description This type conversion function changes an input value of the data type DINT
into a BCD output value (binary-code decimal number) of the data type
DWORD.
Negative input values are always converted to 16#FFFFFFFF. For examp-
le the input value -128 results in the output value 16#FFFFFFFF.
In case of input values which are not within the valid scope of the output
data type (BCD) the output value is always converted to 16#FFFFFFFF.
The maximum permissible BCD value range is 99999999.

Parameter Data type Description


IN DINT input value
OUT DWORD output value

Example
LD 99999999 (*loads 99999999 in accu*)
DINT_TO_D_BCD (*converts DINT to BCD value of data type DWORD*)
ST var2 (*stores 16#99999999 in var2*)

Representation
IL ST FBD

LD IN OUT:=
DINT_TO_D_BCD DINT_TO_D_BCD(IN);
ST OUT

2-32 5958B
Type conversion functions

2.6.5 DINT_TO_BOOL

Description This type conversion function changes an input value of the data type DINT
into an output value of the data type BOOL.
Any input value unequal to 0 results in the output value TRUE.

Parameter Data type Description


IN DINT input value
OUT BOOL output value

Example
LD 14 (*loads 14 in accu*)
DINT_TO_BOOL (*converts DINT to BOOL*)
ST var2 (*stores 1 (TRUE) in var2*)

Representation
IL ST FBD

LD IN OUT:=
DINT_TO_BOOL DINT_TO_BOOL(IN);
ST OUT

5958B 2-33
PROGRAM WORX

2.6.6 DINT_TO_BYTE

Description This type conversion function changes an input value of the data type DINT
into an output value of the data type BYTE.
The lowest-order bits of the input value are only converted to the output va-
lue. For example the input value -1 results in the output value 16#FF.

Parameter Data type Description


IN DINT input value
OUT BYTE output value

If the input value is outside the permissible range of the output value, the
output value will be as follows:
input output
-256 ... -1 0 (0HEX) ... 255 (FFHEX)
-512 ... - 257 0 (0HEX) ... 255 (FFHEX)
...
256 ... 511 0 (0HEX) ... 255 (FFHEX)
512 ... 767 0 (0HEX) ... 255 (FFHEX)
...

Example
LD -1 (*loads -1 in accu*)
DINT_TO_BYTE (*converts DINT to BYTE*)
ST var2 (*stores 16#FF in var2*)

Representation
IL ST FBD

LD IN OUT:=
DINT_TO_BYTE DINT_TO_BYTE(IN);
ST OUT

2-34 5958B
Type conversion functions

2.6.7 DINT_TO_WORD

Description This type conversion function changes an input value of the data type DINT
into an output value of the data type WORD.
The lowest-order bits of the input value are only converted to the output va-
lue. For example the input value -1 results in the output value 16#FFFF.

Parameter Data type Description


IN DINT input value
OUT WORD output value

If the input value is outside the permissible range of the output value, the
output value will be as follows:
input output
-1 ... -65,536 FFFFHEX ... 0HEX
-65,537 ... -131,072 FFFFHEX ... 0HEX
...

Example
LD -1 (*loads -1 in accu*)
DINT_TO_WORD (*converts DINT to WORD*)
ST var2 (*stores 16#FFFF in var2*)

Representation
IL ST FBD

LD IN OUT:=
DINT_TO_WORD DINT_TO_WORD(IN);
ST OUT

5958B 2-35
PROGRAM WORX

2.6.8 DINT_TO_DWORD

Description This type conversion function changes an input value of the data type DINT
into an output value of the data type DWORD.

Parameter Data type Description


IN DINT input value
OUT DWORD output value

If the input value is outside the permissible range of the output value, the
output value will be as follows:
input output
-2,147,483,648 ... -1 8000 0000HEX ... FFFF FFFFHEX

Example
LD -1 (*loads -1 in accu*)
DINT_TO_DWORD (*converts DINT to DWORD*)
ST var2 (*stores 16#FFFFFFFF in var2*)

Representation
IL ST FBD

LD IN OUT:=
DINT_TO_DWORD DINT_TO_DWORD(IN);
ST OUT

2-36 5958B
Type conversion functions

2.6.9 DINT_TO_SINT

Description This type conversion function changes an input value of the data type DINT
into an output value of the data type BYTE.
The lowest-order bits of the input value are only converted to the output va-
lue.

Parameter Data type Description


IN DINT input value
OUT SINT output value

If the input value is outside the permissible range of the output value, the
output value will be as follows:
input output
128 ... 383 -128 ... 127
384 ... 639 -128 ... 127

Example
LD -1 (*loads -1 in accu*)-1 (*loads -1 in accu*)
DINT_TO_SINT (*converts DINT to SINT*)
ST var2 (*stores -1 in var2*)

Representation
IL ST FBD

LD IN OUT:=
DINT_TO_SINT DINT_TO_SINT(IN);
ST OUT

5958B 2-37
PROGRAM WORX

2.6.10 DINT_TO_INT

Description This type conversion function changes an input value of the data type DINT
into an output value of the data type INT.
The lowest-order bits of the input value are only converted to the output va-
lue.

Parameter Data type Description


IN DINT input value
OUT INT output value

If the input value is outside the permissible range of the output value, the
output value will be as follows:
input output
32,768 ... 98,303 -32,768 ... 32,767
98,304 ... 163,839 -32,768 ... 32,767
...

Example
LD -1 (*loads -1 in accu*)
DINT_TO_INT (*converts DINT to INT*)
ST var2 (*stores -1 in var2*)

Representation
IL ST FBD

LD IN OUT:=
DINT_TO_INT DINT_TO_INT(IN);
ST OUT

2-38 5958B
Type conversion functions

2.6.11 DINT_TO_REAL

Description This type conversion function changes an input value of the data type DINT
into an output value of the data type REAL.

Parameter Data type Description


IN DINT input value
OUT REAL output value

Example
LD -1 (*loads -1 in accu*)
DINT_TO_REAL (*converts DINT to REAL*)
ST var2 (*stores -1.0000000 E+00 in var2*)

Representation
IL ST FBD

LD IN OUT:=
DINT_TO_REAL DINT_TO_REAL(IN);
ST OUT

5958B 2-39
PROGRAM WORX

2.6.12 DINT_TO_TIME

Description This type conversion function changes an input value of the data type DINT
into an output value of the data type TIME.
As no negative time values are possible the MSB (most significant bit) of
the input value is not interpreted as sign bit.

Parameter Data type Description


IN DINT input value
OUT TIME output value

If the input value is outside the permissible range of the output value, the
output value will be as follows:
input output
-2,147,483,648 ... -1 2,147,483.648s ... 4,294,967.295s

Example
LD -1 (*loads -1 in accu*)
DINT_TO_TIME (*converts DINT to TIME*)
ST var2 (*stores 4294967295 s in var2*)

Representation
IL ST FBD

LD IN OUT:=
DINT_TO_TIME DINT_TO_TIME(IN);
ST OUT

2-40 5958B
Type conversion functions

2.7 DWORD_TO_*

2.7.1 DWORD_TO_BOOL

Description This type conversion function changes an input value of the data type
DWORD into an output value of the data type BOOL.
Any input value unequal to 16#00000000 results in the output value TRUE.

Parameter Data type Description


IN DWORD input value
OUT BOOL output value

Example
LD 16#00000000 (*loads 16#00000000 in accu*)
DWORD_TO_BOOL (*converts DWORD to BOOL*)
ST var2 (*stores 0 (FALSE) in var2*)

Representation
IL ST FBD

LD IN OUT:=
DWORD_TO_BOOL DWORD_TO_BOOL(IN);
ST OUT

5958B 2-41
PROGRAM WORX

2.7.2 DWORD_TO_BYTE

Description This type conversion function changes an input value of the data type
DWORD into an output value of the data type BYTE.
The lowest-order bits of the input value are only converted to the output va-
lue.

Parameter Data type Description


IN DWORD input value
OUT BYTE output value

If the input value is outside the permissible range of the output value, the
output value will be as follows:
input output
256 (100HEX) ... 511 (1FFHEX) 0 (0HEX) ... 255 (FFHEX)
512 (200HEX) ... 767 (2FFHEX) 0 (0HEX) ... 255 (FFHEX)

Example
LD 16#FFFFFFFF (*loads 16#FFFFFFFF in accu*)
DWORD_TO_BYTE (*converts DWORD to BYTE*)
ST var2 (*stores 16#FF in var2*)

Representation
IL ST FBD

LD IN OUT:=
DWORD_TO_BYTE DWORD_TO_BYTE(IN);
ST OUT

2-42 5958B
Type conversion functions

2.7.3 DWORD_TO_WORD

Description This type conversion function changes an input value of the data type
DWORD into an output value of the data type WORD.
The lowest-order bits of the input value are only converted to the output va-
lue.

Parameter Data type Description


IN DWORD input value
OUT WORD output value

If the input value is outside the permissible range of the output value, the
output value will be as follows:
input output
65,536 (10000HEX) ... 131,071 (1FFFFFHEX) 0 (0HEX) ... 65,535 (FFFFHEX)
131,072 (20000HEX) ... 196,607 (2FFFFFHEX) 0 (0HEX) ... 65,535 (FFFFHEX)

Example
LD 16#ABCD7FFF (*loads 16#ABCD7FFF in accu*)
DWORD_TO_WORD (*converts WORD to DWORD*)
ST var2 (*stores 16#7FFF in var2*)

Representation
IL ST FBD

LD IN OUT:=
DWORD_TO_WORD DWORD_TO_WORD(IN);
ST OUT

5958B 2-43
PROGRAM WORX

2.7.4 DWORD_TO_SINT

Description This type conversion function changes an input value of the data type
DWORD into an output value of the data type SINT.
The lowest-order bits of the input value are only converted to the output va-
lue.
If the MSB (most significant bit) of the low byte is set, the input value is con-
verted to a negative output value.

Parameter Data type Description


IN DWORD input value
OUT SINT output value

If the input value is outside the permissible range of the output value, the
output value will be as follows:
input output
128 (80HEX) ... 383 (17FHEX) -128 ... 127
384 (180HEX) ... 639 (27FHEX) -128 ... 127

Example
LD 16#FFFFFF80 (*loads 16#FFFFFF80 in accu*)
DWORD_TO_SINT (*converts DWORD to SINT*)
ST var2 (*stores -128 in var2*)

Representation
IL ST FBD

LD IN OUT:=
DWORD_TO_SINT DWORD_TO_SINT(IN);
ST OUT

2-44 5958B
Type conversion functions

2.7.5 DWORD_TO_INT

Description This type conversion function changes an input value of the data type
DWORD into an output value of the data type DINT.
The lowest-order bits of the input value are only converted to the output va-
lue.
If the MSB (most significant bit) of the low word is set, the input value is
converted to a negative output value.

Parameter Data type Description


IN DWORD input value
OUT INT output value

If the input value is outside the permissible range of the output value, the
output value will be as follows:
input output
32,768 (8000HEX) ... 98,303 (17FFFHEX) -32,768 ... 32,767
98,304 (18000HEX) ... 163,839 (27FFFHEX) -32,768 ... 32,767

Example
LD 16#FFFF8000 (*loads 16#FFFF8000 in accu*)
DWORD_TO_INT (*converts DWORD to INT*)
ST var2 (*stores -32768 in var2*)

Representation
IL ST FBD

LD IN OUT:=
DWORD_TO_INT DWORD_TO_INT(IN);
ST OUT

5958B 2-45
PROGRAM WORX

2.7.6 DWORD_TO_DINT

Description This type conversion function changes an input value of the data type
DWORD into an output value of the data type DINT. A signed conversion
is performed.

Parameter Data type Description


IN DWORD input value
OUT DINT output value

If the input value is outside the permissible range of the output value, the
output value will be as follows:
input output
2,147,483,648 (8000 0000HEX) ... 4,294,967,295 (FFFF FFFFHEX) -2,147,483,648 ... -1

Example
LD 16#FFFFFFFF (*loads 16#FFFFFFFF in accu*)
DWORD_TO_DINT (*converts DWORD to DINT*)
ST var2 (*stores -1 in var2*)

Representation
IL ST FBD

LD IN OUT:=
DWORD_TO_DINT DWORD_TO_DINT(IN);
ST OUT

2-46 5958B
Type conversion functions

2.7.7 DWORD_TO_REAL

Description This type conversion function changes an input value of the data type
DWORD into an output value of the data type REAL.
The MSB (most significant bit) of the DWORD value is interpreted as sign
bit. DWORD values greater than 16#7FFFFFFF result in negative values
of the output data type. For example the input value 16#80000000 results
in the output value -2.1474836 E+09.

Parameter Data type Description


IN DWORD input value
OUT REAL output value

Example
LD 16#80000000 (*loads 16#80000000 in accu*)
DWORD_TO_REAL (*converts DWORD to REAL*)
ST var2 (*stores -2.1474836 E+09 in var2*)

Representation
IL ST FBD

LD IN OUT:=
DWORD_TO_REAL DWORD_TO_REAL(IN);
ST OUT

5958B 2-47
PROGRAM WORX

2.8 INT_TO_*

2.8.1 INT_TO_B_BCD

Description This type conversion function changes an input value of the data type INT
into a BCD output value (binary-code decimal number) of the data type
BYTE.
Negative input values are always converted to 16#FF. For example the in-
put value -128 results in the output value 16#FF.
In case of input values which are not within the valid scope of the output
data type (BCD) the lowest-order bits of the input value are only interpre-
ted.

Parameter Data type Description


IN INT input value
OUT BYTE output value

Example
LD 32767 (*loads 32767 in accu*)
INT_TO_B_BCD (*converts INT to BCD value of data type BYTE*)
ST var2 (*stores 16#67 in var2*)

Representation
IL ST FBD

LD IN OUT:=
INT_TO_B_BCD INT_TO_B_BCD(IN);
ST OUT

2-48 5958B
Type conversion functions

2.8.2 INT_TO_W_BCD

Description This type conversion function changes an input value of the data type INT
into a BCD output value (binary-code decimal number) of the data type
WORD.
Negative input values are always converted to 16#FFFF. For example the
input value -128 results in the output value 16#FFFF.
In case of input values which are not within the valid scope of the output
data type (BCD) the lowest-order bits of the input value are only interpre-
ted.

Parameter Data type Description


IN INT input value
OUT WORD output value

Example
LD 32767 (*loads 32767 in accu*)
INT_T_W_BCD (*converts INT to BCD value of data type WORD*)
ST var2 (*stores 16#2767 in var2*)

Representation
IL ST FBD

LD IN OUT:=
INT_TO_W_BCD INT_TO_W_BCD(IN);
ST OUT

5958B 2-49
PROGRAM WORX

2.8.3 INT_TO_D_BCD

Description This type conversion function changes an input value of the data type INT
into a BCD output value (binary-code decimal number) of the data type
DWORD.
Negative input values are always converted to 16#FFFFFFFF. For examp-
le the input value -128 results in the output value 16#FFFFFFFF.

Parameter Data type Description


IN INT input value
OUT DWORD output value

Example
LD 32767 (*loads 32767 in accu*)
INT_TO_D_BCD (*converts INT to BCD value of data type DWORD*)
ST var2 (*stores 16#00032767 in var2*)

Representation
IL ST FBD

LD IN OUT:=
INT_TO_D_BCD INT_TO_D_BCD(IN);
ST OUT

2-50 5958B
Type conversion functions

2.8.4 INT_TO_BOOL

Description This type conversion function changes an input value of the data type INT
into an output value of the data type BOOL.
Any input value unequal to 0 results in the output value TRUE.

Parameter Data type Description


IN INT input value
OUT BOOL output value

Example
LD 14 (*loads 14 in accu*)
INT_TO_BOOL (*converts INT to BOOL*)
ST var2 (*stores 1 (TRUE) in var2*)

Representation
IL ST FBD

LD IN OUT:=
INT_TO_BOOL INT_TO_BOOL(IN);
ST OUT

5958B 2-51
PROGRAM WORX

2.8.5 INT_TO_BYTE

Description This type conversion function changes an input value of the data type INT
into an output value of the data type BYTE.
The lowest-order bits of the input value are only converted to the output va-
lue. For example the input value 32767 results in the output value 16#FF.

Parameter Data type Description


IN INT input value
OUT BYTE output value

If the input value is outside the permissible range of the output value, the
output value will be as follows:
input output
-256 ... -1 0 (0HEX) ... 255 (FFHEX)
-512 ... - 257 0 (0HEX) ... 255 (FFHEX)
...
256 ... 511 0 (0HEX) ... 255 (FFHEX)
512 ... 767 0 (0HEX) ... 255 (FFHEX)
...

Example
LD -1 (*loads -1 in accu*)
INT_TO_BYTE (*converts INT to BYTE*)
ST var2 (*stores 16#FF in var2*)

Representation
IL ST FBD

LD IN OUT:=
INT_TO_BYTE INT_TO_BYTE(IN);
ST OUT

2-52 5958B
Type conversion functions

2.8.6 INT_TO_WORD

Description This type conversion function changes an input value of the data type INT
into an output value of the data type WORD.

Parameter Data type Description


IN INT input value
OUT WORD output value

If the input value is outside the permissible range of the output value, the
output value will be as follows:
input output
-32,768 ... -1 8000HEX ...FFFFHEX

Example
LD 32767 (*loads 32767 in accu*)
INT_TO_WORD (*converts INT to WORD*)
ST var2 (*stores 16#7FFF in var2*)

Representation
IL ST FBD

LD IN OUT:=
INT_TO_WORD INT_TO_WORD(IN);
ST OUT

5958B 2-53
PROGRAM WORX

2.8.7 INT_TO_DWORD

Description This type conversion function changes an input value of the data type INT
into an output value of the data type DWORD.
The bit pattern of the input is converted to the lowest-order bits of the out-
put. For example the input value 32767 results in the output value
16#00007FFF.

Parameter Data type Description


IN INT input value
OUT DWORD output value

If the input value is outside the permissible range of the output value, the
output value will be as follows:
input output
-32,768 ... -1 0000 8000HEX ... 0000 FFFFHEX

Example
LD -32768 (*loads in -32768 in accu*)
INT_TO_DWORD (*converts INT to DWORD*)
ST var2 (*stores 16#00008000 in var2*)

Representation
IL ST FBD

LD IN
OUT:=
INT_TO_DWORD INT_TO_DWORD(IN);
ST OUT

2-54 5958B
Type conversion functions

2.8.8 INT_TO_SINT

Description This type conversion function changes an input value of the data type INT
into an output value of the data type SINT.
The lowest-order bits of the input value are only converted to the output va-
lue.

Parameter Data type Description


IN INT input value
OUT SINT output value

If the input value is outside the permissible range of the output value, the
output value will be as follows:
input output
128 ... 383 -128 ... 127
384 ... 639 -128 ... 127
...
-384 ... -129 -128 ... 127
-640 ... -385 -128 ... 127
...

Example
LD -32768 (*loads in -32768 in accu*)
INT_TO_SINT (*converts INT to SINT*)
ST var2 (*stores 0 in var2*)

Representation
IL ST FBD

LD IN OUT:=
INT_TO_SINT INT_TO_SINT(IN);
ST OUT

5958B 2-55
PROGRAM WORX

2.8.9 INT_TO_DINT

Description This type conversion function changes an input value of the data type INT
into an output value of the data type DINT.

Parameter Data type Description


IN INT input value
OUT DINT output value

Example
LD -32768 (*loads in -32768 in accu*)
INT_TO_DINT (*converts INT to DINT*)
ST var2 (*stores -32768 in var2*)

Representation
IL ST FBD

LD IN OUT:=
INT_TO_DINT INT_TO_DINT(IN);
ST OUT

2-56 5958B
Type conversion functions

2.8.10 INT_TO_REAL

Description This type conversion function changes an input value of the data type INT
into an output value of the data type REAL.

Parameter Data type Description


IN INT input value
OUT REAL output value

Example
LD -32768 (*loads -32768 in accu*)
INT_TO_REAL (*converts INT to REAL*)
ST var2 (*stores -3.2768000 E+04 in var2*)

Representation
IL ST FBD

LD IN OUT:=
INT_TO_REAL INT_TO_REAL(IN);
ST OUT

5958B 2-57
PROGRAM WORX

2.9 REAL_TO_*

2.9.1 REAL_TO_BOOL

Description This type conversion function changes an input value of the data type
REAL into an output value of the data type BOOL.
Any input value unequal to 0.0000000 E+00 results in the output value
TRUE.

Parameter Data type Description


IN REAL input value
OUT BOOL output value

Example
LD 2.0000000 E+01 (*loads 2.0000000 E+01 in accu*)
REAL_TO_BOOL (*converts REAL to BOOL*)
ST var2 (*stores 1 (TRUE) in var2*)

Representation
IL ST FBD

LD IN OUT:=
REAL_TO_BOOL REAL_TO_BOOL(IN);
ST OUT

2-58 5958B
Type conversion functions

2.9.2 REAL_TO_BYTE

Description This type conversion function changes an input value of the data type
REAL into an output value of the data type BYTE.
The type conversion is divided into two steps. First the real value is roun-
ded (up to 0.49 the value is rounded down, values equal or greater than
0.50 are rounded off) and subsequently converted into a DWORD value. In
the second step the rounded input value is converted to the lowest-order
bits of the output value.

Parameter Data type Description


IN REAL input value
OUT BYTE output value

If the input value is outside the permissible range of the output value, the
output value will be as follows:
input output
-1 ... -256 FFHEX ...0HEX
-257 ... -512 FFHEX ...0HEX
...
256 ... 511 FFHEX ...0HEX
512 ... 1023 FFHEX ...0HEX
...

Example
LD 2147483647 (*loads 2147483647 in accu*)
REAL_TO_BYTE (*converts REAL to BYTE*)
ST var2 (*stores 16#FF in var2*)

Representation
IL ST FBD

LD IN OUT:=
REAL_TO_BYTE REAL_TO_BYTE(IN);
ST OUT

5958B 2-59
PROGRAM WORX

2.9.3 REAL_TO_WORD

Description This type conversion function changes an input value of the data type
REAL into an output value of the data type WORD.
The type conversion is divided into two steps. First the real value is roun-
ded (up to 0.49 the value is rounded down, values equal or greater than
0.50 are rounded off) and subsequently converted into a DWORD value. In
the second step the rounded input value is converted to the lowest-order
bits of the output value.

Parameter Data type Description


IN REAL input value
OUT WORD output value

If the input value is outside the permissible range of the output value, the
output value will be as follows:
input output
-1 ... -65,536 FFFFHEX ... 0HEX
-65,537 ... -131,072 FFFFHEX ... 0HEX
...
65,536 ... 131,071 0HEX ... FFFFHEX
131,072 ... 196,607 0HEX ... FFFFHEX
...

Example
LD 2147483647 (*loads 2147483647 in accu*)
REAL_TO_WORD (*converts REAL to WORD*)
ST var2 (*stores 16#FFFF in var2*)

Representation
IL ST FBD

LD IN OUT:=
REAL_TO_WORD REAL_TO_WORD(IN);
ST OUT

2-60 5958B
Type conversion functions

2.9.4 REAL_TO_DWORD

Description This type conversion function changes an input value of the data type
REAL into an output value of the data type DWORD.
The type conversion is divided into two steps. First the real value is roun-
ded (up to 0.49 the value is rounded down, values equal or greater than
0.50 are rounded off) and subsequently converted into a DWORD value. In
the second step the complete DWORD value is converted to the output va-
lue.

Parameter Data type Description


IN REAL input value
OUT DWORD output value

If the input value is outside the permissible range of the output value, the
output value will be as follows:
input output
-1 ... -4,294,967,295 FFFF FFFFHEX ... 0HEX
-4,294,967,296 ... -8,589,934,590 FFFF FFFFHEX ... 0HEX
...
4,294,967,296 ... 8,589,934,589 0HEX ... FFFF FFFFHEX
8,589,934,590 ... 12,884,901,885 0HEX ... FFFF FFFFHEX

Example
LD 2147483647 (*loads 2147483647 in accu*)
REAL_TO_DWORD (*converts REAL to DWORD*)
ST var2 (*stores 16#7FFFFFFF in var2*)

Representation
IL ST FBD

LD IN OUT:=
REAL_TO_DWORD REAL_TO_DWORD(IN);
ST OUT

5958B 2-61
PROGRAM WORX

2.9.5 REAL_TO_SINT

Description This type conversion function changes an input value of the data type
REAL into an output value of the data type SINT.
The type conversion is divided into two steps. First the real value is roun-
ded (up to 0.49 the value is rounded down, values equal or greater than
0.50 are rounded off) and subsequently converted into a DWORD value. In
the second step the rounded input value is converted to the lowest-order
bits of the output value.

Parameter Data type Description


IN REAL input value
OUT SINT output value

If the input value is outside the permissible range of the output value, the
output value will be as follows:
input output
128.0 ... 383.0 128 ... 127
384.0 ... 639.0 128 ... 127

Example
LD 2147483647 (*loads 2147483647 in accu*)
REAL_TO_SINT (*converts REAL to SINT*)
ST var2 (*stores -1 in var2*)

Representation
IL ST FBD

LD IN OUT:=
REAL_TO_SINT REAL_TO_SINT(IN);
ST OUT

2-62 5958B
Type conversion functions

2.9.6 REAL_TO_INT

Description This type conversion function changes an input value of the data type
REAL into an output value of the data type INT.
The type conversion is divided into two steps. First the real value is roun-
ded (up to 0.49 the value is rounded down, values equal or greater than
0.50 are rounded off) and subsequently converted into a DWORD value. In
the second step the rounded input value is converted to the lowest-order
bits of the output value.

Parameter Data type Description


IN REAL input value
OUT INT output value

If the input value is outside the permissible range of the output value, the
output value will be as follows:
input output
32,768.0 ... 98,303 -32,768 ... 32,767
98,304.0 ... 163,839 -32,768 ... 32,767

Example
LD 2147483647 (*loads 2147483647 in accu*)
REAL_TO_INT (*converts REAL to INT*)
ST var2 (*stores -1 in var2*)

Representation
IL ST FBD

LD IN OUT:=
REAL_TO_INT REAL_TO_INT(IN);
ST OUT

5958B 2-63
PROGRAM WORX

2.9.7 REAL_TO_DINT

Description This type conversion function changes an input value of the data type
REAL into an output value of the data type DINT.
The type conversion is divided into two steps. First the real value is roun-
ded (up to 0.49 the value is rounded down, values equal or greater than
0.50 are rounded off) and subsequently converted into a DWORD value. In
the second step the complete DWORD value is converted to the output va-
lue.
In case of input values which are not within the valid scope of the output
data type the output value is implementation-dependent.

Parameter Data type Description


IN REAL input value
OUT DINT output value

Example
LD 2147483647 (*loads 2147483647 in accu*)
REAL_TO_DINT (*converts REAL to DINT*)
ST var2 (*stores 2.1474836 E+09 in var2*)

Representation
IL ST FBD

LD IN
OUT:=
REAL_TO_DINT
REAL_TO_DINT(IN);
ST OUT

2-64 5958B
Type conversion functions

2.10 SINT_TO_*

2.10.1 SINT_TO_B_BCD

Description This type conversion function changes an input value of the data type SINT
into a BCD output value (binary-code decimal number) of the data type
BYTE.
Negative input values are always converted to 16#FF. For example the in-
put value -128 results in the output value 16#FF.
In case of input values which are not within the valid scope of the output
data type (BCD) the lowest-order bits of the input value are only interpre-
ted.

Parameter Data type Description


IN SINT input value
OUT BYTE output value

Example
LD 127 (*loads 127 in accu*)
SINT_TO_B_BCD (*converts SINT to BCD value of data type BYTE*)
ST var2 (*stores 16#27 in var2*)

Representation
IL ST FBD

LD IN
OUT:=
SINT_TO_B_BCD
SINT_TO_B_BCD(IN);
ST OUT

5958B 2-65
PROGRAM WORX

2.10.2 SINT_TO_W_BCD

Description This type conversion function changes an input value of the data type SINT
into a BCD output value (binary-code decimal number) of the data type
WORD.
Negative input values are always converted to 16#FFFF. For example the
input value -128 results in the output value 16#FFFF.

Parameter Data type Description


IN SINT input value
OUT WORD output value

Example
LD 127 (*loads 127 in accu*)
SINT_TO_W_BCD (*converts SINT to BCD value of data type WORD*)
ST var2 (*stores 16#0127 in var2*)

Representation
IL ST FBD

LD IN OUT:=
SINT_TO_W_BCD SINT_TO_W_BCD(IN);
ST OUT

2-66 5958B
Type conversion functions

2.10.3 SINT_TO_D_BCD

Description
This type conversion function changes an input value of the data type SINT
into a BCD output value (binary-code decimal number) of the data type
DWORD.
Negative input values are always converted to 16#FFFFFFFF. For examp-
le the input value -128 results in the output value 16#FFFFFFFF.

Parameter Data type Description


IN SINT input value
OUT DWORD output value

Example
LD 127 (*loads 127 in accu*)
SINT_TO_D_BCD (*converts SINT to BCD value of data type DWORD*)
ST var2 (*stores 16#00000127 in var2*)

Representation
IL ST FBD

LD IN OUT:=
SINT_TO_D_BCD SINT_TO_D_BCD(IN);
ST OUT

5958B 2-67
PROGRAM WORX

2.10.4 SINT_TO_BOOL

Description This type conversion function changes an input value of the data type SINT
into an output value of the data type BOOL.
Any input value unequal to 0 results in the output value TRUE.

Parameter Data type Description


IN SINT input value
OUT BOOL output value

Example
LD 14 (*loads 14 in accu*)
SINT_TO_BOOL (*converts SINT to BOOL*)
ST var2 (*stores 1 (TRUE) in var2*)

Representation
IL ST FBD

LD IN OUT:=
SINT_TO_BOOL SINT_TO_BOOL(IN);
ST OUT

2-68 5958B
Type conversion functions

2.10.5 SINT_TO_BYTE

Description This type conversion function changes an input value of the data type SINT
into an output value of the data type BYTE.

Parameter Data type Description


IN SINT input value
OUT BYTE output value

If the input value is outside the permissible range of the output value, the
output value will be as follows:
input output
-128 ... -1 80HEX ... FFHEX

Example
LD -127 (*loads 127 in accu*)
SINT_TO_BYTE (*converts SINT to BYTE*)
ST var2 (*stores 16#7F in var2*)

Representation
IL ST FBD

LD IN OUT:=
SINT_TO_BYTE SINT_TO_BYTE(IN);
ST OUT

5958B 2-69
PROGRAM WORX

2.10.6 SINT_TO_WORD

Description This type conversion function changes an input value of the data type SINT
into an output value of the data type WORD.
The bit pattern of the input is converted to the lowest-order bits of the out-
put. For example the input value 127 results in the output value 16#007F.

Parameter Data type Description


IN SINT input value
OUT WORD output value

If the input value is outside the permissible range of the output value, the
output value will be as follows:
input output
-128 ...-1 0080HEX ... 00FFHEX

Example
LD -128 (*loads -128 in accu*)
SINT_TO_WORD (*converts SINT to WORD*)
ST var2 (*stores 16#0080 in var2*)

Representation
IL ST FBD

LD IN OUT:=
SINT_TO_WORD SINT_TO_WORD(IN);
ST OUT

2-70 5958B
Type conversion functions

2.10.7 SINT_TO_DWORD

Description This type conversion function changes an input value of the data type SINT
into an output value of the data type DWORD.
The bit pattern of the input is converted to the lowest-order bits of the out-
put. For example the input value 127 results in the output value
16#0000007F.

Parameter Data type Description


IN SINT input value
OUT DWORD output value

If the input value is outside the permissible range of the output value, the
output value will be as follows:
input output
-128 ... -1 0000 0080HEX ... 0000 00FFHEX

Example
LD -128 (*loads -128 in accu*)
SINT_TO_DWORD (*converts SINT to DWORD*)
ST var2 (*stores 16#00000080 in var2*)

Representation
IL ST FBD

LD IN OUT:=
SINT_TO_DWORD SINT_TO_DWORD(IN);
ST OUT

5958B 2-71
PROGRAM WORX

2.10.8 SINT_TO_INT

Description This type conversion function changes an input value of the data type SINT
into an output value of the data type INT.

Parameter Data type Description


IN SINT input value
OUT INT output value

Example
LD -128 (*loads -128 in accu*)
SINT_TO_INT (*converts SINT to INT*)
ST var2 (*stores -128 in var2*)

Representation
IL ST FBD

LD IN OUT:=
SINT_TO_INT SINT_TO_INT(IN);
ST OUT

2-72 5958B
Type conversion functions

2.10.9 SINT_TO_DINT

Description This type conversion function changes an input value of the data type SINT
into an output value of the data type DINT.

Parameter Data type Description


IN SINT input value
OUT DINT output value

Example
LD -128 (*loads -128 in accu*)
SINT_TO_DINT (*converts SINT to DINT*)
ST var2 (*stores -128 in var2*)

Representation
IL ST FBD

LD IN OUT:=
SINT_TO_DINT SINT_TO_DINT(IN);
ST OUT

5958B 2-73
PROGRAM WORX

2.10.10 SINT_TO_REAL

Description This type conversion function changes an input value of the data type SINT
into an output value of the data type REAL.

Parameter Data type Description


IN SINT input value
OUT REAL output value

Example
LD -128 (*loads -128 in accu*)
SINT_TO_REAL (*converts SINT to REAL*)
ST var2 (*stores -1.2800000 E+02 in var2*)

Representation
IL ST FBD

LD IN OUT:=
SINT_TO_REAL SINT_TO_REAL(IN);
ST OUT

2-74 5958B
Type conversion functions

2.11 STRING_TO_*

This type conversion function changes an input value of the data type
STRING into an output value of the connected data type.
’*’ is a placeholder for the supported data types. The function is available
for the data types BYTE, WORD, DWORD, SINT, INT, DINT, REAL and
TIME.

Parameter Data types Description


IN STRING input value
OUT BYTE, WORD, DWORD, SINT, INT, DINT, output value
REAL, TIME

Error reaction and treatment


There is a difference in the error treatment of string errors in the different
PLC versions.
For IPC_28, M68_28 and former versions the following occurs:
– in case of a wrong input a string error results. Subsequently the PLC
will go into the state 'STOP'.
– in case of values which are not within the valid scope of the output data
type an overflow occurs.
The following described error handling is only valid for IPC_30, M68_30
and higher versions.
During value transformation the following errors may occur:
– the connected string represents a literal which is not valid for the output
data type. For example the input value INT#123 shall be converted
using the function STRING_TO_TIME.
– the input value is out of the range for the output data type. For example
the input value 16#1024 shall be converted using the function
STRING_TO_BYTE.
– the value does not fit to the literal. For example the input value
INT#1000000 shall be converted using the function
STRING_TO_DINT.
– the connected string is empty.

5958B 2-75
PROGRAM WORX

In case of a wrong input the result variable gets the value ’0’. If the connec-
ted string is empty (even no blanks), the program will not be interrupted. In
all other cases a string exception occurs and the SPG 21 is called. Further-
more an entry is made in the error catalogue including the corresponding
module and the associated line number. The PLC keeps in the state ’RUN’.

Specialty of transformation
When converting strings it is always searched for the first occurrence of the
character ’#’ in the connected string. If this character is found, an evaluation
of the type or format identifier in front of this character is done. In principle
it is possible to transform a number which is embedded in a string.
For example the string ’Jack is INT#40 years old’ results in the output
value 40.
The further evaluation is done as the character ’#’ is not included in the
string. If this character is not found in the string, the evaluation starts at the
beginning of the string. All white spaces are skipped, till the first character
is found which is not a white space (see the following table for regarded
’white spaces’). The evaluation starts.
The evaluation is stopped if a character is found which is not a valid literal.
The evaluation of the strings ’INT#50 J’ and ’INT#50J’ gives the result value
50, both.
The following ASCII codes are regarded as ’white spaces’:

Character Value
horizontal tab 9 (09h)
line feed 10 (0Ah)
vertical tab 11 (0Bh)
form feed 12 (0Ch)
carriage return 13 (0Dh)
blank 32 (20h)

Example
LD ’INT#123’ (*loads ’INT#123’ in accu*)
STRING_TO_INT (*converts STRING to INT*)
ST var3 (*stores ’123’ in var3*)

2-76 5958B
Type conversion functions

Representation
IL ST FBD

LD IN OUT:= Example for function


STRING_TO_* STRING_TO_*(IN); STRING_TO_INT
ST OUT

For using the function just replace * by the corresponding data type.

5958B 2-77
PROGRAM WORX

2.12 TIME_TO_*

2.12.1 TIME_TO_DINT

Description This type conversion function changes an input value of the data type
REAL into an output value of the data type DINT.
The data type TIME is interpreted as unsigned value. Following this time
values greater than 2,147,483.647s are converted to negative values of the
data type DINT.

Parameter Data type Description


IN TIME input value
OUT DINT output value

If the input value is outside the permissible range of the output value, the
output value will be as follows:
input output
2,147,483.648s ...4,294,967.295s -2,147,483,648 ... -1

Example
LD T#2147483.647s (*loads 2147483647 in accu*)
TIME_TO_DINT (*converts REAL to DINT*)
ST var2 (*stores 2147483647 in var2*)

Representation
IL ST FBD

LD IN OUT:=
TIME_TO_DINT TIME_TO_DINT(IN);
ST OUT

2-78 5958B
Type conversion functions

2.13 TRUNC_*

Description This type conversion function cuts decimal places standing behind the
point to form an integer value.

Parameter Data types Description


IN1 REAL input value
OUT INT, SINT, DINT output value

Example
LD REAL#1.2 (*loads 1.2 in accu*)
TRUNC_INT
ST var2 (*stores 1 in var2*)

Representation
IL ST FBD

LD IN1 Example for function


OUT:=TRUNC_*(IN1);
TRUNC_* TRUNC_INT
ST OUT

For using the function just replace * by the corresponding data type.

5958B 2-79
PROGRAM WORX

2.14 W_BCD_TO_*

2.14.1 W_BCD_TO_SINT

Description This type conversion function changes a BCD input value (binary-coded
decimal number) of the data type WORD into an output value of the data
type SINT.
If an incorrect input value (permissible value range 0 to 9) is applied the
output value is converted to -1. For example the input value 16#0A0B re-
sults in the output value -1.
In case of values which are not within the valid scope of the output data
type it has to be considered that there will be an overflow.

Parameter Data type Description


IN WORD input value
OUT SINT output value

Example
LD 16#9999 (*loads 16#9999 in accu*)
W_BCD_TO_SINT (*converts BCD input value (data type WORD)
to SINT*)
ST var2 (*stores 9999 in var2*)

Representation
IL ST FBD

LD IN OUT:=
W_BCD_TO_SINT W_BCD_TO_SINT(IN);
ST OUT

2-80 5958B
Type conversion functions

2.14.2 W_BCD_TO_INT

Description This type conversion function changes a BCD input value (binary-coded
decimal number) of the data type WORD into an output value of the data
type INT.
If an incorrect input value (permissible value range 0 to 9) is applied the
output value is converted to -1. For example the input value 16#0A0B re-
sults in the output value -1.
In case of values which are not within the valid scope of the output data
type it has to be considered that there will be an overflow.

Parameter Data type Description


IN WORD input value
OUT INT output value

Example
LD 16#9999 (*loads 16#9999 in accu*)
W_BCD_TO_INT (*converts BCD input value (data type WORD) to INT*)
ST var2 (*stores 9999 in var2*)

Representation
IL ST FBD

LD IN OUT:=
W_BCD_TO_INT W_BCD_TO_INT(IN);
ST OUT

5958B 2-81
PROGRAM WORX

2.14.3 W_BCD_TO_DINT

Description This type conversion function changes a BCD input value (binary-coded
decimal number) of the data type WORD into an output value of the data
type DINT.
If an incorrect input value (permissible value range 0 to 9) is applied the
output value is converted to -1. For example the input value 16#0A0B re-
sults in the output value -1.
In case of values which are not within the valid scope of the output data
type it has to be considered that there will be an overflow.

Parameter Data type Description


IN WORD input value
OUT DINT output value

Example
LD 16#9999 (*loads 16#9999 in accu*)
W_BCD_TO_DINT (*converts BCD input value (data type WORD)
to DINT*)
ST var2 (*stores 9999 in var2*)

Representation
IL ST FBD

LD IN
OUT:=
W_BCD_TO_DINT
W_BCD_TO_DINT(IN);
ST OUT

2-82 5958B
Type conversion functions

2.15 WORD_TO_*

2.15.1 WORD_TO_BOOL

Description This type conversion function changes an input value of the data type
WORD into an output value of the data type BOOL.
Any input value unequal to 16#00 results in the output value TRUE.

Parameter Data type Description


IN WORD input value
OUT BOOL output value

Example
LD 16#0000 (*loads 16#0000 in accu*)
WORD_TO_BOOL (*converts WORD to BOOL*)
ST var2 (*stores 0 (FALSE) in var2*)

Representation
IL ST FBD

LD IN OUT:=
WORD_TO_BOOL WORD_TO_BOOL(IN);
ST OUT

5958B 2-83
PROGRAM WORX

2.15.2 WORD_TO_BYTE

Description This type conversion function changes an input value of the data type
WORD into an output value of the data type BYTE.
The lowest-order bits of the input value are only converted to the output va-
lue.

Parameter Data type Description


IN WORD input value
OUT BYTE output value

If the input value is outside the permissible range of the output value, the
output value will be as follows:
input output
256 (100HEX) ... 511 (1FFHEX) 0 (0HEX) ... 255 (FFHEX)
512 (200HEX) ... 767 (2FFHEX) 0 (0HEX) ... 255 (FFHEX)

Example
LD 16#FFFF (*loads 16#FFFF in accu*)
WORD_TO_BYTE (*converts WORD to BYTE*)
ST var2 (*stores 16#FF in var2*)

Representation
IL ST FBD

LD IN OUT:=
WORD_TO_BYTE WORD_TO_BYTE(IN);
ST OUT

2-84 5958B
Type conversion functions

2.15.3 WORD_TO_DWORD

Description This type conversion function changes an input value of the data type
WORD into an output value of the data type DWORD.
The bit pattern of the input is converted to the lowest-order bits of the out-
put. For example the input value 16#FFFF results in the output value
16#0000FFFF.

Parameter Data type Description


IN WORD input value
OUT BYTE output value

Example
LD 16#FFFF (*loads 16#FFFF in accu*)
WORD_TO_DWORD (*converts WORD to DWORD*)
ST var2 (*stores 16#0000FFFF in var2*)

Representation
IL ST FBD

LD IN OUT:=
WORD_TO_DWORD WORD_TO_DWORD(IN);
ST OUT

5958B 2-85
PROGRAM WORX

2.15.4 WORD_TO_SINT

Description This type conversion function changes an input value of the data type
WORD into an output value of the data type SINT.
The lowest-order bits of the input value are only converted to the output va-
lue.
If the MSB (most significant bit) of the low byte is set, the input value is con-
verted to a negative output value.

Parameter Data type Description


IN WORD input value
OUT SINT output value

If the input value is outside the permissible range of the output value, the
output value will be as follows:
input output
128 (80HEX) ... 383 (17FHEX) -128 ... 127
384 (180HEX) ... 639 (27FHEX) -128 ... 127

Example
LD 16#FFFF (*loads 16#FFFF in accu*)
WORD_TO_SINT (*converts WORD to SINT*)
ST var2 (*stores -1 in var2*)

Representation
IL ST FBD

LD IN OUT:=
WORD_TO_SINT WORD_TO_SINT(IN);
ST OUT

2-86 5958B
Type conversion functions

2.15.5 WORD_TO_INT

Description This type conversion function changes an input value of the data type
WORD into an output value of the data type INT.
A signed conversion is performed. For output data types greater than the
input data type a sign-conformed expansion is additionally performed.

Parameter Data type Description


IN WORD input value
OUT INT output value

If the input value is outside the permissible range of the output value, the
output value will be as follows:
input output
32,768 (8000HEX) ... 65,535 (FFFFHEX) -32,768 ... -1

Example
LD 16#FFFF (*loads 16#FFFF in accu*)
WORD_TO_INT (*converts WORD to INT*)
ST var2 (*stores -1 in var2*)

Representation
IL ST FBD

LD IN OUT:=
WORD_TO_INT WORD_TO_INT(IN);
ST OUT

5958B 2-87
PROGRAM WORX

2.15.6 WORD_TO_DINT

Description This type conversion function changes an input value of the data type
WORD into an output value of the data type DINT.
A signed conversion is performed. For output data types greater than the
input data type a sign-conformed expansion is additionally performed.
The bit pattern of the input is converted to the lowest-order bits of the out-
put.

Parameter Data type Description


IN WORD input value
OUT DINT output value

If the input value is outside the permissible range of the output value, the
output value will be as follows:
input output
32,768 (8000HEX) ... 65,535 (FFFFHEX) -32,768 ... -1

Example
LD 16#7FFF (*loads 16#7FFF in accu*)
WORD_TO_DINT (*converts WORD to DINT*)
ST var2 (*stores 32767 in var2*)

Representation
IL ST FBD

LD IN OUT:=
WORD_TO_DINT WORD_TO_DINT(IN);
ST OUT

2-88 5958B
Type conversion functions

2.15.7 WORD_TO_REAL

Description This type conversion function changes an input value of the data type
WORD into an output value of the data type REAL.
The MSB (most significant bit) of the WORD value is interpreted as sign bit.
WORD values greater than 16#7FFF result in negative values of the output
data type. For example the input value 16#8000 results in the output value
-3.2768000 E+04.
The bit pattern of the input is converted to the lowest-order bits of the out-
put. For example the input value 16#FFFF results in the output value -
1.0000000 E+00.

Parameter Data type Description


IN WORD input value
OUT REAL output value

Example
LD 16#7FFF (*loads 16#7FFF in accu*)
WORD_TO_DINT (*converts WORD to REAL*)
ST var2 (*stores 3.2767000 E+04 in var2*)

Representation
IL ST FBD

LD IN OUT:=
WORD_TO_REAL WORD_TO_REAL(IN);
ST OUT

5958B 2-89
PROGRAM WORX

2-90 5958B
Section 3
This section provides information on
– how to use numerical functions

Numerical functions ..............................................................................................3-3


3.1 ABS .............................................................................................3-4
3.2 ACOS ..........................................................................................3-5
3.3 ASIN............................................................................................3-6
3.4 ATAN...........................................................................................3-7
3.5 COS ............................................................................................3-8
3.6 EXP .............................................................................................3-9
3.7 LN..............................................................................................3-10
3.8 LOG...........................................................................................3-11
3.9 SIN ............................................................................................3-12
3.10 SQRT ........................................................................................3-13
3.11 TAN ...........................................................................................3-14

5958B 3-1
3-2 5958B
Numerical functions

3 Numerical functions
The following numerical functions are available:

Table 3-1 Numerical functions

Function Short description


ABS Absolute value
ACOS Arc cosine
ASIN Arc sine
ATAN Arc tangent
COS Cosine
EXP Exponent
LN Natural logarithm
LOG Logarithm to the base of 10
SIN Sine
SQRT Square root
TAN Tangent

5958B 3-3
PROGRAM WORX

3.1 ABS

Description This numerical function calculates the absolute value of the operand con-
nected to the input parameter.

Parameter Data types Description


IN1 ANY_NUM input value
OUT ANY_NUM output value

All parameters must have the same data type.

Example
LD -5 (*loads -5 in accu*)
ABS
ST var2 (*stores 5 in var2*)

Representation
IL ST FBD

LD IN1 OUT:=ABS(IN1);
ABS
ST OUT

3-4 5958B
Numerical functions

3.2 ACOS

Description This numerical function calculates the principal arc cosine of the operand
connected to the input parameter.

Parameter Data types Description


IN1 REAL input value
OUT REAL output value in radians

Example
LD REAL#1.0 (*loads 1.0 in accu*)
ACOS
ST var2 (*stores 0.0 in var2*)

Representation
IL ST FBD

LD IN1 OUT:=ACOS(IN1);
ACOS
ST OUT

5958B 3-5
PROGRAM WORX

3.3 ASIN

Description This numerical function calculates the principal arc sine value of the ope-
rand connected to the input parameter.

Parameter Data types Description


IN1 REAL input value
OUT REAL output value in radians

Example
LD REAL#0.0 (*loads 0.0 in accu*)
ASIN
ST var2 (*stores 0.0 in var2*)

Representation
IL ST FBD

LD IN1 OUT:=ASIN(IN1);
ASIN
ST OUT

3-6 5958B
Numerical functions

3.4 ATAN

Description This numerical function calculates the principal arc tangent value of the
operand connected to the input parameter.

Parameter Data types Description


IN1 REAL input value
OUT REAL output value in radians

Example
LD REAL#0.0 (*loads 0.0 in accu*)
ATAN
ST var2 (*stores 0.0 in var2*)

Representation
IL ST FBD

LD IN1 OUT:=ATAN(IN1);
ATAN
ST OUT

5958B 3-7
PROGRAM WORX

3.5 COS

Description This numerical function calculates the cosine of the operands connected
to the input parameter.

Parameter Data types Description


IN1 REAL input value in radians
OUT REAL output value

Example
LD REAL#0.0 (*loads 0.0 in accu*)
COS
ST var2 (*stores 1.0 in var2*)

Representation
IL ST FBD

LD IN1 OUT:=COS(IN1);
COS
ST OUT

3-8 5958B
Numerical functions

3.6 EXP

Description This numerical function calculates the natural exponential of the operand
connected to the input parameter.

Parameter Data types Description


IN1 REAL exponent to base e
OUT REAL output value

Example
LD REAL#0.0 (*loads 0.0 in accu*)
EXP
ST var2 (*stores 1.0 in var2*)

Representation
IL ST FBD

LD IN1 OUT:=EXP(IN1);
EXP
ST OUT

5958B 3-9
PROGRAM WORX

3.7 LN

Description This numerical function calculates the natural logarithm of the operand
connected to the input parameter.

Parameter Data types Description


IN1 REAL input value
OUT REAL output value

Example
LD REAL#1.0 (*loads 1.0 in accu*)
LN
ST var2 (*stores 0.0 in var2*)

Representation
IL ST FBD

LD IN1 OUT:=LN(IN1);
LN
ST OUT

3-10 5958B
Numerical functions

3.8 LOG

Description This numerical function calculates the logarithm to the base of 10 of the
operand connected to the input parameter.

Parameter Data types Description


IN1 REAL input value
OUT REAL output value

Example
LD REAL#1000.0 (*loads 1000.0 in accu*)
LOG
ST var2 (*stores 3.0 in var2*)

Representation
IL ST FBD

LD IN1 OUT:=LOG(IN1);
LOG
ST OUT

5958B 3-11
PROGRAM WORX

3.9 SIN

Description This numerical function calculates the sine of the operand connected to
the input parameter.

Parameter Data types Description


IN1 REAL input value in radians
OUT REAL output value

Example
LD REAL#3.0 (*loads 3.0 in accu*)
SIN
ST var2 (*stores 0.1411 in var2*)

Representation
IL ST FBD

LD IN1 OUT:=SIN(IN1);
SIN
ST OUT

3-12 5958B
Numerical functions

3.10 SQRT

Description This numerical function calculates the square root of the operand connec-
ted to the input parameter.

Parameter Data types Description


IN1 REAL input value
OUT REAL output value

Example
LD REAL#4.0 (*loads 4.0 in accu*)
SQRT
ST var2 (*stores 2.0 in var2*)

Representation
IL ST FBD

LD IN1 OUT:=SQRT(IN1);
SQRT
ST OUT

5958B 3-13
PROGRAM WORX

3.11 TAN

Description This numerical function calculates the tangent of the operand connected
to the input parameter.

Parameter Data types Description


IN1 REAL input value in radians
OUT REAL output value

Example
LD REAL#1.0 (*loads 1.0 in accu*)
TAN
ST var2 (*stores 1.557 in var2*)

Representation
IL ST FBD

LD IN1 OUT:=TAN(IN1);
TAN
ST OUT

3-14 5958B
Section 4
This section provides information on
– how to use arithmetic functions

Arithmetic functions ..............................................................................................4-3


4.1 ADD.............................................................................................4-4
4.2 ADD_T_T ....................................................................................4-5
4.3 DIV ..............................................................................................4-6
4.4 DIV_T_AN ...................................................................................4-7
4.5 EXPT...........................................................................................4-8
4.6 MOD............................................................................................4-9
4.7 MOVE........................................................................................4-10
4.8 MUL...........................................................................................4-11
4.9 MUL_T_AN ...............................................................................4-12
4.10 NEG ..........................................................................................4-13
4.11 SUB...........................................................................................4-14
4.12 SUB_T_T ..................................................................................4-15

5958B 4-1
4-2 5958B
Arithmetic functions

4 Arithmetic functions
The following arithmetic functions are available:

Table 4-1 Arithmetic functions

Function Short description


ADD Additor for ANY_NUM
ADD_T_T Additor for TIME
DIV Divisor for ANY_NUM
DIV_T_AN Divisor for TIME
EXPT Exponentiation
MOD Modulo divisor
MOVE Assignment
MUL Multiplier for ANY_NUM
MUL_T_AN Multiplier for TIME
NEG Double complement
SUB Subtractor for ANY_NUM
SUB_T_T Subtractor for TIME

5958B 4-3
PROGRAM WORX

4.1 ADD

Description This arithmetic function realizes an addition of the operands connected to


the input parameters.

Parameter Data types Description


IN1 ANY_NUM summand
IN2 ANY_NUM summand
OUT ANY_NUM sum

The input IN2 can be duplicated.


All parameters must have the same data type.

Example
LD 3 (*loads 3 in accu*)
ADD 4 (*adds 4 to accu; stores 7 in accu*)
ST var3 (*stores 7 in var3*)

Representation
IL ST FBD

LD IN1 OUT:=IN1+IN2;
ADD IN2
ST OUT

4-4 5958B
Arithmetic functions

4.2 ADD_T_T

Description This arithmetic function realizes an addition of time values connected to the
input parameters.

Parameter Data types Description


IN1 TIME summand
IN2 TIME summand
OUT TIME sum

Example
LD t#10ms (*loads 10 ms in accu*)
ADD_T_T t#20ms (*adds 20 ms to accu*)
ST var3 (*stores 30 ms in var3*)

Representation
IL ST FBD

LD IN1 OUT:= ADD_T_T(IN1, IN2);


ADD_T_T IN2
ST OUT

5958B 4-5
PROGRAM WORX

4.3 DIV

Description This arithmetic function divides the operand connected to IN1 by the ope-
rand connected to IN2.

Parameter Data types Description


IN1 ANY_NUM dividend
IN2 ANY_NUM divisor
OUT ANY_NUM output value

All parameters must have the same data type.

Example
LD 20 (*loads 20 in accu*)
DIV 4 (*divides accu by 4*)
ST var3 (*stores 5 in var3*)

Representation
IL ST FBD

LD IN1 OUT:=IN1/IN2;
DIV IN2
ST OUT

4-6 5958B
Arithmetic functions

4.4 DIV_T_AN

Description This arithmetic function divides the operand connected to IN1 by the ope-
rand connected to IN2, being both time values.

Parameter Data types Description


IN1 TIME dividend
IN2 ANY_NUM divisor
OUT TIME output value

Example
LD t#30ms (*loads 30 ms in accu*)
DIV_T_AN 3
ST var3 (* stores 10 ms in var3*)

Representation
IL ST FBD

LD IN1 OUT:= DIV_T_AN(IN1,IN2);


DIV_T_AN IN2
ST OUT

5958B 4-7
PROGRAM WORX

4.5 EXPT

Description This arithmetic function realizes an exponentiation.

Parameter Data types Description


IN1 ANY_REAL base
IN2 ANY_INT exponent
OUT ANY_REAL output value

Example
LD REAL#2.0 (*loads 2.0 in accu*)
EXPT 4
ST var3 (*stores 16.0 in var3*)

Representation
IL ST FBD

LD IN1 OUT:=EXPT(IN1,IN2);
EXPT IN2
ST OUT

4-8 5958B
Arithmetic functions

4.6 MOD

Description This arithmetic function divides the operand connected to the input IN1 by
the operand connected to input IN2 and returns the remainder of the divi-
sion at OUT.

Parameter Data types Description


IN1 ANY_INT dividend
IN2 ANY_INT divisor
OUT ANY_INT remainder

All parameters must have the same data type.

Example
LD 15 (*loads 15 in accu*)
MOD 4 (*divides 15 by 4 and stores the remainder*)
ST var3 (*stores 3 in var3*)

Representation
IL ST FBD

LD IN1 OUT:=IN1 MOD IN2;


MOD IN2
ST OUT

5958B 4-9
PROGRAM WORX

4.7 MOVE

Description This arithmetic function moves the value of the operand connected to the
input parameter to the operand connected to the output parameter.

Parameter Data types Description


IN ANY_NUM input value
OUT ANY_NUM output value

All parameters must have the same data type.

Example
LD 4 (*loads 4 in accu*)
MOVE
ST var2 (*stores 4 in var2*)

Representation
IL ST FBD

LD IN OUT:=MOVE(IN);
MOVE
ST OUT

4-10 5958B
Arithmetic functions

4.8 MUL

Description This arithmetic function multiplicates the operands connected to the input
parameters.

Parameter Data types Description


IN1 ANY_NUM first input value
IN2 ANY_NUM second input value
OUT ANY_NUM output value

The input IN2 can be duplicated.


All parameters must have the same data type.

Example
LD 4 (*loads 4 in accu*)
MUL 5 (*multiplicates 4 with 5*)
ST var3 (*stores 20 in var3*)

Representation
IL ST FBD

LD IN1 OUT:= IN1 * IN2;


MUL IN2
ST OUT

5958B 4-11
PROGRAM WORX

4.9 MUL_T_AN

Description This arithmetic function multiplicates a time value.

Parameter Data types Description


IN1 TIME first input value
IN2 ANY_NUM second input value
OUT TIME output value

Example
LD t#10ms (*loads 10 ms in accu*)
MUL_T_AN 3 (*multiplicates 10 ms with 3*)
ST var3 (*stores 30 ms in var3*)

Representation
IL ST FBD

LD IN1 OUT:=MUL_T_AN (IN1,IN2);


MUL_T_AN IN2
ST OUT

4-12 5958B
Arithmetic functions

4.10 NEG

Description This arithmetic function negates the operand connected to the input para-
meter.

Parameter Data types Description


IN1 ANY_NUM input value
OUT ANY_NUM output value

All parameters must have the same data type.

Example
LD 5 (*loads 5 in accu*)
NEG
ST var2 (*stores -5 in var2*)

Representation
IL ST FBD

LD IN1 OUT:=NEG(IN1);
NEG
ST OUT

5958B 4-13
PROGRAM WORX

4.11 SUB

Description This arithmetic function subtracts IN2 from IN1.

Parameter Data types Description


IN1 ANY_NUM minuend
IN2 ANY_NUM subtrahend
OUT ANY_NUM difference

All parameters must have the same data type.

Example
LD 5 (*loads 5 in accu*)
SUB 3 (*subtracts 3*)
ST var3 (stores 2 in var3*)

Representation
IL ST FBD

LD IN1 OUT1:= IN1 - IN2;


SUB IN2
ST OUT

4-14 5958B
Arithmetic functions

4.12 SUB_T_T

Description This arithmetic function subtracts IN2 from IN1, being both time values.

Parameter Data types Description


IN1 TIME minuend
IN2 TIME subtrahend
OUT TIME difference

Example
LD t#30ms (*loads 30 ms in accu*)
SUB_T_T t#10ms (*subtracts 10 ms*)
ST var3 (*stores 20 ms in var3*)

Representation
IL ST FBD

LD IN1 OUT:=SUB_T_T(IN1,IN2);
SUB_T_T IN2
ST OUT

5958B 4-15
PROGRAM WORX

4-16 5958B
Section 5
This section provides information on
– how to use boolean functions

Bitwise Boolean functions.....................................................................................5-3


5.1 AND.............................................................................................5-3
5.2 NOT.............................................................................................5-4
5.3 OR...............................................................................................5-5
5.4 XOR ............................................................................................5-6

5958B 5-1
5-2 5958B
Bitwise Boolean functions

5 Bitwise Boolean functions


The following bitwise Boolean functions are available:

Table 5-1 Bitwise Boolean functions

Function Short description


AND AND connection
NOT Complement
OR OR connection
XOR XOR connection

5.1 AND

Description This bitwise Boolean function realizes a logical AND integration of the ope-
rands connected to the input parameters.

Parameter Data types Description


IN1 ANY_BIT input value
IN2 ANY_BIT input value
OUT ANY_BIT output value

The input IN2 can be duplicated. All parameters can be negated.


All parameters must have the same data type.

Example
LD BYTE#11001100 (*loads 11001100 in accu*)
AND BYTE#10101010 (*realizes logical AND*)
ST var3 (*stores 10001000 in var3*)

5958B 5-3
PROGRAM WORX

Representation
IL ST FBD

LD IN1 OUT:=IN1&IN2;
AND IN2
ST OUT

5.2 NOT

Description This bitwise Boolean function negates bitwise the operand connected to
the input parameter.

Parameter Data types Description


IN1 ANY_BIT input value
OUT ANY_BIT output value

All parameters must have the same data type.

Example
LD BYTE#11001100 (*loads 11001100 in accu*)
NOT
ST var2 (*stores 00110011 in var2*)

Representation
IL ST FBD

LD IN1 OUT:=NOT(IN1);
NOT
ST OUT

5-4 5958B
Bitwise Boolean functions

5.3 OR

Description This bitwise Boolean function realizes a logical OR-integration of the ope-
rands connected to the input parameters.

Parameter Data types Description


IN1 ANY_BIT first input value
IN2 ANY_BIT second input value
OUT ANY_BIT output value

The input IN2 can be duplicated. All parameters can be negated.


All parameters must have the same data type.

Example
LD BYTE#11001100 (*loads 11001100 in accu*)
OR BYTE#10101010 (*realizes logical OR*)
ST var3 (*stores 11101110 in var3*)

Representation
IL ST FBD

LD IN1 OUT:=(IN1)OR(IN2);
OR IN2
ST OUT

5958B 5-5
PROGRAM WORX

5.4 XOR

Description This bitwise Boolean function realizes a logical exclusive-OR-integration of


the operands connected to the input parameters.

Parameter Data types Description


IN1 ANY_BIT first input value
IN2 ANY_BIT second input value
OUT ANY_BIT output value

The input IN2 can be duplicated. All parameters can be negated.


All parameters must have the same data type.

Example
LD BYTE#11001100 (*loads 11001100 in accu*)
XOR BYTE#10101010 (*realizes logical XOR*)
ST var3 (*stores 01100110 in var3*)

Representation
IL ST FBD

LD IN1 OUT:=(IN1)XOR(IN2);
XOR IN2
ST OUT

5-6 5958B
Section 6
This section provides information on
– how to use bit-string functions

Bit-string functions ................................................................................................6-3


6.1 ROL.............................................................................................6-4
6.2 ROL_* .........................................................................................6-5
6.3 ROR ............................................................................................6-6
6.4 ROR_*.........................................................................................6-7
6.5 SHL .............................................................................................6-8
6.6 SHL_*..........................................................................................6-9
6.7 SHR...........................................................................................6-10
6.8 SHR_* .......................................................................................6-11

5958B 6-1
6-2 5958B
Bit-string functions

6 Bit-string functions
The following bit-string functions are available:

Table 6-1 Bit-string functions

Function Short description


ROL Rotate left
ROL_* Rotate left typed
ROR Rotate right
ROR_* Rotate right typed
SHL Shift left
SHL_* Shift left typed
SHR Shift right
SHR_* Shift right typed

5958B 6-3
PROGRAM WORX

6.1 ROL

Description This bit-string function realizes a bitwise left rotation of the operand con-
nected to the input IN. N specifies the number of bits to be rotated.
A bitwise left rotation of 3 bits is shown in the following figure:

Parameter Data types Description

IN ANY_BIT input value

N ANY_INT number of bits to be rotated

OUT ANY_BIT output value

Example
LD BYTE#11001100 (*loads 11001100 in accu*)
ROL 3 (*rotates 3 bits*)
ST var3 (*stores 01100110 in var3*)

Representation
IL ST FBD

LD IN OUT:=ROL(IN,N);
ROL N
ST OUT

6-4 5958B
Bit-string functions

6.2 ROL_*

Description
This bit-string function realizes a bitwise left rotation of the operand con-
nected to the input IN. N specifies the number of bits to be rotated.
A bitwise left rotation of 3 bits is shown in the following figure:

Parameter Data types Description


IN BYTE, WORD, DWORD input value
N INT number of bits to be rotated
OUT BYTE, WORD, DWORD output value

Example
LD BYTE#11001100 (*loads 11001100 in accu*)
ROL_BYTE 3 (*rotates 3 bits*)
ST var3 (*stores 01100110 in var3*)

Representation
IL ST FBD

LD IN OUT:=ROL_*(IN,N); Example for function


ROL_* N ROL_BYTE
ST OUT

For using the function just replace * by the corresponding data type.

5958B 6-5
PROGRAM WORX

6.3 ROR

Description
This bit-string function realizes a bitwise right rotation of the operand con-
nected to the input IN. N specifies the number of bits to be rotated.
A bitwise right rotation of 3 bits is shown in the following figure:

Parameter Data types Description


IN ANY_BIT input value
N ANY_INT number of bits to be rotated
OUT ANY_BIT output value

Example
LD BYTE#11001100 (*loads 11001100 in accu*)
ROR 3 (*rotates 3 bits*)
ST var3 (*stores 10011001 in var3*)

Representation
IL ST FBD

LD IN OUT:=ROR(IN,N);
ROR N
ST OUT

6-6 5958B
Bit-string functions

6.4 ROR_*

Description This bit-string function realizes a bitwise right rotation of the operand con-
nected to the input IN. N specifies the number of bits to be rotated.
A bitwise right rotation of 3 bits is shown in the following figure:

Parameter Data types Description


IN BYTE, WORD, DWORD input value
N INT number of bits to be rotated
OUT BYTE, WORD, DWORD output value

Example
LD BYTE#11001100 (*loads 11001100 in accu*)
ROR_BYTE 3 (*rotates 3 bits*)
ST var3 (*stores 10011001 in var3*)

Representation
IL ST FBD

LD IN OUT:=ROR_*(IN,N); Example for function


ROR_* N
ST OUT

For using the function just replace * by the corresponding data type.

5958B 6-7
PROGRAM WORX

6.5 SHL

Description This bit-string function realizes a bitwise left shifting of the operand connec-
ted to the input IN. N specifies the number of bits to be shifted. The empty
bit positions are filled with zeros.
A bitwise left shifting of 3 bits is shown in the following figure:

Parameter Data types Description


IN ANY_BIT input value
N ANY_INT number of bits to be shifted
OUT ANY_BIT output value

Example
LD BYTE#11001100 (*loads 11001100 in accu*)
SHL 3 (*shifts 3 bits*)
ST var3 (*stores 01100000 in var3*)

Representation
IL ST FBD

LD IN OUT:=SHL(IN,N);
SHL N
ST OUT

6-8 5958B
Bit-string functions

6.6 SHL_*

Description This bit-string function realizes a bitwise left shifting of the operand connec-
ted to the input IN. N specifies the number of bits to be shifted. The empty
bit positions are filled with zeros.
A bitwise left shifting of 3 bits is shown in the following figure:

Parameter Data types Description


IN BYTE, WORD, DWORD input value
N INT number of bits to be shifted
OUT BYTE, WORD, DWORD output value

Example
LD BYTE#11001100 (*loads 11001100 in accu*)
SHL_BYTE 3 (*shifts 3 bits*)
ST var3 (*stores 01100000 in var3*)

Representation
IL ST FBD

LD IN OUT:=SHL_*(IN,N); Example for function


SHL_* N SHL_BYTE
ST OUT

For using the function just replace * by the corresponding data type.

5958B 6-9
PROGRAM WORX

6.7 SHR

Description This bit-string function realizes a bitwise right shifting of the operand con-
nected to the input IN. N specifies the number of bits to be shifted. The
empty bit positions are filled with zeros.
A bitwise right shifting of 3 bits is shown in the following figure:

Parameter Data types Description


IN ANY_BIT input value
N ANY_INT number of bits to be shifted
OUT ANY_BIT output value

Example
LD BYTE#11001100 (*loads 11001100 in accu*)
SHR 3 (*shifts 3 bits*)
ST var3 (*stores 00011001 in var3*)

Representation
IL ST FBD

LD IN OUT:=SHR(IN1,N);
SHR N
ST OUT

6-10 5958B
Bit-string functions

6.8 SHR_*

Description
This bit-string function realizes a bitwise right shifting of the operand con-
nected to the input IN. N specifies the number of bits to be shifted. The
empty bit positions are filled with zeros.
A bitwise right shifting of 3 bits is shown in the following figure:

Parameter Data types Description


IN BYTE, WORD, DWORD input value
N INT number of bits to be shifted
OUT BYTE, WORD, DWORD output value

Example
LD BYTE#11001100 (*loads 11001100 in accu*)
SHR_BYTE 3 (*shifts 3 bits*)
ST var3 (*stores 00011001 in var3*)

Representation
IL ST FBD

LD IN OUT:=SHR_*(IN1,N); Example for function


SHR_* N SHR_BYTE
ST OUT

For using the function just replace * by the corresponding data type.

5958B 6-11
PROGRAM WORX

6-12 5958B
Section 7
This section provides information on
– how to use selection functions

Selection functions................................................................................................7-3
7.1 LIMIT ...........................................................................................7-4
7.2 LIMIT_*........................................................................................7-5
7.3 MAX ............................................................................................7-6
7.4 MAX_* .........................................................................................7-7
7.5 MIN..............................................................................................7-8
7.6 MIN_* ..........................................................................................7-9
7.7 SEL ...........................................................................................7-10
7.8 SEL_* ........................................................................................7-11

5958B 7-1
7-2 5958B
Selection functions

7 Selection functions
The following selection functions are available:

Table 7-1 Selection functions

Function Short description


LIMIT Limitation
LIMIT_* Limitation typed
MAX Maximum
MAX_* Maximum typed
MIN Minimum
MIN_* Minimum typed
SEL Binary selection
SEL_* Binary selection typed

5958B 7-3
PROGRAM WORX

7.1 LIMIT

Description This selection function limits the value of the input parameter IN to the
value sector defined by the input parameters MN (minimum) and MX (ma-
ximum).
If MN <= IN <= MX then OUT = IN.
If IN < MN then OUT = MN.
If IN > MX then OUT = MX.
This overloaded function should be normally used. Only in case of the data
type STRING or if memory problems appeared the typed function should
be used.

Parameter Data types Description


MN ANY_INT minimum limit
IN ANY_INT input value
MX ANY_INT maximum limit
OUT ELEMENTARY output value

All parameters must have the same data type.

Example
LD 8 (*loads 8 in accu*)
LIMIT 6,7 (*checks if 6 is in the limits 8 and 7*)
ST var4 (*stores 7 in var4*)

Representation
IL ST FBD

LD MN OUT:=LIMIT(MN,IN,MX);
LIMIT IN,MX
ST OUT

7-4 5958B
Selection functions

7.2 LIMIT_*

Description This selection function limits the value of the input parameter IN to the
value sector defined by the input parameters MN (minimum) and MX (ma-
ximum).
If MN <= IN <= MX then OUT = IN.
If IN < MN then OUT = MN.
If IN > MX then OUT = MX.
This typed function should only be used in case of the data type STRING
or if memory problems appeared. In all other cases the overloaded function
should be used.

Parameter Data types Description


MN INT, DINT, SINT, REAL, STRING minimum limit
IN INT, DINT, SINT, REAL, STRING input value
MX INT, DINT, SINT, REAL, STRING maximum limit
OUT INT, DINT, SINT, REAL, STRING output value

All parameters must have the same data type.

Example LD 8 (*loads 8 in accu*)


LIMIT_INT 6,7 (*checks if 6 is in the limits 8 and 7*)
ST var4 (*stores 7 in var4*)

Representation
IL ST FBD
Example for function
LD MN OUT:=LIMIT_*(MN,IN,MX); LIMIT_INT
LIMIT_* IN,MX
ST OUT

For using the function just replace * by the corresponding data type.

5958B 7-5
PROGRAM WORX

7.3 MAX

Description This selection function determines the maximal value of the operands con-
nected to the input parameters.
This overloaded function should be normally used. Only in case of the data
type STRING or if memory problems appeared the typed function should
be used.

Parameter Data types Description


IN1 ANY_INT first input value
IN2 ANY_INT second input value
OUT ELEMENTARY output value

All parameters must have the same data type.

Example
LD 4 (*loads 4 in accu*)
MAX 5 (*determines the maximal value*)
ST var3 (*stores 5 in var3*)

Representation
IL ST FBD

LD IN1 OUT:=MAX(IN1,IN2);
MAX IN2
ST OUT

7-6 5958B
Selection functions

7.4 MAX_*

Description This selection function determines the maximal value of the operands con-
nected to the input parameters.
This typed function should only be used in case of the data type STRING
or if memory problems appeared. In all other cases the overloaded function
should be used.

Parameter Data types Description


IN1 INT, DINT, SINT, REAL, STRING first input value
IN2 INT, DINT, SINT, REAL, STRING second input value
OUT INT, DINT, SINT, REAL, STRING output value

All parameters must have the same data type.

Example
LD 4 (*loads 4 in accu*)
MAX_INT 5 (*determines the maximal value*)
ST var3 (*stores 5 in var3*)

Representation
IL ST FBD

LD IN1 OUT:=MAX_*(IN1,IN2); Example for function


MAX_* IN2
ST OUT

For using the function just replace * by the corresponding data type.

5958B 7-7
PROGRAM WORX

7.5 MIN

Description This selection function determines the minimal value of the operands con-
nected to the input parameters.
This overloaded function should be normally used. Only in case of the data
type STRING or if memory problems appeared the typed function should
be used.

Parameter Data types Description


IN1 ANY_INT first input value
IN2 ANY_INT second input value
OUT ELEMENTARY output value

All parameters must have the same data type.

Example
LD 4 (*loads 4 in accu*)
MIN 5 (*determines the minimal value*)
ST var3 (*stores 4 in var3*)

Representation
IL ST FBD

LD IN1 OUT:=MIN(IN1,IN2);
MIN IN2
ST OUT

7-8 5958B
Selection functions

7.6 MIN_*

Description This selection function determines the minimal value of the operands con-
nected to the input parameters.
This typed function should only be used in case of the data type STRING
or if memory problems appeared. In all other cases the overloaded function
should be used.

Parameter Data types Description


IN1 INT, DINT, SINT, REAL, STRING first input value
IN2 INT, DINT, SINT, REAL, STRING second input value
OUT INT, DINT, SINT, REAL, STRING output value

All parameters must have the same data type.

Example
LD 4 (*loads 4 in accu*)
MIN_INT 5 (*determines the minimal value*)
ST var3 (*stores 4 in var3*)

Representation
IL ST FBD

LD IN1 OUT:=MIN_*(IN1,IN2); Example for function


MIN_* IN2
ST OUT

For using the function just replace * by the corresponding data type.

5958B 7-9
PROGRAM WORX

7.7 SEL

Description This selection function selects one of two inputs depending on the value of
the first input G.
If G = FALSE, the value of the input IN0 is allocated to the output OUT.
If G = TRUE, the value of the input IN1 is allocated to the output OUT.
This overloaded function should be normally used. Only in case of the data
type STRING or if memory problems appeared the typed function should
be used.

Parameter Data types Description


G BOOL selecting input
IN0 ANY_INT input value
IN1 ANY_INT input value
OUT ANY output value

The input G can be negated.


IN0, IN1 and OUT must have the same data type.

Example
LD BYTE#10001000 (*loads 10001000 in accu*)
AND BYTE#01110111 (*realizes logical AND*)
SEL BYTE#00000000,BYTE#11111111
ST var4 (*stores 00000000 in var4*)

Representation
IL ST FBD

LD G OUT:=SEL(G,IN0,IN1);
SEL IN0,IN1
ST OUT

7-10 5958B
Selection functions

7.8 SEL_*

Description This selection function selects one of two inputs depending on the value of
the first input G.
If G = FALSE, the value of the input IN0 is allocated to the output OUT.
If G = TRUE, the value of the input IN1 is allocated to the output OUT.
This typed function should only be used in case of the data type STRING
or if memory problems appeared. In all other cases the overloaded function
should be used.

Parameter Data types Description


G BOOL selecting input
IN0 BOOL, BYTE, DINT, INT, SINT, REAL, input value
STRING, WORD, DWORD, TIME
IN1 BOOL, BYTE, DINT, INT, SINT, REAL, input value
STRING, WORD, DWORD, TIME
OUT BOOL, BYTE, DINT, INT, SINT, REAL, output value
STRING, WORD, DWORD, TIME

The input G can be negated.


IN0, IN1 and OUT must have the same data type.

Example
LD BYTE#10001000 (*loads 10001000 in accu*)
AND BYTE#01110111 (*realizes logical AND*)
SEL_BYTE BYTE#00000000,BYTE#11111111
ST var4 (*stores 00000000 in var4*)

5958B 7-11
PROGRAM WORX

Representation
IL ST FBD
Example for function
LD G OUT:=SEL_*(G,IN0,IN1); SEL_BYTE
SEL_* IN0,IN1
ST OUT

For using the function just replace * by the corresponding data type.

7-12 5958B
Section 8
This section provides information on
– how to use comparison functions

Comparison functions ...........................................................................................8-3


8.1 EQ ...............................................................................................8-4
8.2 GE ...............................................................................................8-5
8.3 GT ...............................................................................................8-6
8.4 LE................................................................................................8-7
8.5 LT ................................................................................................8-8
8.6 NE ...............................................................................................8-9

5958B 8-1
8-2 5958B
Comparison functions

8 Comparison functions
The following comparison functions are available:

Table 8-1 Comparison functions

Function Short description


EQ Comparison: =
GE Comparison: >=
GT Comparison: >
LE Comparison: <=
LT Comparison: <
NE Comparison: <>

5958B 8-3
PROGRAM WORX

8.1 EQ

Description This comparison function compares the operands connected to the input
parameters in regard to equality. Comparison proceeds from left to right.

Parameter Data types Description


IN1 ELEMENTARY first input value
IN2 ELEMENTARY second input value
OUT BOOL TRUE if the inputs are equal.
FALSE if the inputs are not equal.

The inputs IN1 and IN2 can be duplicated.


The output OUT can be negated.

Example
LD 4 (*loads 4 in accu*)
EQ 5 (* compares accu with 5*)
ST var3 (*stores FALSE in var3*)

Representation
IL ST FBD

LD IN1 OUT:=IN1=IN2;
EQ IN2
ST OUT

8-4 5958B
Comparison functions

8.2 GE

Description This comparison function compares the operands connected to the input
parameters in regard to greater/equal. Comparison proceeds from left to
right.
The comparison is always a signed comparison. Therefore the values for
DWORD are limited to 31 bit, for WORD to 15 bit and for BYTE to 7 bit.
For string comparison use the corresponding typed function.

Parameter Data types Description


IN1 ELEMENTARY first input value
IN2 ELEMENTARY second input value
OUT BOOL TRUE if IN1 is greater or equal than IN2.
FALSE if IN1 is less than IN2.

– The inputs IN1 and IN2 can be duplicated.


– The output OUT can be negated.
– All inputs must have the same data type.

Example
LD 6 (*loads 6 in accu*)
GE 5 (*compares 5 to the accu*)
ST var3 (*stores FALSE in var3*)

Representation
IL ST FBD

LD IN1 OUT:=IN1>=IN2;
GE IN2
ST OUT

5958B 8-5
PROGRAM WORX

8.3 GT

Description This comparison function compares the operands connected to the input
parameters in regard to greater. Comparison proceeds from left to right.
The comparison is always a signed comparison. Therefore the values for
DWORD are limited to 31 bit, for WORD to 15 bit and for BYTE to 7 bit.
For string comparison use the corresponding typed function.

Parameter Data types Description


IN1 ELEMENTARY first input value
IN2 ELEMENTARY second input value
OUT BOOL TRUE if IN1 is greater than IN2.
FALSE if IN1 is equal or less than IN2.

– The inputs IN1 and IN2 can be duplicated.


– The output OUT can be negated.
– All inputs must have the same data type.

Example
LD 4 (*loads 4 in accu*)
GT 3 (*compares 4 with 3*)
ST var3 (*stores TRUE in var3*)

Representation
IL ST FBD

LD IN1 OUT:=IN1>IN2;
GT IN2
ST OUT

8-6 5958B
Comparison functions

8.4 LE

Description
This comparison function compares the operands connected to the input
parameters in regard to less/equal. Comparison proceeds from left to right.
The comparison is always a signed comparison. Therefore the values for
DWORD are limited to 31 bit, for WORD to 15 bit and for BYTE to 7 bit.
For string comparison use the corresponding typed function.

Parameter Data types Description


IN1 ELEMENTARY first input value
IN2 ELEMENTARY second input value
OUT BOOL TRUE if IN1 is less or equal than IN2.
FALSE if IN1 is greater than IN2.

The output OUT can be negated.

Example
LD 3 (*loads 3 in accu*)
LE 4 (*compares 4 with accu*)
ST var3 (*stores TRUE in var3*)

Representation
IL ST FBD

LD IN1 OUT:=IN1<=IN2;
LE IN2
ST OUT

5958B 8-7
PROGRAM WORX

8.5 LT

Description This comparison function compares the operands connected to the input
parameters in regard to less. Comparison proceeds from left to right.
The comparison is always a signed comparison. Therefore the values for
DWORD are limited to 31 bit, for WORD to 15 bit and for BYTE to 7 bit.
For string comparison use the corresponding typed function.

Parameter Data types Description


IN1 ELEMENTARY first input value
IN2 ELEMENTARY second input value
OUT BOOL TRUE if IN1 is lower than IN2.
FALSE if IN1 is greater or equal than IN2.

The output OUT can be negated.

Example
LD 4 (*loads 4 in accu*)
LT 5 (*compares 5 with 4*)
ST var3 (*stores TRUE in var3*)

Representation
IL ST FBD

LD IN1 OUT:= IN1 < IN2;


LT IN2
ST OUT

8-8 5958B
Comparison functions

8.6 NE

Description This comparison function compares the operands connected to the input
parameters in regard to inequality.

Parameter Data types Description


IN1 ANY_NUM first input value
IN2 ANY_NUM second input value
OUT BOOL TRUE if IN1 and IN2 are not equal.
FALSE if IN1 and IN2 are equal.

The output OUT can be negated.


IN1 and IN2 must have the same data type.

Example
LD 4 (*loads 4 in accu*)
NE 4 (*compares both values*)
ST var3 (*stores TRUE in var3*)

Representation
IL ST FBD

LD IN1 OUT:= IN1 <> IN2;


NE IN2
ST OUT

5958B 8-9
PROGRAM WORX

8-10 5958B
Section 9
This section provides information on
– how to use character string functions

Character string functions.....................................................................................9-3


9.1 *_TO_STRING ............................................................................9-4
9.2 CONCAT .....................................................................................9-7
9.3 DELETE ......................................................................................9-9
9.4 EQ_STRING† ............................................................................9-11
9.5 FIND..........................................................................................9-12
9.6 GE_STRING† ............................................................................9-13
9.7 GT_STRING† ............................................................................9-14
9.8 INSERT .....................................................................................9-15
9.9 LE_STRING†.............................................................................9-17
9.10 LEFT .........................................................................................9-18
9.11 LEN ...........................................................................................9-20
9.12 LT_STRING† .............................................................................9-21
9.13 MID............................................................................................9-22
9.14 NE_STRING† ............................................................................9-24
9.15 REPLACE .................................................................................9-25
9.16 RIGHT .......................................................................................9-27

†. Extended functions going beyond the standard functional range of the


IEC 61131-3.

5958B 9-1
9-2 5958B
Character string functions

9 Character string functions


The following character string functions are available:

Table 9-1 Character string functions

Function Short description


*_TO_STRING Type conversion to STRING
CONCAT Extensible concatenation
DELETE Delete substring
EQ_STRING† Comparison: = for STRING
FIND Find characters
GE_STRING† Comparison: >= for STRING
GT_STRING† Comparison: > for STRING
INSERT Insert characters
LE_STRING† Comparison: <= for STRING
LEFT Leftmost characters
LEN String length
LT_STRING† Comparison: < for STRING
MID Middle characters
NE_STRING† Comparison: <> for STRING
REPLACE Replace characters
RIGHT Rightmost characters
† Extended functions going beyond the standard functional
range of the IEC 61131-3.

5958B 9-3
PROGRAM WORX

9.1 *_TO_STRING

Description This character string function changes the value connected to the input pa-
rameter into the data type STRING.
’*’ is a placeholder for the supported data types. The function is available
for the data types BYTE, DINT, DWORD, INT, REAL, SINT, TIME and
WORD.
A format string can be used to create the text according to special concep-
tions. It may include the conversion instructions. In addition optional para-
meters can be used for the different functions to indicate, how many cha-
racters are put out. These optional parameters are embedded in the
conversion instructions. The following optional parameters are available:

Width This parameter indicates, how many characters are put out at minimal. If
necessary the output is filled up with ’0’ (if a 0 is set before ’width’) or with
white spaces.

Precision This parameter indicates, how many characters are put out at maximal, re-
spectively the amount of significant decimal positions for the data type
REAL.
The optional parameters are embedded in the conversion instruction as fol-
lows:
’%’[width][’.’precision][l]

Parameter Data types Description


IN BYTE, DINT, DWORD, input value
INT, REAL, SINT, TIME,
WORD
FORMAT STRING format string.
’%c’ = ASCII number
’%d’ = decimal integer
’%u’ = unsigned integer
’%x’ = hexadecimal integer
’%e’ = floating point exponential
’%f’ = floating point number
’%l’ = optional parameter
’’ = default values are used
OUT STRING output value

9-4 5958B
Character string functions

The following table contains information about the valid format strings for
the different character string functions. In addition the default strings are li-
sted, which are valid, if an empty string (’’) is connected as format string.

Function Valid format strings Default strings


BYTE_TO_STRING %c, %x, %u '16#lx'
WORD_TO_STRING %u, %x '16#'lx'
DWORD_TO_STRING
SINT_TO_STRING %d '%ld'
INT_TO_STRING
DINT_TO_STRING
REAL_TO_STRING %e, %f '%le'
TIME_TO_STRING %u 'T#%lu ms'

Error reaction and treatment


There is a difference in the error treatment of string errors in the different
PLC versions.
For IPC_28, M68_28 and former versions the following occurs:
– in case of a wrong input a string error results. Subsequently the PLC
will go into the state 'STOP'.
– in case of values which are not within the valid scope of the output data
type an overflow occurs.
The following described error handling is only valid for IPC_30, M68_30
and higher versions.
During value transformation the following errors may occur:
– an illegal format string is used for the function. For example the format
string '%f' is applied to the function INT_TO_STRING.
– no format string is used (for example the string 'conveyor').
In case of an error the output string is cleared. Then it is checked whether
the exception handling is enabled and the error process is started. In this
case a string exception occurs and the SPG 21 is called. Furthermore an
entry is made in the error catalogue including the corresponding module
and the associated line number. The PLC keeps in the state 'RUN'.
The functions *_TO_STRING cause a runtime error if in the format string
the format parameter is directly followed by '.'.

5958B 9-5
PROGRAM WORX

Example
LD BYTE16#FF
BYTE_TO_STRING ’my result is %u!’
ST var3 (*stores ’my result is 255!’ in var3*)

Representation
IL ST

LD IN OUT1:=
*_TO_STRING FORMAT *_TO_STRING(IN,FORMAT);
ST OUT1

FBD

Example for function BYTE_TO_STRING

For using the function just replace * by the corresponding data type.

9-6 5958B
Character string functions

9.2 CONCAT

Description This character string function concatenates the second input string to the
end of the first input string.
It is not possible to use the same string as input and output string. In this
case there should be used an intermediate variable at the output. Than this
intermediate variable has to be assigned to the input variable.

Error reaction and treatment


There is a difference in the error treatment of string errors in the different
PLC versions.
For IPC_28, M68_28 and former versions the following occurs:
– in case of a wrong input a string error results. Subsequently the PLC
will go into the state 'STOP'.
– in case of values which are not within the valid scope of the output data
type an overflow occurs.
The following described error handling is only valid for IPC_30, M68_30
and higher versions.
If the following error conditions become true a string error occurs:
len(IN1) + len(IN2) > maxlen(OUT)
IN2 ==OUT
where 'len(...)' represents the actual string length and 'maxlen(...)' the ma-
ximum string length allowed (maxlen(Default string) = 80).
In case of a wrong input the result variable gets the empty string '' and a
string error occurs. In this case the SPG 21 is called and an entry is made
in the error catalogue including the corresponding module and the associa-
ted line number. The PLC keeps in the state 'RUN'.

Parameter Data types Description


IN1 STRING first input string
IN2 STRING second input string
OUT STRING output string

The function can only be used for IPC_28, M68_28 and higher versions.

5958B 9-7
PROGRAM WORX

Example
LD ’conveyor’ (*loads ’conveyor’ in accu*)
CONCAT ’drive’ (*concatenates ’drive’*)
ST var3 (*stores ’conveyordrive’ in var3*)

Representation
IL ST FBD

LD IN1 OUT:= CONCAT(IN1,IN2);


CONCAT IN2
ST OUT

9-8 5958B
Character string functions

9.3 DELETE

Description This character string function deletes a substring from a given string. L cha-
racters of IN are deleted, beginning at character position P.
P cannot be 0. The first position in a string is 1.

Error reaction and treatment


There is a difference in the error treatment of string errors in the different
PLC versions.
For IPC_28, M68_28 and former versions the following occurs:
– in case of a wrong input a string error results. Subsequently the PLC
will go into the state 'STOP'.
– in case of values which are not within the valid scope of the output data
type an overflow occurs.
The following described error handling is only valid for IPC_30, M68_30
and higher versions.
If the following error conditions become true a string error occurs:
len(IN) - L > maxlen(OUT)
P + L > len(IN)
P<0
where 'len(...)' represents the actual string length and 'maxlen(...)' the ma-
ximum string length allowed (maxlen(Default string) = 80).
In case of a wrong input the result variable gets the empty string '' and a
string error occurs. In this case the SPG 21 is called and an entry is made
in the error catalogue including the corresponding module and the associa-
ted line number. The PLC keeps in the state 'RUN'.

Parameter Data types Description


IN STRING input string
L ANY_INT number of characters to be deleted
P ANY_INT position of the first character to be deleted
OUT STRING output string

The function can only be used for IPC_28, M68_28 and higher versions.

5958B 9-9
PROGRAM WORX

Example
LD ’conveyor’ (*loads ’conveyor’ in accu*)
DELETE 2,4 (*deletes 2 characters at position 4*)
ST var4 (*stores ’conyor’ in var4*)

Representation
IL ST FBD

LD IN OUT:= DELETE(IN,L,P);
DELETE L,P
ST OUT

9-10 5958B
Character string functions

9.4 EQ_STRING

Description This character string function compares the character strings connected to
the input parameters in regard to equality.
Comparison proceeds from left to right. The character ’Z’ is greater than the
character ’A’. Therefore the string ’Z’ is greater than ’AZ’ and ’AZ’ is greater
than ’ABC’.
For the purposes of comparison of two strings of unequal length, the shor-
ter string shall be considered to be extended on the right to the length of
the longer string by characters with the value zero.

Parameter Data types Description


IN1 STRING first input value
IN2 STRING second input value
OUT BOOL TRUE if the inputs are equal.
FALSE if the inputs are not equal.

The output OUT can be negated.

Example
LD ’drive’ (*loads ’drive’ in accu*)
EQ_STRING ’driver’ (*compares accu with ’driver’*)
ST var3 (*stores FALSE in var3*)

Representation
IL ST FBD

LD IN1 OUT:=EQ_STRING(IN1,IN2);
EQ_STRING IN2
ST OUT

5958B 9-11
PROGRAM WORX

9.5 FIND

Description This character string function detects the position of a substring IN2 within
a given string IN1. The character position of the first occurrence of IN2 in
IN1 is stored to OUT.
If no occurrence of IN2 is found, then OUT := 0.
The first position in a string is 1.

Parameter Data types Description


IN1 STRING input string
IN2 STRING substring to be found
OUT INT character position of the first occurrence of
the substring

The function can only be used for IPC_28, M68_28 and higher versions.

Example
LD ’conveyor’ (*loads ’conveyor’ in accu*)
FIND ’ve’ (*find ’ve’ within ’conveyor’*)
ST var3 (*stores 4 in var3*)

Representation
IL ST FBD

LD IN1 OUT:= FIND(IN1,IN2);


FIND IN2
ST OUT

9-12 5958B
Character string functions

9.6 GE_STRING

Description This character string function compares the character strings connected to
the input parameters in regard to greater/equal.
Comparison proceeds from left to right. The character ’Z’ is greater than the
character ’A’. Therefore the string ’Z’ is greater than ’AZ’ and ’AZ’ is greater
than ’ABC’.
For the purposes of comparison of two strings of unequal length, the shor-
ter string shall be considered to be extended on the right to the length of
the longer string by characters with the value zero.

Parameter Data types Description


IN1 STRING first input value
IN2 STRING second input value
OUT BOOL TRUE if IN1 is greater or equal than IN2.
FALSE if IN1 is less than IN2.

The output OUT can be negated.

Example
LD ’input_1’ (*loads ’input_1’ in accu*)
GE_STRING ’input_2’ (*compares ’input_2’ to the accu*)
ST var3 (*stores FALSE in var3*)

Representation
IL ST FBD

LD IN1 OUT:=GE_STRING(IN1,IN2);
GE_STRING IN2
ST OUT

5958B 9-13
PROGRAM WORX

9.7 GT_STRING

Description This character string function compares the character strings connected to
the input parameters in regard to greater.
Comparison proceeds from left to right. The character ’Z’ is greater than the
character ’A’. Therefore the string ’Z’ is greater than ’AZ’ and ’AZ’ is greater
than ’ABC’.
For the purposes of comparison of two strings of unequal length, the shor-
ter string shall be considered to be extended on the right to the length of
the longer string by characters with the value zero.

Parameter Data types Description


IN1 STRING first input value
IN2 STRING second input value
OUT BOOL TRUE if IN1 is greater than IN2.
FALSE if IN1 is equal or less than IN2.

The output OUT can be negated.

Example
LD ’input_1’ (*loads ’input_1’ in accu*)
GT_STRING ’input_2’ (*compares ’input_2’ to the accu*)
ST var3 (*stores FALSE in var3*)

Representation
IL ST FBD

LD IN1 OUT:=GT_STRING(IN1,IN2);
GT_STRING IN2
ST OUT

9-14 5958B
Character string functions

9.8 INSERT

Description This character string function inserts a string IN2 in a given string IN1. IN2
is inserted in IN1 after character position P.
P cannot be 0. The first position in a string is 1. If you want to insert a string
before another use the function CONCAT.
It is not possible to use the same string as input and output string. In this
case there should be used an intermediate variable at the output. Than this
intermediate variable has to be assigned to the input variable.

Error reaction and treatment


There is a difference in the error treatment of string errors in the different
PLC versions.
For IPC_28, M68_28 and former versions the following occurs:
– in case of a wrong input a string error results. Subsequently the PLC
will go into the state 'STOP'.
– in case of values which are not within the valid scope of the output data
type an overflow occurs.
The following described error handling is only valid for IPC_30, M68_30
and higher versions.
If the following error conditions become true a string error occurs:
len(IN1) + len(IN2) > maxlen(OUT)
P<0
P > len(IN1)
IN2 == OUT
where 'len(...)' represents the actual string length and 'maxlen(...)' the ma-
ximum string length allowed (maxlen(Default string) = 80).
In case of a wrong input the result variable gets the empty string '' and a
string error occurs. In this case the SPG 21 is called and an entry is made
in the error catalogue including the corresponding module and the associa-
ted line number. The PLC keeps in the state 'RUN'.

5958B 9-15
PROGRAM WORX

Parameter Data types Description


IN1 STRING input string
IN2 STRING second string to be inserted in IN1
P ANY_INT character position where string IN2 is
inserted
OUT STRING output string

The function can only be used for IPC_28, M68_28 and higher versions.

Example
LD ’conveyor’ (*loads ’conveyor’ in accu*)
INSERT ’ve’,5 (*inserts ’ve’ behind e*)
ST var3 (*stores ’conveveyor’ in var3*)

Representation
IL ST FBD

LD IN1 OUT:= INSERT(IN1,IN2,P);


INSERT IN2,P
ST OUT

9-16 5958B
Character string functions

9.9 LE_STRING

Description This character string function compares the character strings connected to
the input parameters in regard to less/equal.
Comparison proceeds from left to right. The character ’Z’ is greater than the
character ’A’. Therefore the string ’Z’ is greater than ’AZ’ and ’AZ’ is greater
than ’ABC’.
For the purposes of comparison of two strings of unequal length, the shor-
ter string shall be considered to be extended on the right to the length of
the longer string by characters with the value zero.

Parameter Data types Description


IN1 STRING first input value
IN2 STRING second input value
OUT BOOL TRUE if IN1 is less or equal than IN2.
FALSE if IN1 is greater than IN2.

The output OUT can be negated.

Example
LD ’input_1’ (*loads ’input_1’ in accu*)
LE_STRING ’input_2’ (*compares ’input_2’ with accu*)
ST var3 (*stores TRUE in var3*)

Representation
IL ST FBD

LD IN1 OUT:=LE_STRING(IN1,IN2);
LE_STRING IN2
ST OUT

5958B 9-17
PROGRAM WORX

9.10 LEFT

Description This character string function extracts the leftmost characters of a string IN.
L specifies the number of characters to be extracted from IN.

Error reaction and treatment


There is a difference in the error treatment of string errors in the different
PLC versions.
For IPC_28, M68_28 and former versions the following occurs:
– in case of a wrong input a string error results. Subsequently the PLC
will go into the state 'STOP'.
– in case of values which are not within the valid scope of the output data
type an overflow occurs.
The following described error handling is only valid for IPC_30, M68_30
and higher versions.
If the following error conditions become true a string error occurs:
L > len(IN)
L > maxlen(OUT)
where 'len(IN)' represents the actual string length and 'maxlen(OUT)' the
maximum string length allowed (maxlen(Default string) = 80).
In case of a wrong input the result variable gets the empty string '' and a
string error occurs. In this case the SPG 21 is called and an entry is made
in the error catalogue including the corresponding module and the associa-
ted line number. The PLC keeps in the state 'RUN'.

Parameter Data types Description


IN STRING input string
L ANY_INT number of characters to be extracted
OUT STRING output string

The function can only be used for IPC_28, M68_28 and higher versions.

9-18 5958B
Character string functions

Example
LD ’conveyor’ (*loads ’conveyor’ in accu*)
LEFT 3 (*extracts 3 leftmost characters*)
ST var3 (*stores ’con’ in var3*)

Representation
IL ST FBD

LD IN OUT:= LEFT(IN, L);


LEFT L
ST OUT

5958B 9-19
PROGRAM WORX

9.11 LEN

Description This character string function determines the length of a string.

Parameter Data types Description


IN1 STRING input string
OUT INT length of string IN1

The function can only be used for IPC_28, M68_28 and higher versions.

Example
LD ’conveyor’ (*loads ’conveyor’ in accu*)
LEN
ST var2 (*stores 8 in var2*)

Representation
IL ST FBD

LD IN1 OUT:= LEN(IN1);


LEN
ST OUT

9-20 5958B
Character string functions

9.12 LT_STRING

Description This character string function compares the character strings connected to
the input parameters in regard to less.
Comparison proceeds from left to right. The character ’Z’ is greater than the
character ’A’. Therefore the string ’Z’ is greater than ’AZ’ and ’AZ’ is greater
than ’ABC’.
For the purposes of comparison of two strings of unequal length, the shor-
ter string shall be considered to be extended on the right to the length of
the longer string by characters with the value zero.

Parameter Data types Description


IN1 STRING first input value
IN2 STRING second input value
OUT BOOL TRUE if IN1 is lower than IN2.
FALSE if IN1 is greater or equal than IN2.

The output OUT can be negated.

Example
LD ’abc’ (*loads ’abc’ in accu*)
LT_STRING ’bcd’ (*compares ’bcd’ with accu*)
ST var3 (*stores TRUE in var3*)

Representation
IL ST FBD

LD IN1 OUT:=LT_STRING(IN1,IN2);
LT_STRING IN2
ST OUT

5958B 9-21
PROGRAM WORX

9.13 MID

Description This character string function extracts a substring from the middle of a
string. L characters of IN are extracted, beginning at character position P.
P cannot be 0. The first position in a string is 1.
It is not possible to use the same string as input and output string. In this
case there should be used an intermediate variable at the output. Than this
intermediate variable has to be assigned to the input variable.

Error reaction and treatment


There is a difference in the error treatment of string errors in the different
PLC versions.
For IPC_28, M68_28 and former versions the following occurs:
– in case of a wrong input a string error results. Subsequently the PLC
will go into the state 'STOP'.
– in case of values which are not within the valid scope of the output data
type an overflow occurs.
The following described error handling is only valid for IPC_30, M68_30
and higher versions.
If the following error conditions become true a string error occurs:
L > maxlen(OUT)
P<0
P+L > len(IN)
where 'len(IN)' represents the actual string length and 'maxlen(OUT)' the
maximum string length allowed (maxlen(Default string) = 80).
In case of a wrong input the result variable gets the empty string '' and a
string error occurs. In this case the SPG 21 is called and an entry is made
in the error catalogue including the corresponding module and the associa-
ted line number. The PLC keeps in the state 'RUN'.

9-22 5958B
Character string functions

Parameter Data types Description


IN STRING input string
L ANY_INT number of characters to be extracted
P ANY_INT position of the first character to be extracted
OUT STRING output string

The function can only be used for IPC_28, M68_28 and higher versions.

Example
LD ’conveyor’ (*loads ’conveyor’ in accu*)
MID 3,4 (*extracts 3 characters beginning at position 4*)
ST var4 (*stores ’vey’ in var4*)

Representation
IL ST FBD

LD IN OUT:= MID(IN,L,P);
MID L,P
ST OUT

5958B 9-23
PROGRAM WORX

9.14 NE_STRING

Description This character string function compares the character strings connected to
the input parameters in regard to inequality.
Comparison proceeds from left to right. The character ’Z’ is greater than the
character ’A’. Therefore the string ’Z’ is greater than ’AZ’ and ’AZ’ is greater
than ’ABC’.
For the purposes of comparison of two strings of unequal length, the shor-
ter string shall be considered to be extended on the right to the length of
the longer string by characters with the value zero.

Parameter Data types Description


IN1 STRING first input value
IN2 STRING second input value
OUT BOOL TRUE if IN1 and IN2 are not equal.
FALSE if IN1 and IN2 are equal.

The output OUT can be negated.

Example
LD ’abc’ (*loads ’abc’ in accu*)
NE_STRING ’bcd’ (*compares ’bcd’ with accu*)
ST var3 (*stores TRUE in var3*)

Representation
IL ST FBD

LD IN1 OUT:=NE_STRING (IN1,IN2);


NE_STRING IN2
ST OUT

9-24 5958B
Character string functions

9.15 REPLACE

Description This character string function replaces a substring in a string by another. L


characters of IN1 are replaced by IN2, starting at character position P.
P cannot be 0. The first position in a string is 1.
It is not possible to use the same string as input and output string. In this
case there should be used an intermediate variable at the output. Than this
intermediate variable has to be assigned to the input variable.

Error reaction and treatment


There is a difference in the error treatment of string errors in the different
PLC versions.
For IPC_28, M68_28 and former versions the following occurs:
– in case of a wrong input a string error results. Subsequently the PLC
will go into the state 'STOP'.
– in case of values which are not within the valid scope of the output data
type an overflow occurs.
The following described error handling is only valid for IPC_30, M68_30
and higher versions.
If the following error conditions become true a string error occurs:
len(IN1) - L + len(IN2) > maxlen(OUT)
IN2 == OUT
P + L > len(IN1)
P<0
where 'len(...)' represents the actual string length and 'maxlen(...)' the ma-
ximum string length allowed (maxlen(Default string) = 80).
In case of a wrong input the result variable gets the empty string '' and a
string error occurs. In this case the SPG 21 is called and an entry is made
in the error catalogue including the corresponding module and the associa-
ted line number. The PLC keeps in the state 'RUN'.

5958B 9-25
PROGRAM WORX

Parameter Data types Description


IN1 STRING input string
IN2 STRING substring for replacing
L ANY_INT number of characters to be replaced
P ANY_INT position of the first character to be replaced
OUT STRING output string

The function can only be used for IPC_28, M68_28 and higher versions.

Example
LD ’conveyor’ (*loads ’conveyor’ in accu*)
REPLACE ’mut’,3,4 (*replaces ’vey’ by ’mut’*)
ST var5 (*stores ’conmutor’ in var5*)

Representation
IL ST FBD

LD IN1 OUT:=
REPLACE IN2,L,P REPLACE(IN1,IN2,L,P);
ST OUT

9-26 5958B
Character string functions

9.16 RIGHT

Description This character string function extracts the rightmost characters of a string
IN. L specifies the number of characters to be extracted from IN.

Error reaction and treatment


There is a difference in the error treatment of string errors in the different
PLC versions.
For IPC_28, M68_28 and former versions the following occurs:
– in case of a wrong input a string error results. Subsequently the PLC
will go into the state 'STOP'.
– in case of values which are not within the valid scope of the output data
type an overflow occurs.
The following described error handling is only valid for IPC_30, M68_30
and higher versions.
If the following error conditions become true a string error occurs:
L > len(IN)
L > maxlen(OUT)
where 'len(IN)' represents the actual string length and 'maxlen(OUT)' the
maximum string length allowed (maxlen(Default string) = 80).
In case of a wrong input the result variable gets the empty string '' and a
string error occurs. In this case the SPG 21 is called and an entry is made
in the error catalogue including the corresponding module and the associa-
ted line number. The PLC keeps in the state 'RUN'.

Parameter Data types Description


IN STRING input string
L ANY_INT number of characters to be extracted
OUT STRING output string

The function can only be used for IPC_28, M68_28 and higher versions.

5958B 9-27
PROGRAM WORX

Example
LD ’conveyor’ (*loads ’conveyor’ in accu*)
RIGHT 3 (*extracts 3 rightmost characters*)
ST var3 (*stores ’yor’ in var3*)

Representation
IL ST FBD

LD IN OUT:= RIGHT(IN,L);
RIGHT L
ST OUT

9-28 5958B
Section 10
This section provides information on
– how to use bistable function blocks

Bistable function blocks ......................................................................................10-3


10.1 SR .............................................................................................10-3
10.2 RS .............................................................................................10-5

5958B 10-1
10-2 5958B
Bistable function blocks

10 Bistable function blocks


The following bistable function blocks or elements are available:

Table 10-1 Bistable function blocks

Function block Short description


SR Set dominant
RS Reset dominant

10.1 SR

Description This bistable function block realizes a prior set of the output Q1. If the input
SET1 = TRUE, the output Q1 is set. Q1 remains set even if SET becomes
FALSE. Q1 is reset, if RESET = TRUE. If both inputs = TRUE, the output
Q1 is set by SET1 to TRUE.
If the function block is called for the first time, Q1 is FALSE.

Parameter Data types Description


SET1 BOOL IF TRUE Q1 is set dominant
RESET BOOL If TRUE Q1 is reset
Q1 BOOL output

All parameters can be negated.

Example

5958B 10-3
PROGRAM WORX

Variables VAR
declaration
var1 : BOOL;
var2 : BOOL;
var3 : BOOL;
SR_1 : SR;
END_VAR
Function blocks have to be instantiated. The instance name can be any
name of your choice. It must be unique within the POU. In the example the
instance name ’SR_1’ is used.

Representation
IL ST

LD var1 SR_1(SET1:=var1,RESET:=var2);
ST SR_1.SET1 var3:= SR_1.Q1;
LD var2
ST SR_1.RESET
CAL SR_1
LD SR_1.Q1
ST var3

FBD

10-4 5958B
Bistable function blocks

10.2 RS

Description This bistable function block realizes a prior reset of the output Q1. If the
input SET = TRUE, the output Q1 is set. Q1 remains set even if SET beco-
mes FALSE. Q1 is reset, if RESET1 = TRUE. If both inputs = TRUE, the
output Q1 is set by RESET1 to FALSE.
If the function block is called for the first time, Q1 is FALSE.

Parameter Data types Description


SET BOOL IF TRUE Q1 is set
RESET1 BOOL IF TRUE Q1 is reset dominant
Q1 BOOL output value

All parameters can be negated.

Example

Variables VAR
declaration
var1 : BOOL;
var2 : BOOL;
var3 : BOOL;
RS_1 : RS;
END_VAR
Function blocks have to be instantiated. The instance name can be any
name of your choice. It must be unique within the POU. In the example the
instance name ’RS_1’ is used.

5958B 10-5
PROGRAM WORX

Representation
IL ST

LD var1 RS_1(SET:=var1,RESET1:=var2);
ST RS_1.SET var3:= RS_1.Q1;
LD ar2
ST RS_1.RESET1
CAL RS_1
LD RS_1.Q1
ST var3

FBD

10-6 5958B
Section 11
This section provides information on
– how to use edge detection function blocks

Edge detection function blocks ...........................................................................11-3


11.1 F_TRIG .....................................................................................11-3
11.2 R_TRIG .....................................................................................11-5

5958B 11-1
11-2 5958B
Edge detection function blocks

11 Edge detection function blocks


The following edge detection function blocks are available:

Table 11-1 Edge detection function blocks

Function block Short description


F_TRIG Falling edge detector
R_TRIG Rising edge detector

11.1 F_TRIG

Description This edge detection function block detects a falling edge. If a falling edge
is detected at the input CLK, the output Q changes from FALSE to TRUE
or vice versa. Q remains until the program cycle is done.
If the function block is called for the first time, Q is FALSE until the first edge
is detected.

Parameter Data types Description


CLK BOOL detects a falling edge
Q BOOL If a falling edge is detected, Q changes
from FALSE to TRUE

Example

5958B 11-3
PROGRAM WORX

Variables VAR
declaration
var1 : BOOL;
var2 : BOOL;
F_TRIG_1 : F_TRIG;
END_VAR
Function blocks have to be instantiated. The instance name can be any
name of your choice. It must be unique within the POU. In the example the
instance name ’F_TRIG_1’ is used.

Representation
IL ST FBD

LD var1
F_TRIG_1(CLK:= var1);
ST F_TRIG_1.CLK
var2:= F_TRIG_1.Q;
CAL F_TRIG_1
LD F_TRIG_1.Q
ST var2

11-4 5958B
Edge detection function blocks

11.2 R_TRIG

Description This edge detection function block detects a rising edge. If a rising edge is
detected at the input CLK, the output Q changes from FALSE to TRUE or
vice versa. Q remains until the program cycle is done.
If the function block is called for the first time, Q is FALSE until the first edge
is detected.

Parameter Data types Description


CLK BOOL detects a rising edge
Q BOOL If a rising edge is detected, Q changes
from FALSE to TRUE

Example

Variables VAR
declaration
var1 : BOOL;
var2 : BOOL;
R_TRIG_1 : R_TRIG;
END_VAR
Function blocks have to be instantiated. The instance name can be any
name of your choice. It must be unique within the POU. In the example the
instance name ’R_TRIG_1’ is used.

5958B 11-5
PROGRAM WORX

Representation
IL ST FBD

LD var1 R_TRIG_1(CLK:=var1);
ST R_TRIG_1.CLK var2:= R_TRIG_1.Q
CAL R_TRIG_1
LD R_TRIG_1.Q
ST var2

11-6 5958B
Section 12
This section provides information on
– how to use counter function blocks

Counter function blocks ......................................................................................12-3


12.1 CTU...........................................................................................12-3
12.2 CTD...........................................................................................12-5
12.3 CTUD ........................................................................................12-7

5958B 12-1
12-2 5958B
Counter function blocks

12 Counter function blocks


The following counter function blocks are available:

Table 12-1 Counter function blocks

Function block Short description


CTU Up-counter
CTD Down-counter
CTUD Up-down-counter

12.1 CTU

Description This counter function block counts up. In case of a rising edge at the input
CU and RESET = FALSE, CV is increased by one. If the final value of the
counter (PV) is achieved, TRUE is issued at the output Q and the function
block stopps counting.
If RESET = TRUE, the counter is initialized with 0. To enable the counting
process, the input RESET must be FALSE. Otherwise the counter will al-
ways be re-initialized.

Parameter Data types Description


CU BOOL If a rising edge is detected, CV is
increased by one
RESET BOOL If TRUE, the counter is initialized with 0
If FALSE, counting is enabled
PV INT preset value
Q BOOL TRUE if CV = PV
CV INT counter result
(retentive)

The output Q can be negated.


The counter result is stored in the retentive area.

5958B 12-3
PROGRAM WORX

Example

Variables VAR
declaration
var1 : BOOL;
var2 : BOOL;
var3 : INT;
var4 : BOOL;
var5 : INT;
CTU_1 : CTU;
END_VAR
Function blocks have to be instantiated. The instance name can be any
name of your choice. It must be unique within the POU. In the example the
instance name ’CTU_1’ is used.

Representation
IL ST FBD

LD var1 CTU_1(CU:= var1,


ST CTU_1.CU RESET:= var2,PV:= var3);
LD var2 var4:= CTU_1.Q;
ST CTU_1.RESET var5:= CTU_1.CV;
LD var3
ST CTU_1.PV
CAL CTU_1
LD CTU_1.Q
ST var4
LD CTU_1.CV
ST var5

12-4 5958B
Counter function blocks

12.2 CTD

Description This counter function block counts down. In case of a rising edge at the
input CD and LOAD = FALSE, CV decrements by one. If the final value of
the counter (0) is achieved, TRUE is issued at the output Q and the function
block stopps counting.
If LOAD = TRUE, the counter is initialized by the value of the input PV. To
enable the counting process, the input LOAD must be FALSE. Otherwise
the counter will always be re-initialized.

Parameter Data types Description


CD BOOL If a rising edge is detected, CV decre-
ments by one.
LOAD BOOL If TRUE, the counter is initialized with PV.
If FALSE, counting is enabled.
PV INT preset value
Q BOOL TRUE if CV = 0
CV INT counter result
(retentive)

The output Q can be negated.


The counter result is stored in the retentive area.

Example

5958B 12-5
PROGRAM WORX

Variables VAR
declaration
var1 : BOOL;
var2 : BOOL;
var3 : INT;
var4 : BOOL;
var5 : INT;
CTD_1 : CTD;
END_VAR
Function blocks have to be instantiated. The instance name can be any
name of your choice. It must be unique within the POU. In the example the
instance name ’CTD_1’ is used.

Representation
IL ST FBD

LD var1 CTD_1(CD:=var1,
ST CTD_1.CD LOAD:=var2,PV:=var3);
LD var2 var4:= CTD_1.Q;
ST CTD_1.LOAD var5:=CTD_1.CV;
LD var3
ST CTD_1.PV
CAL CTD_1
LD CTD_1.Q
ST var4
LD CTD_1.CV
ST var5

12-6 5958B
Counter function blocks

12.3 CTUD

Description This counter function block counts up or down. In case of a rising edge at
the input CU, CV is increased by one. In case of a rising edge at the input
CD, CV decrements by one. If CV = PV, TRUE is issued at the output QU.
If CV = 0, TRUE is issued at the output QD.
If the input RESET = TRUE, the counter is initialized with 0. If the input
LOAD = TRUE, the counter is initialized with PV. To enable the counting
process, the inputs RESET and LOAD must be FALSE. Otherwise the
counter will always be re-initialized.

Parameter Data types Description


CU BOOL If a rising edge is detected, CV is increased
by one.
CD BOOL If a rising edge is detected, CV decrements
by one.
RESET BOOL If TRUE the counter is initialized with 0.
If FALSE counting is enabled.
LOAD BOOL If TRUE the counter is initialized with PV.
If FALSE counting is enabled.
PV INT preset value
QU BOOL TRUE if CV = PV
QD BOOL TRUE if CV = 0
CV INT counter result (retentive)

The outputs QU and QD can be negated.


The counter result is stored in the retentive area.

Example

5958B 12-7
PROGRAM WORX

Variables VAR
declaration
var1 : BOOL;
var2 : BOOL;
var3 : BOOL;
var4 : BOOL;
var5 : INT;
var6 : BOOL;
var7 : BOOL;
var8 : INT;
CTUD_1 : CTUD;
END_VAR
Function blocks have to be instantiated. The instance name can be any
name of your choice. It must be unique within the POU. In the example the
instance name ’CTUD_1’ is used.

Representation
IL ST FBD

LD var1 CTUD_1(CU:= var,


ST CTUD_1.CU CD:= var1,
LD var2 RESET:= var3,
ST CTUD_1.CD LOAD:= var4,
LD var3 PV:= var5);
ST CTUD_1.RESET var6:= CTUD_1.QU;
LD var4 var7:= CTUD_1.QD;
ST CTUD_1.LOAD var8:= CTUD_1.CV;
LD var5
ST CTUD_1.PV
CAL CTUD_1
LD CTUD_1.QU
ST var6
LD CTUD_1.QD
ST var7
LD CTUD_1CV
ST var8

12-8 5958B
Section 13
This section provides information on
– how to use timer function blocks

Timer function blocks..........................................................................................13-3


13.1 TP..............................................................................................13-3
13.2 TP_R .........................................................................................13-5
13.3 TON...........................................................................................13-8
13.4 TON_R ....................................................................................13-10
13.5 TOF .........................................................................................13-13
13.6 TOF_R ....................................................................................13-15

5958B 13-1
13-2 5958B
Timer function blocks

13 Timer function blocks


The following timer function blocks are available:

Table 13-1 Timer function blocks

Function block Short description


TP Pulse
TP_R Pulse
TON On-delay timer
TON_R On-delay timer
TOF Off-delay timer
TOF_R Off-delay timer

13.1 TP

Description This timer function block creates a pulse.


If the input IN changes from FALSE to TRUE, a pulse is created at output
Q for the time interval PT. The time which has already elapsed is indicated
at the output ET. If IN gets TRUE for another time and PT has not been
elapsed, it has no impact on the duration of the pulse created at output Q.

Parameter Data types Description


IN BOOL If a rising edge is detected, a pulse is crea-
ted.
PT TIME preset time interval for the pulse
Q BOOL TRUE if IN = TRUE and ET < PT
FALSE if IN = FALSE and ET >= PT
ET TIME elapsed time interval

The input IN and the output Q can be negated.

5958B 13-3
PROGRAM WORX

Time diagram

Example

Variables VAR
declaration
var1 : BOOL;
var2 : TIME;
var3 : BOOL;
var4 : TIME;
TP_1 : TP;
END_VAR
Function blocks have to be instantiated. The instance name can be any
name of your choice. It must be unique within the POU. In the example the
instance name ’TP_1’ is used.

13-4 5958B
Timer function blocks

Representation
IL ST FBD

LD var1
TP_1(IN:=var1,PT:=var2);
ST TP_1.IN
LD var2 var3:= TP_1.Q;
ST TP_1.PT var4:= TP_1.ET;
CAL TP_1
LD TP_1.Q
ST var3
LD TP_1.ET
ST var4

13.2 TP_R

This function block has the same function as function block TP.
The elapsed time interval however, is stored in the retentive area.

Description This timer function block creates a pulse. It operates as retain timer, i.e. the
timer continues after a warm start occurs.
If the input IN changes from FALSE to TRUE, a pulse is created at output
Q for the time interval PT. The time which has already elapsed is indicated
at the output ET. If IN gets TRUE for another time and PT has not been
elapsed, it has no impact on the duration of the pulse created at output Q.

Parameter Data types Description


IN BOOL If a rising edge is detected, a pulse is crea-
ted.
PT TIME preset time interval for the pulse
Q BOOL TRUE if IN = TRUE and ET < PT
FALSE if IN = FALSE and ET >= PT
ET TIME elapsed time interval

The input IN and the output Q can be negated.

5958B 13-5
PROGRAM WORX

Algorithm
The algorithm is based on incrementing time distances between two invo-
cations of the function block. This function block is capable to calculate the
elapsed time after a warm restart beginning from the last invocation. The
time distance is measured by using the internal ProConOS system tick
counter located at the system flag area %MD 1.52. To get a ’normalized’
time base in millisecond, the internal flag %MW 1.44 is used to convert
timer ticks into millisecond. The preset timer value is limited at
2.147.483.647 milliseconds, which is caused by the maximum range of the
DINT data type.

Problem of lost invocation after warm restart


Because the algorithm is based on a non retentive internal system tick
counter, it is important to take notice of the problem, which we call ’lost in-
vocation’. The figure below describes the behavior of the function block be-
fore and after a warm start is forced. After the IN parameter raised to
TRUE, the next invocation detects the raising edge state of IN. At this point
the calculation begins with ET (elapsed time) := 0. After a warm restart, the
next invocation detects the changed state and normalize the internal start
value by subtracting the current system counter with the internal retentive
elapsed counter. That is why, the time distance to the previous invocation
is 0. Related to the ’real’ elapsed time there is a delay dependent from the
duration between successive invocations of TP_R. That means, after a
warm start the duration of a TP_R function block is at worst one invocation
distance slower than a TP_R where no warm restart occurs.

13-6 5958B
Timer function blocks

Hot start behavior


After a hot start is performed , it is important to know, that the timer calcu-
lates the elapsed time including the duration of the stop state. A hot start is
forced e.g. if the PLC is continued from a breakpoint. During the online de-
bug, it could happen that some timer expire if the PLC halts on breakpoints.

Example

Variables VAR
declaration var1 : BOOL;
var2 : TIME;
var3 : BOOL;
var4 : TIME;
TP_R_1 : TP_R;
END_VAR

Function blocks have to be instantiated. The instance name can be any


name of your choice. It must be unique within the POU. In the example the
instance name ’TP_R_1’ is used.

Representation
IL ST FBD

LD var1 TP_R_1(IN:=var1,PT:=var2);
ST TP_R_1.IN var3:= TP_R_1.Q;
LD var2 var4:= TP_R_1.ET;
ST TP_R_1.PT
CAL TP_R_1
LD TP_R_1.Q
ST var3
LD TP_R_1.ET
ST var4

5958B 13-7
PROGRAM WORX

13.3 TON

Description This timer function block realizes an on-delay timing.


If the input IN changes from FALSE to TRUE, switching on is delayed for
the time interval at input PT. After PT has passed, TRUE is issued at the
output Q. The time which has already elapsed is indicated at the output ET.

Parameter Data types Description


IN BOOL If a rising edge is detected, the on-delay ti-
ming is started.
PT TIME preset time interval for the delay
Q BOOL TRUE if IN = TRUE and ET < PT
FALSE if IN = FALSE and ET >= PT
ET TIME elapsed time interval

The input IN and the output Q can be negated.

Time diagram

Example

13-8 5958B
Timer function blocks

Variables VAR
declaration
var1 : BOOL;
var2 : TIME;
var3 : BOOL;
var4 : TIME;
TON_1 : TON;
END_VAR
Function blocks have to be instantiated. The instance name can be any
name of your choice. It must be unique within the POU. In the example the
instance name ’TON_1’ is used.

Representation
IL ST FBD

LD var1 TON_1(IN:=var1,PT:=var2);
ST TON_1.IN var3:= TON_1.Q;
LD var2 var4:= TON_1.ET;
ST TON_1.PT
CAL TON_1
LD TON_1.Q
ST var3
LD TON_1.ET
ST var4

5958B 13-9
PROGRAM WORX

13.4 TON_R

This function block has the same function as function block TON.
The elapsed time interval however, is stored in the retentive area.

Description This timer function block realizes an on-delay timing. It operates as retain
timer, i.e. the timer continues after a warm start occurs.
If the input IN changes from FALSE to TRUE, switching on is delayed for
the time interval at input PT. After PT has passed, TRUE is issued at the
output Q. The time which has already elapsed is indicated at the output ET.

Parameter Data types Description


IN BOOL If a rising edge is detected, the on-delay ti-
ming is started.
PT TIME preset time interval for the delay
Q BOOL TRUE if IN = TRUE and ET < PT
FALSE if IN = FALSE and ET >= PT
ET TIME elapsed time interval

The input IN and the output Q can be negated.

Algorithm
The algorithm is based on incrementing time distances between two invo-
cations of the function block. This function block is capable to calculate the
elapsed time after a warm restart beginning from the last invocation. The
time distance is measured by using the internal ProConOS system tick
counter located at the system flag area %MD 1.52. To get a ’normalized’
time base in millisecond, the internal flag %MW 1.44 is used to convert
timer ticks into millisecond. The preset timer value is limited at
2.147.483.647 milliseconds, which is caused by the maximum range of the
DINT data type.

Problem of lost invocation after warm restart


Because the algorithm is based on a non retentive internal system tick
counter, it is important to take notice of the problem, which we call ’lost in-
vocation’. The figure below describes the behavior of the function block be-
fore and after a warm start is forced. After the IN parameter raised to
TRUE, the next invocation detects the raising edge state of IN. At this point

13-10 5958B
Timer function blocks

the calculation begins with ET (elapsed time) := 0. After a warm restart, the
next invocation detects the changed state and normalize the internal start
value by subtracting the current system counter with the internal retentive
elapsed counter. That is why, the time distance to the previous invocation
is 0. Related to the ’real’ elapsed time there is a delay dependent from the
duration between successive invocations of TON_R. That means, after a
warm start the duration of a TON_R function block is at worst one invoca-
tion distance slower than a TON_R where no warm restart occurs.

Hot start behavior


After a hot start is performed , it is important to know, that the timer calcu-
lates the elapsed time including the duration of the stop state. A hot start is
forced e.g. if the PLC is continued from a breakpoint. During the online de-
bug, it could happen that some timer expire if the PLC halts on breakpoints.

Example

5958B 13-11
PROGRAM WORX

Variables VAR
declaration
var1 : BOOL;
var2 : TIME;
var3 : BOOL;
var4 : TIME;
TON_R_1 : TON_R;
END_VAR
Function blocks have to be instantiated. The instance name can be any
name of your choice. It must be unique within the POU. In the example the
instance name ’TON_R_1’ is used.

Representation
IL ST FBD

LD var1 TON_R_1(IN:=var1,PT:=var2);
ST TON_R_1.IN var3:= TON_R_1.Q;
LD var2 var4:= TON_R_1.ET;
ST TON_R_1.PT
CAL TON_R_1
LD TON_R_1.Q
ST var3
LD TON_R_1.ET
ST var4

13-12 5958B
Timer function blocks

13.5 TOF

Description This timer function block realizes an off-delay timing.


If the input IN changes from TRUE to FALSE, switching off is delayed for
the time interval at input PT. After PT has passed, FALSE is issued at the
output Q. The time which has already elapsed is indicated at the output ET.

Parameter Data types Description


IN BOOL If a falling edge is detected, the off-delay ti-
ming is started.
PT TIME preset time interval for the delay
Q BOOL TRUE if IN = TRUE and ET < PT
FALSE if IN = FALSE and ET >= PT
ET TIME elapsed time interval

The input IN and the output Q can be negated.

Time diagram

Example

5958B 13-13
PROGRAM WORX

Variables VAR
declaration
var1 : BOOL;
var2 : TIME;
var3 : BOOL;
var4 : TIME;
TOF_1 : TOF;
END_VAR
Function blocks have to be instantiated. The instance name can be any
name of your choice. It must be unique within the POU. In the example the
instance name ’TOF_1’ is used.

Representation
IL ST FBD

LD var1 TOF_1(IN:=var1,PT:=var2);
ST TOF_1.IN var3:= TOF_1.Q;
LD var2 var4:= TOF_1.ET;
ST TOF_1.PT
CAL TOF_1
LD TOF_1.Q
ST var3
LD TOF_1.ET
ST var4

13-14 5958B
Timer function blocks

13.6 TOF_R

This function block has the same function as function block TOF.
The elapsed time interval however, is stored in the retentive area.

Description This timer function block realizes an off-delay timing. It operates as retain
timer, i.e. the timer continues after a warm start occurs.
If the input IN changes from TRUE to FALSE, switching off is delayed for
the time interval at input PT. After PT has passed, FALSE is issued at the
output Q. The time which has already elapsed is indicated at the output ET.

Parameter Data types Description


IN BOOL If a falling edge is detected, the off-delay ti-
ming is started.
PT TIME preset time interval for the delay
Q BOOL TRUE if IN = TRUE and ET < PT
FALSE if IN = FALSE and ET >= PT
ET TIME elapsed time interval

The input IN and the output Q can be negated.

Algorithm
The algorithm is based on incrementing time distances between two invo-
cations of the function block. This function block is capable to calculate the
elapsed time after a warm restart beginning from the last invocation. The
time distance is measured by using the internal ProConOS system tick
counter located at the system flag area %MD 1.52. To get a ’normalized’
time base in millisecond, the internal flag %MW 1.44 is used to convert
timer ticks into millisecond. The preset timer value is limited at
2.147.483.647 milliseconds, which is caused by the maximum range of the
DINT data type.

Problem of lost invocation after warm restart


Because the algorithm is based on a non retentive internal system tick
counter, it is important to take notice of the problem, which we call ’lost in-
vocation’. The figure below describes the behavior of the function block be-
fore and after a warm start is forced. After the IN parameter raised to
TRUE, the next invocation detects the raising edge state of IN. At this point

5958B 13-15
PROGRAM WORX

the calculation begins with ET (elapsed time) := 0. After a warm restart, the
next invocation detects the changed state and normalize the internal start
value by subtracting the current system counter with the internal retentive
elapsed counter. That is why, the time distance to the previous invocation
is 0. Related to the ’real’ elapsed time there is a delay dependent from the
duration between successive invocations of TOF_R. That means, after a
warm start the duration of a TOF_R function block is at worst one invoca-
tion distance slower than a TOF_R where no warm restart occurs.

Hot start behavior


After a hot start is performed , it is important to know, that the timer calcu-
lates the elapsed time including the duration of the stop state. A hot start is
forced e.g. if the PLC is continued from a breakpoint. During the online de-
bug, it could happen that some timer expire if the PLC halts on breakpoints.

Example

13-16 5958B
Timer function blocks

Variables VAR
declaration
var1 : BOOL;
var2 : TIME;
var3 : BOOL;
var4 : TIME;
TOF_R_1 : TOF_R;
END_VAR
Function blocks have to be instantiated. The instance name can be any
name of your choice. It must be unique within the POU. In the example the
instance name ’TOF_R_1’ is used.

Representation
IL ST FBD

LD var1 TOF_R_1(IN:=var1,PT:=var2);
ST TOF_R_1.IN var3:= TOF_R_1.Q;
LD var2 var4:= TOF_R_1.ET;
ST TOF_R_1.PT
CAL TOF_R_1
LD TOF_R_1.Q
ST var3
LD TOF_R_1.ET
ST var4

5958B 13-17
PROGRAM WORX

13-18 5958B
Section 14
This section provides information on
– how to use ProConOS functions

ProConOS functions† .........................................................................................14-3


14.1 Overview ...................................................................................14-3
14.2 COLD_RESTART .....................................................................14-3
14.3 CONTINUE ...............................................................................14-5
14.4 HOT_RESTART........................................................................14-6
14.5 WARM_RESTART ....................................................................14-7
14.6 RD_*_BY_SYM .........................................................................14-9
14.7 WR_*_BY_SYM ......................................................................14-11

†. Extended functions going beyond the standard functional range of the IEC 61131-3.

5958B 14-1
14-2 5958B
ProConOS functions

14 ProConOS functions

14.1 Overview

In addition to the IEC standard functions ProConOS functions can be used.


For ProConOS the following functions are available:

Table 14-1 ProConOS functions

Function Short description


COLD_RESTART† executes a cold restart
CONTINUE† continues the program execution
HOT_RESTART† executes a hot restart

RD_*_BY_SYM reads a value from a symbolic variable in PDD
WARM_RESTART† executes a warm restart
WR_*_BY_SYM† writes a value to a symbolic variable in PDD
† Extended functions going beyond the standard functional range
of the IEC 61131-3.

14.2 COLD_RESTART

Description This ProConOS function executes a cold restart if the input is TRUE. Du-
ring a cold restart all data is initialized.
This function should be called in the corresponding SPG to restart automa-
tically the program execution if e.g. a stack overflow, string error or division
by zero occurred. A cold restart is done immediately after the exception oc-
curred.
If the function is called in the normal PLC application to execute a cold re-
start, the program execution of the current cycle is finished first and then
the cold restart is done.

5958B 14-3
PROGRAM WORX

Use this function carefully. Make sure that the exception such as division
by zero or string error will not cause any damage restarting the program
execution.

Parameter Data type Description


COND BOOL executes a cold restart if it is TRUE
OUT BOOL TRUE if COND = TRUE and cold restart pos-
sible

Example Variable declaration:


VAR
var1 : BOOL;
END_VAR

Code body declaration:


LD BOOL#TRUE (*executes a cold restart*)
COLD_RESTART
ST var1 (*stores TRUE on var1*)

Representation
IL ST

LD COND OUT :=COLD_RESTART(COND,OUT);


COLD_RESTART
ST OUT

FBD

14-4 5958B
ProConOS functions

14.3 CONTINUE

Description This ProConOS function continues the program execution if the input is
TRUE. This function should be called in the corresponding SPG to continue
automatically the program execution e.g. in case of a watchdog error.
This function should not be used for the exceptions division by zero (SPG
11), stack overflow (SPG 12), bus error (SPG 20) and bounds error (SPG
19).
Use this function carefully. Make sure that the exception such as the watch-
dog error will not cause any damage continuing the program execution.

Parameter Data type Description


COND BOOL continues the program execution if it is
TRUE
OUT BOOL TRUE if COND = TRUE and the program
execution possible

Example Variable declaration:


VAR
var1 : BOOL;
END_VAR

14.3.0.1 Code body declaration:


LD BOOL#TRUE (*continues the program execution*)
CONTINUE
ST var1 (*stores TRUE on var1*)

Representation
IL ST FBD

LD COND OUT := CONTINUE(COND,OUT);


CONTINUE
ST OUT

5958B 14-5
PROGRAM WORX

14.4 HOT_RESTART

Description This ProConOS function executes a hot restart if the input is TRUE. During
a hot restart no data is initialized.
This function should be called in the corresponding SPG to restart automa-
tically the program execution if e.g. a stack overflow, string error or division
by zero occurred. A hot restart is done immediately after the exception oc-
curred.
If the function is called in the normal PLC application to execute a hot re-
start, the program execution of the current cycle is finished first and then
the hot restart is done.
Use this function carefully. Make sure that the exception such as division
by zero or string error will not cause any damage restarting the program
execution.

Parameter Data type Description


COND BOOL executes a hot restart if it is TRUE
OUT BOOL TRUE if COND = TRUE and hot restart pos-
sible

Example Variable declaration:


VAR
var1 : BOOL;
END_VAR
Code body declaration:
LD BOOL#TRUE (*executes a hot restart*)
HOT_RESTART
ST var1 (*stores TRUE on var1*)
Representation
IL ST FBD

LD COND OUT :=
HOT_RESTART HOT_RESTART(COND,OUT);
ST OUT

14-6 5958B
ProConOS functions

14.5 WARM_RESTART

Description This ProConOS function executes a warm restart if the input is TRUE. Du-
ring a warm restart only non-retentive data is initialized.
This function should be called in the corresponding SPG to restart automa-
tically the program execution if e.g. a stack overflow, string error or division
by zero occurred. A warm restart is done immediately after the exception
occurred.
If the function is called in the normal PLC application to execute a warm re-
start, the program execution of the current cycle is finished first and then
the warm restart is done.
Use this function carefully. Make sure that the exception such as division
by zero or string error will not cause any damage restarting the program
execution.

Parameter Data type Description


COND BOOL executes a warm restart if it is TRUE
OUT BOOL TRUE if COND = TRUE and warm restart
possible

Example Variable declaration:


VAR
var1 : BOOL;
END_VAR

Code body declaration:


LD BOOL#TRUE (*executes a warm restart*)
WARM_RESTART
ST var1 (*stores TRUE on var1*)

5958B 14-7
PROGRAM WORX

Representation
IL ST

LD COND OUT :=WARM_RESTART(COND,OUT);


WARM_RESTART
ST OUT
FBD

14-8 5958B
ProConOS functions

14.6 RD_*_BY_SYM

Description This ProConOS function reads the value of a symbolic variable in the PDD
whose name is assigned to a string.
For local variables the full instance name ’program instance.function block
instance.variable name’ has to be used, each instance being separated
with a point. The function block instance is optional depending whether you
have inserted a function block instance in the subtree ’Physical Hardware’
or not.
For global variables ’@GV’ and the variable name separated by a point
have to be used.
The variable has to be declared using the variable attribute {PDD} in the
variable declaration. For information about declaring variables refer to the
general help of PROGRAM WORX.
The function is only available for IPC_28, M68_28, ProConOS 2.9 and hig-
her if PDD is supported.

Parameter Data types Description


IN STRING string containing the name of
the symbolic variable which is
going to be read
ERR INT error code:
0 no error occurred
1 variable not found in PDD
2 data type not supported
3 string error

RD_*_BY_SYM BYTE, SINT, WORD, value which is read


INT, DWORD, DINT,
STRING

5958B 14-9
PROGRAM WORX

Example

Representation
IL ST

LD IN RD_*_BY_SYM:= RD_*_BY_SYM(IN,ERR);
RD_*_BY_SYM ERR
ST RD_*_BY_SYM
FBD

Example for function RD_BYTE_BY_SYM

For using the function just replace * by the corresponding data type.

14-10 5958B
ProConOS functions

14.7 WR_*_BY_SYM

Description This ProConOS function writes a value to a variable which has been inser-
ted in the PDD.
For local variables the full instance name ’program instance.function block
instance.variable name’ has to be used, each instance being separated
with a point. The function block instance is optional depending whether you
have inserted a function block instance in the subtree ’Physical Hardware’
or not.
For global variables ’@GV’ and the variable name separated by a point
have to be used.
The variable has to be declared using the variable attribute {PDD} in the
variable declaration. For information about declaring variables refer to the
general help of PROGRAM WORX.
The function is only available for IPC_28, M68_28, ProConOS 2.9 and hig-
her if PDD is supported.

Parameter Data types Description


IN_STR STRING string containing the symbolic
name of the variable which is
going to be written
IN_VAL BYTE, SINT, value which is going to be written
WORD, INT, to the variable
DWORD, DINT,
STRING,
WR_*_BY_SYM INT error code:
0 no error occurred
1 variable not found in PDD
2 data error
3 data type not supported
4 string error

5958B 14-11
PROGRAM WORX

Example

Representation
IL ST

LD INSTR WR_*_BY_SYM:=
WR_*_BY_SYM IN_VAL WR_*_BY_SYM(IN_STR,IN_VAL);
ST WR_*_BY_SYM

FBD
Example for function WR_BYTE_BY_SYM

For using the function just replace * by the corresponding data type.

14-12 5958B
Section 15
This section provides information on
– how to use ProConOS function blocks

ProConOS function blocks† ................................................................................15-3


15.1 Overview ...................................................................................15-3
15.2 CLR_OUT .................................................................................15-4
15.3 DERIVAT...................................................................................15-5
15.4 GET_SYM .................................................................................15-8
15.5 INTEGRAL ..............................................................................15-11
15.6 RD_BOOL_BY_SYM ..............................................................15-14
15.7 RD_INPUT_GROUP ...............................................................15-16
15.8 WR_BOOL_BY_SYM..............................................................15-18
15.9 WR_OUTPUT_GROUP ..........................................................15-21

†. Extended functions going beyond the standard functional range of the IEC 61131-3.

5958B 15-1
15-2 5958B
ProConOS function blocks

15 ProConOS function blocks

15.1 Overview

In addition to the IEC standard function blocks ProConOS function blocks


can be used.
For ProConOS the following function blocks are available:

Table 15-1 ProConOS function blocks

Function block Short description


CLR_OUT† sets all outputs of the I/O image to zero
DERIVAT† differentiation with respect to time
GET_SYM† searches for the symbolic name of a varia-
ble in PDD
INTEGRAL† integration over time
RD_BOOL_BY_SYM† reads a value from a symbolic variable in
PDD
RD_INPUT_GROUP† reads the values of an input group in the
I/O image
WR_BOOL_BY_SYM† writes a value to a symbolic variable in PDD
WR_OUTPUT_GROUP† writes the values of an output group in the
I/O image
† Extended functions going beyond the standard functional range of
the IEC 61131-3.

5958B 15-3
PROGRAM WORX

15.2 CLR_OUT

Description This ProConOS function block sets the outputs of the I/O image to zero. It
should be called in SPG 2 to set all outputs to zero if the program execution
stops.

Parameter Data type Description


EN BOOL sets all outputs of the I/O image to zero if it is
TRUE

Example Variable declaration:


VAR
var1 : BOOL;
CLR_OUT_1 : CLR_OUT;
END_VAR
Code body declaration:
LD BOOL#TRUE (*loads TRUE*)
ST CLR_OUT_1.EN (*stores TRUE on the input*)
CAL CLR_OUT_1 (*sets all outputs to zero*)
Variables VAR
declaration
var1 : BOOL;
CLR_OUT_1 : CLR_OUT;
END_VAR
Function blocks have to be instantiated. The instance name can be any
name of your choice. It must be unique within the POU. In the example the
instance name ’CLR_OUT_1’ is used.

Representation
IL ST FBD

LD var1 CLR_OUT_1(IN);
ST CLR_OUT_1.EN
CAL CLR_OUT_1

15-4 5958B
ProConOS function blocks

15.3 DERIVAT

Description This ProConOS function block implements differentiation with respect to


time. The function block is executed when ENABLE = TRUE.
The following program fragment describes the functionality of the function
block:

The value of the operand connected to CYCLE has to correspond to the


cycle time of the task where the function block is used.

Parameter Data type Description


ENABLE BOOL TRUE = the function block is executed
RUN BOOL FALSE = the execution of the function block
is halted and the output is set to zero
XIN REAL Input value
CYCLE TIME Sampling period corresponding to the cycle
of the task where the function block is execu-
ted
XOUT REAL Output value

5958B 15-5
PROGRAM WORX

Example

Variables VAR
declaration
var1 : BOOL;
var2 : BOOL;
var3 : REAL;
var4 : TIME;
var5 : REAL;
DERIVAT_1 : DERIVAT;
END_VAR
Function blocks have to be instantiated. The instance name can be any
name of your choice. It must be unique within the POU. In the example the
instance name ’DERIVAT_1’ is used.

15-6 5958B
ProConOS function blocks

Representation

IL ST

LD var1 DERIVAT_1(ENABLE:=var1,RUN:=var2,
ST DERIVAT_1.ENABLE XIN:=var3,CYCLE=var4);
LD var2 var5:=DERIVAT_1.XOUT;
ST DERIVAT_1.RUN
LD var3
ST DERIVAT_1.XIN
LD var4
ST DERIVAT_1.CYCLE
CAL DERIVAT_1
LD DERIVAT_1.XOUT
ST var5

FBD

5958B 15-7
PROGRAM WORX

15.4 GET_SYM

Description This ProConOS function block searches for the symbolic name of a varia-
ble in the PDD. For local variables the symbolic name is the full instance
name ’program instance.function block instance.variable name’, each in-
stance being separated with a point. The function block instance is optional
depending whether you have inserted a function block instance in the sub-
tree ’Physical Hardware’ or not. For global variables the symbolic name is
’@GV’ and the variable name separated by a point.
The variable has to be declared using the variable attribute {PDD} in the
variable declaration. For information about declaring variables refer to the
general help of PROGRAM WORX.
If field names are supported the function block can also be used to search
for field names. Field names are an additional description for a variable de-
scribing the field topology of variables in a plant.
If the input EN of the function block is TRUE, it is searched in the PDD for
the symbolic name of the variable connected to the input VARIABLE. If the
variable is found in the PDD the symbolic and/or the field name is stored to
the output ’SymbolicName’ and/or ’FieldName’. If the resulting output string
is too long for the connected string variable, SPG 21 is called and the PLC
is set to the state STOP. If PDD or MSFC are not supported only the error
and status flags are set.
The function block is only available for IPC_28, M68_28, ProConOS 2.9
and higher if PDD and MSFC are supported.

Parameter Data type Description


EN BOOL TRUE = the function block is executed
VARIABLE ANY variable whose symbolic or field name
is going to be searched
ERROR BOOL TRUE = no symbol found
FALSE = symbol found

15-8 5958B
ProConOS function blocks

Parameter Data type Description


STATUS INT Status code:
0 no symbol or field address found
1 symbol found
2 field address found
3 symbol and/or address found
4 symbol string too long
5 field string too long
6 PDD or MSFC not supported
SymbolicName STRING Symbolic name of the variable if it is
found
FieldName STRING Field name of the variable if it is found

– When specifying ARRAY or STRUCT elements, GET_SYM does not


provide a return value.
– Symbolic names must not exceed 80 characters.

Example

5958B 15-9
PROGRAM WORX

Variables VAR
declaration
EN : BOOL;
VARIABLE : * {PDD};
ERROR : BOOL;
STATUS : INT;
SymbolicName : STRING;
FieldName : STRING;
GET_SYM_1 : GET_SYM;
END_VAR
For using the function just replace * by the corresponding data type.

Function blocks have to be instantiated. The instance name can be any


name of your choice. It must be unique within the POU. In the example the
instance name ’GET_SYM_1’ is used.

Representation

IL ST FBD

LD var1 GET_SYM_1(EN:=var1,
ST GET_SYM_1.EN VARIABLE:=var2);
LD var2 var3:=GET_SYM_1.ERROR;
ST GET_SYM_1.VARIABLE var4:=GET_SYM_1.STATUS;
CAL GET_SYM_1 var5:=GET_SYM_1.SymbolicName;
LD GET_SYM_1.ERROR var6:=GET_SYM_1.FieldName;
ST var3
LD GET_SYM_1.STATUS
ST var4
LD GET_SYM_1.SymbolicName
ST var5
LD GET_SYM_1.FieldName
ST var6

15-10 5958B
ProConOS function blocks

15.5 INTEGRAL

Description This ProConOS function block implements integration over time. The
function block is carried out when the ENABLE is set to TRUE.
The following program fragment describes the functionality of the function
block:

The value of the operand connected to CYCLE has to correspond to the


cycle time of the task where the function block is used.

Parameter Data type Description


ENABLE BOOL TRUE = the function block is executed
RUN BOOL FALSE = the execution of the function block
is halted
R1 BOOL The function block is reset and initialized
with the initial value X0
XIN REAL Input value
X0 REAL Initial value
CYCLE TIME Sampling period corresponding to the cycle
of the task where the function block is execu-
ted
Q BOOL Negated R1
XOUT REAL Output value

5958B 15-11
PROGRAM WORX

Example

Variables VAR
declaration
var1 : BOOL;
var2 : BOOL;
var3 : BOOL;
var4 : REAL;
var5 : REAL;
var6 : TIME;
var7 : BOOL;
var8 : REAL;
INTEGRAL_1 : INTEGRAL;
END_VAR

15-12 5958B
ProConOS function blocks

Function blocks have to be instantiated. The instance name can be any


name of your choice. It must be unique within the POU. In the example the
instance name ’INTEGRAL_1’ is used.

Representation

IL ST

LD var1 INTEGRAL_1(ENABLE:=var1,RUN:=var2,R1:=var3,XIN:=var4,
ST INTEGRAL_1.ENABLE XO:=var5,CYCLE=var6);
LD var2 var7:=INTEGRAL_1.Q;
ST INTEGRAL_1.RUN var8:=INTEGRAL_1.XOUT;
LD var3
ST INTEGRAL_1.R1
LD var4
ST INTEGRAL_1.XIN
LD var5
ST INTEGRAL_1.XO
LD var6
ST INTEGRAL_1.CYCLE
CAL INTEGRAL_1
LD INTEGRAL_1.Q
ST var7
LD INTEGRAL_1.XOUT
ST var8
FBD

5958B 15-13
PROGRAM WORX

15.6 RD_BOOL_BY_SYM

Description This ProConOS function block reads the value of a symbolic variable in the
PDD whose name is assigned to a string.
For local variables the full instance name ’program instance.function block
instance.variable name’ has to be used, each instance being separated
with a point. The function block instance is optional depending whether you
have inserted a function block instance in the subtree ’Physical Hardware’
or not.
For global variables ’@GV’ and the variable name separated by a point
have to be used.
The variable has to be declared using the variable attribute {PDD} in the
variable declaration. For information about declaring variables refer to the
general help of PROGRAM WORX.
The function block is only available for IPC_28, M68_28, ProConOS 2.9
and higher if PDD is supported.

Parameter Data types Description


IN STRING string containing the name of the symbolic
variable which is going to be read
ERR INT error code:
0 no error occurred
1 variable not found in PDD
2 data type not supported

OUT BOOL value which is read

Example Variable declaration:


VAR
stringvar : STRING := ’GV.var1’;
var2 : INT;
var3 : BOOL;
RD_BOOL_BY_SYM_1 : RD_BOOL_BY_SYM;
END_VAR
VAR_GLOBAL
var1 : BOOL {PDD};
END_VAR

15-14 5958B
ProConOS function blocks

Code body declaration:

The result is that the value of the global variable ’var1’ is stored to ’var3’ and
0 is stored at ’var2’.

Variables VAR
declaration var1 : STRING;
var2 : INT;
var3 : BOOL;
RD_BOOL_BY_SYM_1 : RD_BOOL_BY_SYM;
END_VAR
Function blocks have to be instantiated. The instance name can be any
name of your choice. It must be unique within the POU. In the example the
instance name ’RD_BOOL_BY_SYM_1’ is used.

Representation
IL ST

LD var1 RD_BOOL_BY_SYM_1(IN:=var1,
ST RD_BOOL_BY_SYM_1.IN ERR:=var2);
LD var2 var3:=RD_BOOL_BY_SYM_1.OUT;
ST RD_BOOL_BY_SYM_1.ERR
CAL RD_BOOL_BY_SYM_1
LD RD_BOOL_BY_SYM_1.OUT
ST var3
FBD

5958B 15-15
PROGRAM WORX

15.7 RD_INPUT_GROUP

Description This ProConOS function block reads the values of the I/O image for one
input group. The input group is specified by the address of the variable con-
nected to the input VAR. The variable can be any variable of this group.
The function block should be used to refresh the I/O image at the time of
calling.

Parameter Data type Description


MEMBER BYTE Variable who specifies the input group
ERROR INT Error code:
0 no error occurred
1 no driver found for this input address
2 error while reading the I/O image
7 variable address does not correspond
to an input group in the I/O
configuration

Example

15-16 5958B
ProConOS function blocks

Variables VAR
declaration
VAR : BYTE;
ERROR : INT;
RD_INPUT_GROUP_1 : RD_INPUT_GROUP
END_VAR
Function blocks have to be instantiated. The instance name can be any
name of your choice. It must be unique within the POU. In the example the
instance name ’RD_INPUT_GROUP_1’ is used.

Representation

IL ST

LD var1 RD_INPUT_GROUP_1(VAR:=var1);
ST RD_INPUT_GROUP_1.VAR var2:=RD_INPUT_GROUP_1.ERROR;
CAL RD_INPUT_GROUP_1
LD RD_INPUT_GROUP_1.ERROR
ST var2
FBD

5958B 15-17
PROGRAM WORX

15.8 WR_BOOL_BY_SYM

Description This ProConOS function block writes a value to a variable which has been
inserted in the PDD.
For local variables the full instance name ’program instance.function block
instance.variable name’ has to be used, each instance being separated
with a point. The function block instance is optional depending whether you
have inserted a function block instance in the subtree ’Physical Hardware’
or not.
For global variables ’@GV’ and the variable name separated by a point
have to be used.
The variable has to be declared using the variable attribute {PDD} in the
variable declaration. For information about declaring variables refer to the
general help of PROGRAM WORX.
The function block is only available for IPC_28, M68_28, ProConOS 2.9
and higher if PDD is supported.

Parameter Data types Description


IN_STR STRING string containing the symbolic name of the
variable which is going to be written
IN_VAL BOOL value which is going to be written to the va-
riable
ERR INT error code:
0 no error occurred
1 variable not found in PDD
2 data error
3 data type not supported

15-18 5958B
ProConOS function blocks

Example

The result is that TRUE is written to the global variable ’var1’ and 0 is stored
at ’var2’.

Variables VAR
declaration
var1 : STRING;
var2 : BOOL;
var3 : INT;
WR_BOOL_BY_SYM_1 : WR_BOOL_BY_SYM;
END_VAR
Function blocks have to be instantiated. The instance name can be any
name of your choice. It must be unique within the POU. In the example the
instance name ’WR_BOOL_BY_SYM_1’ is used.

5958B 15-19
PROGRAM WORX

Representation

IL ST

LD var1
WR_BOOL_BY_SYM_1(IN_STR:=var1,IN_VAR:=var2);
ST WR_BOOL_BY_SYM_1.IN_STR var3:=WR_BOOL_BY_SYM_1.ERR;
LD var2
ST WR_BOOL_BY_SYM_1.IN_VAL
CAL WR_BOOL_BY_SYM_1
LD WR_BOOL_BY_SYM_1.ERR
ST var3

FBD

15-20 5958B
ProConOS function blocks

15.9 WR_OUTPUT_GROUP

Description This ProConOS function block writes the values of the I/O image for one
output group. The output group is specified by the address of the variable
connected to the input VAR. The variable can be any variable of this group.
The function block should be used to refresh the I/O image at the time of
calling.

Parameter Data type Description


MEMBER BYTE Variable who specifies the output group
ERROR INT Error code:
0 no error occurred
1 no driver found for this output address
3 error while writing the I/O image
7 variable address does not correspond
to an output group in the I/O
configuration

Example

5958B 15-21
PROGRAM WORX

Variables VAR
declaration
VAR : BYTE;
ERROR : INT;
WR_OUTPUT_GROUP_1 : WR_OUTPUT_GROUP
END_VAR
Function blocks have to be instantiated. The instance name can be any
name of your choice. It must be unique within the POU. In the example the
instance name ’WR_OUTPUT_GROUP_1’ is used.

Representation

IL ST

LD var1 WR_OUTPUT_GROUP_1(VAR:=var1);
ST WR_OUTPUT_GROUP_1.VAR var2:=WR_OUTPUT_GROUP_1.ERROR;
CAL WR_OUTPUT_GROUP_1
LD WR_OUTPUT_GROUP_1.ERROR
ST var2

FBD

15-22 5958B
Section 16
This section provides information on
– how to use bit manipulation functions

Bit manipulation functions† .................................................................................16-3


16.1 Overview ...................................................................................16-3
16.2 BIT_TEST .................................................................................16-4
16.3 GET_CHAR...............................................................................16-5
16.4 GET_LSB ..................................................................................16-6
16.5 GET_MSB .................................................................................16-7
16.6 SET_LSB ..................................................................................16-8
16.7 SET_MSB .................................................................................16-9
16.8 I_BIT_IN_*...............................................................................16-10
16.9 R_BIT_IN_* .............................................................................16-12
16.10 S_BIT_IN_* .............................................................................16-14
16.11 PARITY_*................................................................................16-16
16.12 STRING_TO_BUFFER ...........................................................16-17
16.13 SWAP......................................................................................16-19

†. Extended functions going beyond the standard functional range of the IEC 61131-3.

5958B 16-1
16-2 5958B
Bit manipulation functions

16 Bit manipulation functions

16.1 Overview

In addition to the standard functions firmware functions can be used if you


have announced the firmware library in your PROGRAM WORX project.

Announcing libraries is described in the general help.


The following bit manipulation functions are available:

Table 16-1 Bit manipulation functions

Function Short description


BIT_TEST† reads the value of a single bit in a bit string

GET_CHAR extracts one character out of a string
GET_LSB† reads the value of the less significant BYTE of
a bit string
GET_MSB† reads the value of the most significant BYTE
of a bit string
I_BIT_IN_* † inverts a single bit in a bit string

PARITY_* checks if the number of set bits is even or odd
R_BIT_IN_* † resets a single bit in a bit string
S_BIT_IN_* † sets a single bit in a bit string
SET_LSB† writes a value on the less significant BYTE of
a bit string
SET_MSB† writes a value on the most significant BYTE of
a bit string
STRING_TO_BUFFER† copies characters of a string to a buffer
SWAP† exchanges the most and the less significant
BYTE of a bit string
† Extended functions going beyond the standard functional range of
the IEC 61131-3.

5958B 16-3
PROGRAM WORX

16.2 BIT_TEST

Description This bit manipulation function can be used to read the value of a single bit
in a bit string.

Parameter Data type Description


IN ANY_BIT input bit string
NO SINT number of bit to be tested
OUT BOOL output value of the tested bit

Example Variable declaration:


VAR
var1 : BOOL;
END_VAR

Code body declaration:

LD BYTE#00100001 (*loads the input bit string*)


BIT_TEST SINT#5 (*specifies number of bit*)
ST var1 (*stores TRUE in var1*)

Representation
IL ST FBD

LD IN OUT := BIT_TEST(IN,NO);
BIT_TEST NO
ST OUT

16-4 5958B
Bit manipulation functions

16.3 GET_CHAR

Description This bit manipulation function can be used to extract one character out of
a string. The output value represents the number of the character in ASCII
code.

Parameter Data type Description


IN STRING input string
N INT number of the character within the string star-
ting from the left
GET_CHA INT ASCII code number of the extracted charac-
R ter

Example Variable declaration:


VAR
var1 : INT;
END_VAR

Code body declaration:

LD ’drive’ (*loads the string*)


GET_CHAR 3 (*extracts the third character from the left*)
ST var1 (*stores ’105’ as ASCII number*)

Representation
IL ST FBD

LD IN GET_CHAR:=GET_CHAR(IN,N);
GET_CHAR N
ST GET_CHAR

5958B 16-5
PROGRAM WORX

16.4 GET_LSB

Description This bit manipulation function can be used to read the value of the less si-
gnificant BYTE of a bit string.

Parameter Data type Description


IN WORD input bit string
OUT BYTE value of the less significant BYTE

Example Variable declaration:


VAR
var1 : BYTE;
END_VAR

Code body declaration:

LD WORD#1001100100110011 (*loads the bit string*)


GET_LSB
ST var1 (*stores ’00110011’ to var1*)

Representation
IL ST FBD

LD IN OUT := GET_LSB(IN);
GET_LSB
ST OUT

16-6 5958B
Bit manipulation functions

16.5 GET_MSB

Description This bit manipulation function can be used to read the value of the most si-
gnificant BYTE of a bit string.

Parameter Data type Description


IN WORD input bit string
OUT BYTE value of the most significant BYTE

Example Variable declaration:


VAR
var1 : BYTE;
END_VAR

Code body declaration:

LD WORD#1001100100110011 (*loads the bit string*)


GET_MSB
ST var1 (*stores ’10011001’ to var1*)

Representation
IL ST FBD

LD IN OUT := GET_MSB(IN);
GET_MSB
ST OUT

5958B 16-7
PROGRAM WORX

16.6 SET_LSB

Description This bit manipulation function can be used to write a value on the less si-
gnificant BYTE of a bit string.

Parameter Data type Description


LSB BYTE value to be written on the less significant
BYTE
DATA WORD input bit string
OUT WORD output bit string

Example Variable declaration:


VAR
var1 : WORD;
END_VAR

Code body declaration:

LD BYTE#00110011 (*loads the value to be written*)


SET_LSB WORD#1111111100000000
ST var1 (*stores ’1111111100110011’ in var1*)

Representation
IL ST FBD

LD LSB OUT := SET_LSB(LSB,DATA);


SET_LSB DATA
ST OUT

16-8 5958B
Bit manipulation functions

16.7 SET_MSB

Description This bit manipulation function can be used to write a value on the most si-
gnificant BYTE of a bit string.

Parameter Data type Description


MSB BYTE value to be written on the most significant
BYTE
DATA WORD input bit string
OUT WORD output bit string

Example Variable declaration:


VAR
var1 : WORD;
END_VAR

Code body declaration:

LD BYTE#00110011 (*loads the value to be written*)


SET_MSB WORD#1111111100000000
ST var1 (*stores ’0011001100000000’ in var1*)

Representation
IL ST FBD

LD MSB OUT := SET_MSB(MSB,DATA);


SET_MSB DATA
ST OUT

5958B 16-9
PROGRAM WORX

16.8 I_BIT_IN_*

Description This bit manipulation function can be used to invert a single bit in a bit
string.

Parameter Data type Description


ENAB BOOL enables the execution of the function
IN BYTE, WORD, input bit string
DWORD
BIT_NO SINT number of the bit to be inverted
OUT BYTE, WORD, output bit string
DWORD

Example Variable declaration:


VAR
var1 : BYTE;
END_VAR

Code body declaration:

LD BOOL#TRUE (*enables the function*)


I_BIT_IN_BYTE BYTE#10011001,SINT#5 (*inverts bit 5*)
ST var1 (*stores ’10111001’ in var1*)

16-10 5958B
Bit manipulation functions

Representation
IL ST

LD ENAB OUT:= I_BIT_IN_*(ENAB,IN,BIT_NO);


I_BIT_IN_* IN,BIT_NO
ST OUT
FBD

Example for function I_BIT_IN_BYTE

For using the function just replace * by the corresponding data type.

5958B 16-11
PROGRAM WORX

16.9 R_BIT_IN_*

Description This bit manipulation function can be used to reset a single bit in a bit string
to FALSE.

Parameter Data type Description


ENAB BOOL enables the execution of the function
IN BYTE, WORD, input bit string
DWORD
BIT_NO SINT number of the bit to be reset to FALSE
OUT BYTE, WORD, output bit string
DWORD

Example Variable declaration:


VAR
var1 : BYTE;
END_VAR

Code body declaration:

LD BOOL#TRUE (*enables the function*)


R_BIT_IN_BYTE BYTE#10011001,SINT#5 (*resets bit 4*)
ST var1 (*stores ’10001001’ in var1*)

16-12 5958B
Bit manipulation functions

Representation
IL ST

LD ENAB OUT:=R_BIT_IN_*(ENAB,IN,BIT_NO);
R_BIT_IN_* IN,BIT_NO
ST OUT

FBD

Example for function R_BIT_IN_BYTE

For using the function just replace * by the corresponding data type.

5958B 16-13
PROGRAM WORX

16.10 S_BIT_IN_*

Description This bit manipulation function can be used to set a single bit in a bit string
to TRUE.

Parameter Data type Description


ENAB BOOL enables the execution of the function
IN BYTE, WORD, input bit string
DWORD
BIT_NO SINT number of bit to be set to TRUE
OUT BYTE, WORD, output bit string
DWORD

Example Variable declaration:


VAR
var1 : BYTE;
END_VAR

Code body declaration:

LD BOOL#TRUE (*enables the function*)


S_BIT_IN_BYTE BYTE#10011001,SINT#5 (*sets bit 5*)
ST var1 (*stores ’10111001’ in var1*)

16-14 5958B
Bit manipulation functions

Representation
IL ST

LD ENAB OUT:=S_BIT_IN_*(ENAB,IN,BIT_NO);
S_BIT_IN_* IN,BIT_NO
ST OUT

FBD

Example for function S_BIT_IN_BYTE

For using the function just replace * by the corresponding data type.

5958B 16-15
PROGRAM WORX

16.11 PARITY_*

Description This bit manipulation function can be used to check if the number of set bits
is even or odd.

Parameter Data type Description


IN1 BYTE, WORD, DWORD input bit string
OUT BOOL number of the set bits
TRUE = even number
FALSE = odd number

Example Variable declaration:


VAR
var1 : BOOL;
END_VAR

Code body declaration:

LD BYTE#00100001 (*loads the input bit string*)


PARITY_BYTE
ST var1 (*stores ’TRUE’ in var1*)

Representation
IL ST FBD
Example for function
LD IN1 OUT := PARITY_*(IN1); PARITY_BYTE
PARITY_*
ST OUT

For using the function just replace * by the corresponding data type.

16-16 5958B
Bit manipulation functions

16.12 STRING_TO_BUFFER

Description This bit manipulation function copies characters of a string to a buffer.


Make sure that the string copied to the buffer does not exceed the length
of the array. No check is done by PROGRAM WORX.
lThis function should only be used if an array is needed. Otherwise the
function GET_CHAR should be used.

Parameter Data type Description


STR_IN STRING input string
BUFFER BYTE buffer
BUF_LEN INT number of characters copied to
the buffer
STRING_TO_BUFFER INT output value

Example

5958B 16-17
PROGRAM WORX

Representation

IL

LD STR_IN
STRING_TO_BUFFER BUFFER,BUF_LEN
ST STRING_TO_BUFFER

ST

STRING_TO_BUFFER:=STRING_TO_BUFFER(STR_IN,BUFFER, BUF_LEN);

FBD

16-18 5958B
Bit manipulation functions

16.13 SWAP

Description This bit manipulation function can be used to exchange the most and the
less significant BYTE of a bit string.

Parameter Data type Description


IN WORD input bit string
OUT WORD output bit string

Example Variable declaration:


VAR
var1 : WORD;
END_VAR

Code body declaration:

LD WORD#1111111100000000 (*loads the input bit string*)


SWAP
ST var1 (*stores ’0000000011111111’ in var1*)

Representation
IL ST FBD

LD IN OUT := SWAP(IN);
SWAP
ST OUT

5958B 16-19
PROGRAM WORX

16-20 5958B
Section 17
This section provides information on
– how to use IB Communication Blocks

IB Communication Blocks† .................................................................................17-3


17.1 Overview ...................................................................................17-3
17.2 IB_CONTROL ...........................................................................17-4
17.3 PCP_CLIENT ............................................................................17-7
17.4 PCP_CONNECT .....................................................................17-11
17.5 PCP_READ.............................................................................17-14
17.6 PCP_SERVER ........................................................................17-18
17.7 PCP_WRITE ...........................................................................17-22
17.8 *_TO_BUF...............................................................................17-25
17.8.1 Possible status of the copy process for
*_TO_BUF function blocks.........................................17-31
17.8.2 String specialties of the function block
STRING_TO_BUF .....................................................17-32
17.9 BUF_TO_*...............................................................................17-33
17.9.1 Possible status of the copy process for
BUF_TO_* function blocks.........................................17-39
17.9.2 String specialties of the function block
BUF_TO_STRING .....................................................17-40

†. Extended functions going beyond the standard functional range of the IEC 61131-3.

5958B 17-1
17-2 5958B
IB Communication Blocks

17 IB Communication Blocks

17.1 Overview

The IB Communication Blocks provide you with the functions of Firmware


and PCP services.
The following IB Communication Blocks are available:

Table 17-1 IB Communication Blocks

Function Short description


PCP_CONNECT† establish communication connections to any PCP
device
PCP_READ† read data from the PCP device objects
PCP_WRITE† write data to the PCP device objects

PCP_CLIENT send PCP services and receive their confirmations
PCP_SERVER† receive PCP services and send their responses
IB_CONTROL† send Firmware services and receive their confirmati-
ons
† Extended functions going beyond the standard functional range of
the IEC 61131-3.

You can establish communication connections which directly deliver data


to PCP objects of single devices with PCP_READ and PCP_WRITE blocks
or which run PCP services with PCP SERVER/CLIENT blocks.
You can use the IB_CONTROL block to run a Firmware service.
Each block is both a sending and a receiving block. This means, that a
block sending a request can also receive the respective confirmation.
When objects are written or read directly you can also check if the action is
successful.
The PCP_CONNECT, PCP_WRITE, and PCP_READ blocks correspond
to the blocks specified in IEC 61131-5. The PCP_READ and PCP_WRITE
blocks have been extended by the parameter DATA_CNT.

5958B 17-3
PROGRAM WORX

The PCP_SERVER, PCP_CLIENT, and IB_CONTROL blocks are specific


to INTERBUS.
You can use IB Communication Blocks only on Controller Boards with
Firmware ≥ 4.4a.

17.2 IB_CONTROL

This block enables you to send Firmware services (requests) and receive
their confirmations.

Parameter Data types Description

REQ BOOL REQ stands for REQUEST. This input enables you to start the
(Input) block or prepare it for re-start.
Rising Edge (0,1) = The block is being started.
Falling Edge (1,0) = The block is being prepared for re-start.

NDR BOOL With a rising edge, this output (New Data Received) indicates
(Output) the availability of the data (confirmation) read in the RD_1 re-
ceive buffer. With NDR=TRUE you can read the data from the
receive buffer.

Note:
The data saved in RD_1 is only valid in the cycle in which
NDR changes from FALSE to TRUE.

RD_1 ANY RD_1 is the block’s receive buffer. The data can be ARRAY
(Input/Output) (VAR_IN_OUT) OF BYTE or ARRAY OF WORD types or user defined. The
receive buffer is used for receiving the confirmation (including
message code and parameter count).

SD_1 ANY SD_1 the block’s send buffer. You must transfer the request
(Input/Output) (VAR_IN_OUT) of the PCP service you wish to use according to its predefined
arrangement (including service code and parameter count) to
the send buffer. The data can be ARRAY OF BYTE or ARRAY
OF WORD types or user defined.
Please refer to the PCP documentation (IBS SYS PCP G4
UM) to see the arrangement and parameters of the PCP ser-
vice you want to use.

17-4 5958B
IB Communication Blocks

Parameter Data types Description

ADD_ERROR ANY If an error occurs, the error code is in ADD_ERROR. The error
(Input/Output) (VAR_IN_OUT) codes are PCP error messages. These are described in the
PCP manual. The minimal array length in ADD_ERROR is
two words or four bytes. You must connect ADD_ERROR to
a suitable variable. If the format is incorrect, the block will re-
turn an error (ERROR=TRUE).

Note:
The error codes saved in ADD_ERROR are only valid in the
cycle in which ERROR changes from FALSE to TRUE.

ERROR BOOL With a rising edge, this output indicates that an error has oc-
(Output) curred. You can read the error code from ADD_ERROR du-
ring the cycle in which the rising edge occurs.

Representation
IL

LD (* BOOL *)
ST IB_CONTROL_1.REQ
LD (* ANY *)
ST IB_CONTROL_1.ADD_ERROR
LD (* ANY *)
ST IB_CONTROL_1.SD_1
LD (* ANY *)
ST IB_CONTROL_1.RD_1
CAL IB_CONTROL_1
LD IB_CONTROL_1.NDR
ST (* BOOL *)
LD IB_CONTROL_1.ERROR
ST (* BOOL *)
LD IB_CONTROL_1.ADD_ERROR
ST (* ANY *)
LD IB_CONTROL_1.SD_1
ST (* ANY *)
LD IB_CONTROL_1.RD_1
ST (* ANY *)

5958B 17-5
PROGRAM WORX

ST

IB_CONTROL_1(REQ:=(* BOOL *),ADD_ERROR:=(* ANY *),


SD_1:=(* ANY *),RD_1:=(* ANY *));
(* BOOL *):= IB_CONTROL_1.NDR;
(* BOOL *):= IB_CONTROL_1.ERROR;
(* ANY *):= IB_CONTROL_1.ADD_ERROR;
(* ANY *):= IB_CONTROL_1.SD_1;
(* ANY *):= IB_CONTROL_1.RD_1;
FBD

17-6 5958B
IB Communication Blocks

17.3 PCP_CLIENT

This block enables you to send PCP services (requests) and receive their
confirmations.
Do not use this block with the following PCP services:
– INITIATE_REQUEST
– READ_REQUEST
– WRITE_REQUEST
– READ_WITH_NAME_REQUEST
– WRITE_WITH_NAME_REQUEST
– INFORMATION_REPORT_REQUEST
– ABORT_REQUEST

Parameter Data types Description


REQ BOOL REQ stands for REQUEST. This input enables you to start the
(Input) block or prepare it for re-start.
Rising Edge (0,1) = The block is being started.
Falling Edge (1,0) = The block is being prepared for re-start.
ID INT This parameter indicates a communication connection. The ID
(Input) parameter helps you to distinguish between several existing
communication connections. ID is only valid if the VALID para-
meter value of the PCP_CONNECT block is TRUE.
NDR BOOL With a rising edge, this output (New Data Received) shows
(Output) you the availability of the data read (confirmation) in the RD_1
receive buffer. If NDR=TRUE you can read the data from the
receive buffer.

Note:
The data saved in RD_1 is only valid in the cycle in which NDR
changes from FALSE to TRUE.
RD_1 ANY RD_1 is the block's receive buffer. The data can be ARRAY
(Input/Output) (VAR_IN_OUT) OF BYTE or ARRAY OF WORD types or user defined. The re-
ceive buffer is used for receiving the confirmation (including
message code and parameter count).

5958B 17-7
PROGRAM WORX

Parameter Data types Description


SD_1 ANY SD_1 is the block’s send buffer. You must transfer the request
(Input/Output) (VAR_IN_OUT) of the PCP service you wish to use according to its predefined
arrangement (including service code and parameter count) to
the send buffer. The data can be ARRAY OF BYTE or ARRAY
OF WORD types or user defined.
Please refer to the PCP documentation (IBS SYS PCP G4
UM) to see the arrangement and parameters of the PCP ser-
vice you want to use.
The CR entry (communication reference) does not have to be
allocated, since the communication connection has already
been established through the PCP_CONNECT block.
ADD_ERROR ANY If an error occurs, the error code is in ADD_ERROR. The error
(Input/Output) (VAR_IN_OUT) codes are PCP error messages. These are described in the
PCP manual. The minimal array length in ADD_ERROR is two
words or four bytes. You must connect ADD_ERROR to a sui-
table variable. If the format is incorrect, the block will return an
error (ERROR=TRUE).

Note:
The error codes saved in ADD_ERROR are only valid in the
cycle in which ERROR changes from FALSE to TRUE.
ERROR BOOL With a rising edge, this output indicates that an error has oc-
(Output) curred. You can read the error code from ADD_ERROR during
the cycle in which the rising edge occurs.

17-8 5958B
IB Communication Blocks

Representation
IL
LD (* BOOL *)
ST PCP_CLIENT_1.REQ
LD (* INT *)
ST PCP_CLIENT_1.ID
LD (* ANY *)
ST PCP_CLIENT_1.ADD_ERROR
LD (* ANY *)
ST PCP_CLIENT_1.SD_1
LD (* ANY *)
ST PCP_CLIENT_1.RD_1
CAL PCP_CLIENT_1
LD PCP_CLIENT_1.NDR
ST (* BOOL *)
LD PCP_CLIENT_1.ERROR
ST (* BOOL *)
LD PCP_CLIENT_1.ADD_ERROR
ST (* ANY *)
LD PCP_CLIENT_1.SD_1
ST (* ANY *)
LD PCP_CLIENT_1.RD_1
ST (* ANY *)

ST
PCP_CLIENT_1(REQ:=(* BOOL *),ID:=(* INT *),
ADD_ERROR:=(* ANY *),SD_1:=(* ANY *),RD_1:=(* ANY *));
(* BOOL *):= PCP_CLIENT_1.NDR;
(* BOOL *):= PCP_CLIENT_1.ERROR;
(* ANY *):= PCP_CLIENT_1.ADD_ERROR;
(* ANY *):= PCP_CLIENT_1.SD_1;
(* ANY *):= PCP_CLIENT_1.RD_1;

5958B 17-9
PROGRAM WORX

FBD

17-10 5958B
IB Communication Blocks

17.4 PCP_CONNECT

Use this block to establish communication connections to any (even hig-


her-level) PCP device. The block can establish a connection to another
PCP device (Initiate_Request) and receive and deal with a connection re-
quest (Initiate_Indication).

Parameter Data types Description


EN_C BOOL EN_C stands for "Enable Connect" and is used to establish
(Input) and maintain communication connections.
EN_C = TRUE
The connections is being established or maintained. Connec-
tion requests from other devices are answered positively.
EN_C = FALSE
The connection is being ended. Connection requests from
other devices are answered negatively.
ADD_ERROR ANY If an error occurs, the error code is in ADD_ERROR. The error
(Input/Output) (VAR_IN_OUT) codes are PCP error messages. These are described in the
PCP manual. The minimal array length in ADD_ERROR is two
words or four bytes. You must connect ADD_ERROR to a sui-
table variable. If the format is incorrect, the block will return an
error (ERROR=TRUE).

Note:
The error codes saved in ADD_ERROR are only valid in the
cycle in which ERROR changes from FALSE to TRUE.

5958B 17-11
PROGRAM WORX

Parameter Data types Description


PARTNER STRING This input expects the designator of the PCP device you want
(Input/Output) to establish a connection to or that wants to establish a con-
nection.
Syntax example:
"CR 3" for communication reference 3,
"Cr3", "C3", "CR 03", and "C03" are also accepted.
"D1.4.6" for the device in System1, Segment 4, and Position 6.
"Dn 01.04.06", "D 1.4.6", "d 1.4.6", "dn 1.04.06", and
"Dn1.4.6" are also accepted.
The system parameters are:
"0" for the higher-level bus system,
"1" for the local bus system.
VALID BOOL This parameter shows you if a correct communication connec-
(Output) tion exists. The ID parameter is only valid with VALID = TRUE.
ID INT This parameter indicates a communication connection. The ID
(Output) parameter helps you to distinguish between several existing
communication connections. ID is only valid if the VALID para-
meter value of the PCP_CONNECT block is TRUE.
ERROR BOOL With a rising edge, this output indicates that an error has oc-
(Output) curred. You can read the error code from ADD_ERROR during
the cycle in which the rising edge occurs.

17-12 5958B
IB Communication Blocks

Representation
IL
LD (* BOOL *)
ST PCP_CONNECT_1.EN_C
LD (* ANY *)
ST PCP_CONNECT_1.ADD_ERROR
LD (* ANY *)
ST PCP_CONNECT_1.PARTNER
CAL PCP_CONNECT_1
LD PCP_CONNECT_1.VALID
ST (* BOOL *)
LD PCP_CONNECT_1.ERROR
ST (* BOOL *)
LD PCP_CONNECT_1.ADD_ERROR
ST (* ANY *)
LD PCP_CONNECT_1.PARTNER
ST (* ANY *)
LD PCP_CONNECT_1.ID
ST (* INT *)
ST
PCP_CONNECT_1(EN_C:=(* BOOL *),ADD_ERROR:=(* ANY *),
PARTNER:=(* ANY *));
(* BOOL *):= PCP_CONNECT_1.VALID;
(* BOOL *):= PCP_CONNECT_1.ERROR;
(* ANY *):= PCP_CONNECT_1.ADD_ERROR;
(* ANY *):= PCP_CONNECT_1.PARTNER;
(* INT *):= PCP_CONNECT_1.ID;
FBD

5958B 17-13
PROGRAM WORX

17.5 PCP_READ

The PCP_READ block enables you to read data from the PCP device ob-
jects.

Parameter Data types Description


REQ BOOL REQ stands for REQUEST. This input enables you to start the
(Input) block or prepare it for re-start.
Rising Edge (0,1) = The block is being started.
Falling Edge (1,0) = The block is being prepared for re-start.
ID INT This parameter indicates a communication connection. The ID
(Input) parameter helps you to distinguish between several existing
communication connections. ID is only valid if the VALID para-
meter value of the PCP_CONNECT block is TRUE.
ADD_ERROR ANY If an error occurs, the error code is in ADD_ERROR. The error
(Input/Output) (VAR_IN_OUT) codes are PCP error messages. These are described in the
PCP manual. The minimal array length in ADD_ERROR is two
words or four bytes. You must connect ADD_ERROR to a sui-
table variable. If the format is incorrect, the block will return an
error (ERROR=TRUE).

Note:
The error codes saved in ADD_ERROR are only valid in the
cycle in which ERROR changes from FALSE to TRUE.
VAR_1 ANY This parameter indicates the object or control variable to be
(Input/Output) (VAR_IN_OUT) read.
If you want to read a PCP device object, VAR_1 is an ARRAY
OF WORD data type with the index of the PCP object in the
first word and the subindex in the second word.
If you read a variable from the control, this variable is addres-
sed through the ID Input and VAR_1 is a STRING data type.

17-14 5958B
IB Communication Blocks

Parameter Data types Description


NDR BOOL This output (New Data Received) shows you the availability of
(Output) the data read in the RD_1 receive buffer with a rising edge.
With NDR=TRUE, you can read the data from the receive buf-
fer.

Note:
The data saved in RD_1 is only valid in the cycle in which NDR
changes from FALSE to TRUE.
RD_1 ANY RD_1 is the block’s receive buffer. The data can be of any pre-
(Input/Output) (VAR_IN_OUT) defined data type or user defined. The block can only receive
all data correctly, if the variable connected to RD_1 is greater
than or equal to the number of the data received.
ERROR BOOL With a rising edge, this output indicates that an error has oc-
(Output) curred. You can read the error code from ADD_ERROR during
the cycle in which the rising edge occurs.
DATA_CNT INT DATA_CNT displays the number of data bytes read in the
(Output) RD_1 receive buffer.

5958B 17-15
PROGRAM WORX

Representation
IL
LD (* BOOL *)
ST PCP_READ_1.REQ
LD (* INT *)
ST PCP_READ_1.ID
LD (* ANY *)
ST PCP_READ_1.ADD_ERROR
LD (* ANY *)
ST PCP_READ_1.VAR_1
LD (* ANY *)
ST PCP_READ_1.RD_1
CAL PCP_READ_1
LD PCP_READ_1.NDR
ST (* BOOL *)
LD PCP_READ_1.DATA_CNT
ST (* INT *)
LD PCP_READ_1.ERROR
ST (* BOOL *)
LD PCP_READ_1.ADD_ERROR
ST (* ANY *)
LD PCP_READ_1.VAR_1
ST (* ANY *)
LD PCP_READ_1.RD_1
ST (* ANY *)

ST
PCP_READ_1(REQ:=(* BOOL *),ID:=(* INT *),ADD_ERROR:=(* ANY *),
VAR_1:=(* ANY *),RD_1:=(* ANY *));
(* BOOL *):= PCP_READ_1.NDR;
(* INT *):= PCP_READ_1.DATA_CNT;
(* BOOL *):= PCP_READ_1.ERROR;
(* ANY *):= PCP_READ_1.ADD_ERROR;
(* ANY *):= PCP_READ_1.VAR_1;
(* ANY *):= PCP_READ_1.RD_1;

17-16 5958B
IB Communication Blocks

FBD

5958B 17-17
PROGRAM WORX

17.6 PCP_SERVER

This block enables you to receive PCP services (indications) and send their
responses.

Parameter Data types Description


EN_R BOOL EN_R stands for "Enable Receive" and is used to enable the
(Input) block. With EN_R = TRUE, the block can receive indications.
With EN_R = FALSE, the block rejects the indications.
RSP BOOL This input is used to start the transmission of the response
(Input) contained in the SD_1 send buffer.
ID INT This parameter indicates a communication connection. The ID
(Input) parameter helps you to distinguish between several existing
communication connections. ID is only valid if the VALID para-
meter value of the PCP_CONNECT block is TRUE.
RD_1 ANY RD_1 is the block’s receive buffer. The data can be ARRAY
(Input/Output) (VAR_IN_OUT) OF BYTE or ARRAY OF WORD types or user defined. The re-
ceive buffer is used for receiving the indication (including mes-
sage code and parameter count).
SD_1 ANY SD_1 the block’s send buffer. You must transfer the request of
(Input/Output) (VAR_IN_OUT) the PCP service you wish to use according to its predefined ar-
rangement (including service code and parameter count) to
the send buffer. The data can be ARRAY OF BYTE or ARRAY
OF WORD types or user defined.
Please refer to the PCP documentation (IBS SYS PCP G4
UM) to see the arrangement and parameters of the PCP ser-
vice you want to use.
VAR_1 ANY This parameter indicates the object to be received.
(Input/Output) (VAR_IN_OUT)
If you want to receive a PCP device object, VAR_1 is an
ARRAY OF WORD data type with the index of the PCP object
in the first word and the subindex in the second word.

17-18 5958B
IB Communication Blocks

Parameter Data types Description


NDR BOOL This output (New Data Received) shows you the availability of
(Output) the data read in the RD_1 receive buffer with a rising edge.
With NDR=TRUE, you can read the data from the receive buf-
fer.

Note:
The data saved in RD_1 is only valid in the cycle in which NDR
changes from FALSE to TRUE.
ADD_ERROR ANY If an error occurs, the error code is in ADD_ERROR. The error
(Input/Output) (VAR_IN_OUT) codes are PCP error messages. These are described in the
PCP manual. The minimal array length in ADD_ERROR is two
words or four bytes. You must connect ADD_ERROR to a sui-
table variable. If the format is incorrect, the block will return an
error (ERROR=TRUE).

Note:
The error codes saved in ADD_ERROR are only valid in the
cycle in which ERROR changes from FALSE to TRUE.
ERROR BOOL With a rising edge, this output indicates that an error has oc-
(Output) curred. You can read the error code from ADD_ERROR during
the cycle in which the rising edge occurs.

5958B 17-19
PROGRAM WORX

Representation
IL

LD (* BOOL *)
ST PCP_SERVER_1.EN_R
LD (* BOOL *)
ST PCP_SERVER_1.RSP
LD (* INT *)
ST PCP_SERVER_1.ID
LD (* ANY *)
ST PCP_SERVER_1.ADD_ERROR
LD (* ANY *)
ST PCP_SERVER_1.VAR_1
LD (* ANY *)
ST PCP_SERVER_1.SD_1
LD (* ANY *)
ST PCP_SERVER_1.RD_1
CAL PCP_SERVER_1
LD PCP_SERVER_1.NDR
ST (* BOOL *)
LD PCP_SERVER_1.ERROR
ST (* BOOL *)
LD PCP_SERVER_1.ADD_ERROR
ST (* ANY *)
LD PCP_SERVER_1.VAR_1
ST (* ANY *)
LD PCP_SERVER_1.SD_1
ST (* ANY *)
LD PCP_SERVER_1.RD_1
ST (* ANY *)

17-20 5958B
IB Communication Blocks

ST
PCP_SERVER_1(EN_R:=(* BOOL *),RSP:=(* BOOL *),ID:=(* INT *),
ADD_ERROR:=(* ANY *),VAR_1:=(* ANY *),SD_1:=(* ANY *),
RD_1:=(* ANY *));
(* BOOL *):= PCP_SERVER_1.NDR;
(* BOOL *):= PCP_SERVER_1.ERROR;
(* ANY *):= PCP_SERVER_1.ADD_ERROR;
(* ANY *):= PCP_SERVER_1.VAR_1;
(* ANY *):= PCP_SERVER_1.SD_1;
(* ANY *):= PCP_SERVER_1.RD_1;
FBD

5958B 17-21
PROGRAM WORX

17.7 PCP_WRITE

The PCP_WRITE block enables you to write data to the PCP device ob-
jects.

Parameter Data types Description


REQ BOOL REQ stands for REQUEST. This input enables you to start the
(Input) block or prepare it for re-start.
Rising Edge (0,1) = The block is being started.
Falling Edge (1,0) = The block is being prepared for re-start.
ID INT This parameter indicates a communication connection. The ID
(Input) parameter helps you to distinguish between several existing
communication connections. ID is only valid if the VALID para-
meter value of the PCP_CONNECT block is TRUE.
DATA_CNT INT DATA_CNT displays the number of data bytes to be sent in the
(Output) SD_1 output buffer.
VAR_1 ANY This parameter indicates the PCP object or control variable to
(Input/Output) (VAR_IN_OUT) be written.
If you want to write to a PCP device object, VAR_1 is an
ARRAY OF WORD data type with the index of the PCP object
in the first word and the subindex in the second word.
If you write a variable to the control, this variable is addressed
through the ID input and VAR_1 is a STRING data type.

Note:
The error codes saved in ADD_ERROR are only valid in the
cycle in which ERROR changes from FALSE to TRUE.
SD_1 ANY SD_1 is the block’s send buffer. The data can be of any prede-
(Input/Output) fined data type or user defined. The block can only send all
data correctly, if the variable connected to SD_1 is greater
than or equal to the number of the data to be sent.
DONE BOOL With a rising edge, this output indicates that the data has been
(Output) successfully written from the SD_1 send buffer either to the
PCP object specified in VAR_1 or to the variable.

17-22 5958B
IB Communication Blocks

Parameter Data types Description


ERROR BOOL With a rising edge, this output indicates that an error has oc-
(Output) curred. You can read the error code from ADD_ERROR during
the cycle in which the rising edge occurs.
ADD_ERROR ANY If an error occurs, the error code is in ADD_ERROR. The error
(Input/Output) (VAR_IN_OUT) codes are PCP error messages. These are described in the
PCP manual. The minimal array length in ADD_ERROR is two
words or four bytes. You must connect ADD_ERROR to a sui-
table variable. If the format is incorrect, the block will return an
error (ERROR=TRUE).

Representation
IL
LD (* BOOL *)
ST PCP_WRITE_1.REQ
LD (* INT *)
ST PCP_WRITE_1.ID
LD (* INT *)
ST PCP_WRITE_1.DATA_CNT
LD (* ANY *)
ST PCP_WRITE_1.ADD_ERROR
LD (* ANY *)
ST PCP_WRITE_1.VAR_1
LD (* ANY *)
ST PCP_WRITE_1.SD_1
CAL PCP_WRITE_1
LD PCP_WRITE_1.DONE
ST (* BOOL *)
LD PCP_WRITE_1.ERROR
ST (* BOOL *)
LD PCP_WRITE_1.ADD_ERROR
ST (* ANY *)
LD PCP_WRITE_1.VAR_1
ST (* ANY *)
LD PCP_WRITE_1.SD_1
ST (* ANY *)

5958B 17-23
PROGRAM WORX

ST
PCP_WRITE_1(REQ:=(* BOOL *),ID:=(* INT *),DATA_CNT:=(* INT *),
ADD_ERROR:=(* ANY *),VAR_1:=(* ANY *),SD_1:=(* ANY *));
(* BOOL *):= PCP_WRITE_1.DONE;
(* BOOL *):= PCP_WRITE_1.ERROR;
(* ANY *):= PCP_WRITE_1.ADD_ERROR;
(* ANY *):= PCP_WRITE_1.VAR_1;
(* ANY *):= PCP_WRITE_1.SD_1;

FBD

17-24 5958B
IB Communication Blocks

17.8 *_TO_BUF

Description This ProConOS function block allows to copy elementary data types from
a variable, an array or elements of a user-defined structure to a byte st-
ream. INTEL or MOTOROLA format is possible for the byte stream. There-
fore an automatic data format conversion is supported. So this function
block is useful for the data transfer or the communication among applicati-
ons which are executed on different hardware platforms (INTEL or MOTO-
ROLA).
’ * ’ is a place-marker for the supported data types. The FB is available for
the data types BYTE, WORD, DWORD, SINT, INT, DINT, TIME, REAL,
STRING.

Operation
For the data type STRING the operation is different to the following descri-
bed. For information about the handling of the STRING_TO_BUF function
block click here.
After a rising edge has been put to the parameter REQ the copy process
starts. As defined in the parameter BUF_FORMAT the data are converted
into INTEL or MOTOROLA format. The size of the destination BUFFER is
checked before copying.
After the copy process has finished correctly, the output parameter DONE
is set to ’TRUE’. In case of any occurred errors the parameter ERROR is
set to ’TRUE’ and the parameter STATUS gets a value unequal to zero
which represent the current error message. These values are kept as long
as a falling edge is put to the parameter REQ. A new rising edge to the pa-
rameter REQ starts a new copy process.
It is not allowed to use the same addresses for the source and the destina-
tion!

Parameter Data types Description


REQ BOOL a rising edge starts the copy ac-
tion of the function block
BUF_FORMAT BOOL a value of TRUE indicates that
the buffer data are in MOTO-
ROLA format, whereas a value
of FALSE indicates that the buf-
fer data are in INTEL format

5958B 17-25
PROGRAM WORX

Parameter Data types Description


BUF_OFFS DINT byte address in the buffer
BUF_CNT DINT amount of bytes to be copied
SRC * or ARRAY_OF_* source array or variable of stan-
dard data type *
BUFFER ANY destination array (byte stream)
DONE BOOL a value of ’TRUE’ indicates that
the data are copied
ERROR BOOL a value of ’TRUE’ indicates an
occurred error
STATUS INT indicates the status of the copy
process.

Example Variable declaration:


TYPE
dtStruct :
STRUCT
byteElem : BYTE;
wordElem : WORD;
END_STRUCT;
END_TYPE
TYPE
BYTE_ARRAY : ARRAY[0..200] OF BYTE;
END_TYPE
VAR_GLOBAL
byteStream : BYTE_ARRAY;
END_VAR
VAR
ReqByte : BOOL;
DoneByte : BOOL;

17-26 5958B
IB Communication Blocks

ErrorByte : BOOL;
StateByte : INT;
FormatByte : BOOL;
OffsetByte : DINT;
LengthByte : DINT:= 1;
byteElem : BYTE := 16#ab;
BYTE_TO_BUF_1 : BYTE_TO_BUF;
data : dtStruct;
END_VAR
VAR_EXTERNAL
byteStream : BYTE_ARRAY;
END_VAR

Code body declaration:

A structure element ’data.byteElem’ is used in this example. At first the


value to be copied had to be assigned from the variable ’byteElem’ to the
structure element. Of course it is possible to use the variable ’byteElem’ as
well as the SRC.
After a rising edge has been put to the parameter REQ the copy process
starts. The result is that ’TRUE’ is written to the variable ’DoneByte’ if the
writing process is finished and the value ’AB’ is copied from the SRC struc-
ture element ’data.byteElem’ to the DST ’byteStream’.

5958B 17-27
PROGRAM WORX

Variables VAR
declaration
BYTE_TO_BUF_1 : BYTE_TO_BUF;
END_VAR
Function blocks have to be instantiated. The instance name can be any
name of your choice. It must be unique within the POU. In the example the
instance name ’BYTE_TO_BUF’ is used.

Timing diagram

17-28 5958B
IB Communication Blocks

Representation
IL

Example for function block BYTE_TO_BUF

LD (* BOOL *)
ST BYTE_TO_BUF_1.REQ
LD (* BOOL *)
ST BYTE_TO_BUF_1.BUF_FORMAT
LD (* DINT *)
ST BYTE_TO_BUF_1.BUF_OFFS
LD (* DINT *)
ST BYTE_TO_BUF_1.BUF_CNT
LD (* ANY *)
ST BYTE_TO_BUF_1.SRC
LD (* ANY *)
ST BYTE_TO_BUF_1.BUFFER
CAL BYTE_TO_BUF_1
LD BYTE_TO_BUF_1.DONE
ST (* BOOL *)
LD BYTE_TO_BUF_1.ERROR
ST (* BOOL *)
LD BYTE_TO_BUF_1.STATUS
ST (* INT *)
LD BYTE_TO_BUF_1.SRC
ST (* ANY *)
LD BYTE_TO_BUF_1.BUFFER
ST (* ANY *)

5958B 17-29
PROGRAM WORX

ST

Example for function block BYTE_TO_BUF

BYTE_TO_BUF_1(REQ:=(* BOOL *),BUF_FORMAT:=(* BOOL *),


BUF_OFFS:=(* DINT *),BUF_CNT:=(* DINT *),
SRC:=(* ANY *),BUFFER:=(* ANY *));
(* BOOL *):= BYTE_TO_BUF_1.DONE;
(* BOOL *):= BYTE_TO_BUF_1.ERROR;
(* INT *):= BYTE_TO_BUF_1.STATUS;
(* ANY *):= BYTE_TO_BUF_1.SRC;
(* ANY *):= BYTE_TO_BUF_1.BUFFER;

FBD
Example for function block BYTE_TO_BUF

17-30 5958B
IB Communication Blocks

17.8.1 Possible status of the copy process for


*_TO_BUF function blocks

The following status of the copy process are possible:

Table 17-2 Possible status of the copy process for *_TO_BUF function
blocks

Status number Description


0 The copy process has been finished correctly.
1 The VAR_IN_OUT descriptors used for the parame-
ter SRC and BUFFER are invalid. This is an internal
error.
2 The length of the source buffer does not fit. The size
of bytes to be copied assigned in BUF_CNT is larger
than the available size of the SRC.
3 The length of the destination buffer does not fit. The
sum of the bytes to be copied assigned in BUF_CNT
and the offset in the connected byte stream assigned
in BUF_OFFS is larger than the size of the connec-
ted byte stream.
4 This data type is not supported.
5 The alignment does not fit to this data type. The size
to be copied assigned in BUF_CNT must be divisible
by the size of the data type without a rest.
6 The conversion INTEL/MOTOROLA has failed.
7 The string length does not fit. Additional checks are
necessary for the data type string. This is described
in the chapter ’String specialties’.
8 The destination buffer has a wrong data type. In
some cases the data type is checked. This is descri-
bed in the special chapter for each data type.

5958B 17-31
PROGRAM WORX

Table 17-2 Possible status of the copy process for *_TO_BUF function
blocks

Status number Description


9 The offset value is not correct. In some cases the off-
set is checked. This is described in the special chap-
ter for each data type.
10 The BUF_CNT does not fit. In some cases the size
to be copied is checked. This is described in the spe-
cial chapter for each data type.
11 The addresses of the source and the destination are
the same.

17.8.2 String specialties of the function block


STRING_TO_BUF

For the data type STRING the handling is different to the general handling
of the other data types. If a string is connected to the parameter BUFFER,
it is assumed that this string is a ProConOS formatted string having a 4 byte
header and a terminating zero character. In case of a format change (IN-
TEL or MOTOROLA) this header is converted; whereas variables, having
other data types like an array of BYTE or WORD connected to the parame-
ter BUFFER indicate that this string is a C string without a header. This
string must also be terminated with a zero.
For the data type STRING the size to be copied assigned in BUF_CNT is
limited to 32767 bytes because of the STRING length allowed at most. In
case of a larger size the parameter ERROR is set to ’TRUE’ and the para-
meter STATUS gets the value ’10’.
If the source STRING has less characters than requested by the parameter
BUF_CNT, only the available characters are copied to the destination and
the rest is filled up with zeros. One terminating zero character is set at the
end of the copied characters every time.
If the destination byte stream is not a STRING, the necessary free memory
in the destination consists of the bytes to be copied, the offset in the desti-
nation and the terminating zero character. If the destination is less than ne-
cessary, the parameter ERROR is set to ’TRUE’ and the parameter STA-
TUS gets the value ’7’.

17-32 5958B
IB Communication Blocks

If the destination byte stream is a STRING, the necessary free memory in


the destination consists of the bytes to be copied, the offset in the destina-
tion, the size of the string header and the terminating zero character. If the
destination is less than necessary, the parameter ERROR is set to ’TRUE’
and the parameter STATUS gets the value ’7’.

17.9 BUF_TO_*

Description This ProConOS function block allows to copy elementary data types from
a byte stream to a variable, an array or elements of a user-defined struc-
ture. INTEL or MOTOROLA format is possible for the byte stream. There-
fore an automatic data format conversion is supported. So this function
block is useful for the data transfer or the communication among applicati-
ons which are executed on different hardware platforms (INTEL or MOTO-
ROLA).).
’ * ’ is a place-marker for the supported data types. The FB is available for
the data types BYTE, WORD, DWORD, SINT, INT, DINT, TIME, REAL,
STRING.

Operation
For the data type STRING the operation is different to the following descri-
bed. For information about the handling of the BUF_TO_STRING function
block click here.
After a rising edge has been put to the parameter REQ the copy process
starts. As defined in the parameter BUF_FORMAT the data are converted
into INTEL or MOTOROLA format. The size of the destination DST is chek-
ked before copying.
After the copy process has finished correctly, the output parameter DONE
is set to ’TRUE’. In case of any occurred errors the parameter ERROR is
set to ’TRUE’ and the parameter STATUS gets a value unequal to zero
which represent the current error message. These values are kept as long
as a falling edge is put to the parameter REQ. A new rising edge to the pa-
rameter REQ starts a new copy process.
It is not allowed to use the same addresses for the source and the destina-
tion!

5958B 17-33
PROGRAM WORX

Parameter Data types Description


REQ BOOL a rising edge starts the copy ac-
tion of the function block
BUF_FORMAT BOOL a value of TRUE indicates that
the buffer data are in MOTO-
ROLA format, whereas a value
of FALSE indicates that the buf-
fer data are in INTEL format
BUF_OFFS DINT byte address in the buffer
BUF_CNT DINT amount of bytes to be copied
BUFFER ANY source array (byte stream)
DST * or ARRAY_OF_* destination array or variable of
standard data
type *
DONE BOOL a value of ’TRUE’ indicates that
the data are copied
ERROR BOOL a value of ’TRUE’ indicates an
occurred error
STATUS INT indicates the status of the copy
process. For a detailed descrip-
tion of the possible status click
here.

Example Variable declaration:


TYPE
dtStruct :
STRUCT
byteElem : BYTE;
wordElem : WORD;
END_STRUCT;
END_TYPE

17-34 5958B
IB Communication Blocks

TYPE
BYTE_ARRAY : ARRAY[0..200] OF BYTE;
END_TYPE
VAR_EXTERNAL
byteStream : BYTE_ARRAY;
END_VAR
VAR
ReqByte : BOOL;
DoneByte : BOOL;
ErrorByte : BOOL;
StateByte : INT;
FormatByte : BOOL;
OffsetByte : DINT;
LengthByte : DINT := 1;
byteElem : BYTE;
data : dtStruct;
BUF_TO_BYTE_1 : BUF_TO_BYTE;
END_VAR

Code body declaration:

After a rising edge has been put to the parameter REQ the copy process
starts. The result is that ’TRUE’ is written to the variable ’DoneByte’ if the
writing process has finished and the value ’AB’ is copied from the SRC ’by-
teStream’ to the DST structure element ’data.byteElem’.
In order to show the DST value directly (without the watchlist) it is possible
to assign the structure element to the variable ’byteElem’. Of course it is
possible to use the variable ’byteElem’ as well as the DST.

5958B 17-35
PROGRAM WORX

Variables VAR
declaration
BUF_TO_BYTE_1 : BUF_TO_BYTE;
END_VAR
Function blocks have to be instantiated. The instance name can be any
name of your choice. It must be unique within the POU. In the example the
instance name ’BUF_TO_BYTE’ is used.

Timing diagram

17-36 5958B
IB Communication Blocks

Representation
IL

Example for function block BUF_TO_BYTE

LD (* BOOL *)
ST BUF_TO_BYTE_1.REQ
LD (* BOOL *)
ST BUF_TO_BYTE_1.BUF_FORMAT
LD (* DINT *)
ST BUF_TO_BYTE_1.BUF_OFFS
LD (* DINT *)
ST BUF_TO_BYTE_1.BUF_CNT
LD (* ANY *)
ST BUF_TO_BYTE_1.BUFFER
LD (* ANY *)
ST BUF_TO_BYTE_1.DST
CAL BUF_TO_BYTE_1
LD BUF_TO_BYTE_1.DONE
ST (* BOOL *)
LD BUF_TO_BYTE_1.ERROR
ST (* BOOL *)
LD BUF_TO_BYTE_1.STATUS
ST (* INT *)
LD BUF_TO_BYTE_1.BUFFER
ST (* ANY *)
LD BUF_TO_BYTE_1.DST
ST (* ANY *)

5958B 17-37
PROGRAM WORX

ST

Example for function block BUF_TO_BYTE

BUF_TO_BYTE_1(REQ:=(* BOOL *),BUF_FORMAT:=(* BOOL *),


BUF_OFFS:=(* DINT *),BUF_CNT:=(* DINT *),
BUFFER:=(* ANY *),DST:=(* ANY *));
(* BOOL *):= BUF_TO_BYTE_1.DONE;
(* BOOL *):= BUF_TO_BYTE_1.ERROR;
(* INT *):= BUF_TO_BYTE_1.STATUS;
(* ANY *):= BUF_TO_BYTE_1.BUFFER;
(* ANY *):= BUF_TO_BYTE_1.DST;

FBD
Example for function block BUF_TO_BYTE

17-38 5958B
IB Communication Blocks

17.9.1 Possible status of the copy process for


BUF_TO_* function blocks

The following status of the copy process are possible:

Table 17-3 Possible status of the copy process for BUF_TO_* function
blocks

Status number Description


0 The copy process is finished correctly.
1 The VAR_IN_OUT descriptors used for the parame-
ter DST and BUFFER are invalid. This is an internal
error.
2 The length of the source buffer does not fit. The size
of bytes to be copied assigned in BUF_CNT is larger
than the available size of the SRC.
3 The length of the destination buffer does not fit. The
sum of the bytes to be copied assigned in BUF_CNT
and the offset in the connected byte stream assigned
in BUF_OFFS is larger than the size of the connected
byte stream.
4 This data type is not supported.
5 The alignment does not fit to this data type. The size
to be copied assigned in BUF_CNT must be divisible
to the size of the data type without a rest.
6 The conversion INTEL/MOTOROLA has failed.
7 The string length does not fit. For the data type string
additional checks are necessary. This is described in
the chapter ’String specialties’.
8 The destination buffer has a wrong data type. In
some events the data type is checked. This is descri-
bed in the special chapter for each data type.
9 The offset value is not correct. In some events the off-
set is checked. This is described in the special chap-
ter for each data type.

5958B 17-39
PROGRAM WORX

Table 17-3 Possible status of the copy process for BUF_TO_* function
blocks

Status number Description


10 The BUF_CNT does not fit. In some events the size
to be copied is checked. This is described in the spe-
cial chapter for each data type.
11 The addresses of the source and the destination are
the same.

17.9.2 String specialties of the function block


BUF_TO_STRING

For the data type STRING the handling is different to the general handling
of the other data types. If a string is connected to the parameter BUFFER,
it is assumed that this string is a ProConOS formatted string having a 4 byte
header and a terminating zero character. In case of a format change (IN-
TEL or MOTOROLA) this header is converted; whereas variables, having
other data types like an array of BYTE or WORD connected to the parame-
ter BUFFER indicate that this string is a C string without a header. This
string must also be terminated with a zero.
For the data type STRING the size to be copied assigned in BUF_CNT is
limited to 32767 bytes because of the STRING length allowed at most. In
case of a larger size the parameter ERROR is set to ’TRUE’ and the para-
meter STATUS gets the value ’10’.
If the destination data type is not a STRING, the parameter ERROR is set
to ’TRUE’ and the parameter STATUS gets the value ’8’.
The necessary free memory in the destination string only consists of the
bytes to be copied. If the destination string is less than necessary, the pa-
rameter ERROR is set to ’TRUE’ and the parameter STATUS gets the
value ’7’.
If the source is not a STRING, the requested data are copied and a termi-
nating zero character is set at the end of the copied characters.
If the source is a STRING and an offset is declared in the parameter
BUF_OFFS, the parameter ERROR is set to ’TRUE’ and the parameter
STATUS gets the value ’9’. If no offset is declared it is checked whether the
requested data are available in the source string. Only the available data
or the requested data if lower than the available size are copied and a ter-
minating zero character is set at the end of the copied characters.

17-40 5958B
Section 18
This section provides information on
– how to use TCP/IP Communication Blocks

TCP/IP Communication Blocks† .........................................................................18-3


18.1 Overview ...................................................................................18-3
18.2 IP_CONNECT ...........................................................................18-4
18.3 IP_URCV...................................................................................18-6
18.4 IP_USEND ................................................................................18-8
18.5 IP_TIME ..................................................................................18-10
18.6 Error Codes.............................................................................18-13

†. Extended functions going beyond the standard functional range of the IEC 61131-3.

5958B 18-1
18-2 5958B
TCP/IP Communication Blocks

18 TCP/IP Communication Blocks

18.1 Overview

TCP/IP communication blocks are designed to enable a number of ETH


controller boards to communicate with each other via an TCP/IP connec-
tion.
You can establish communication links, transmit and receive data via TCP/
IP and use the system time of one ETH controller board to synchronize
other ETH controller boards.
The communication between the Ethernet controller boards is peer to peer.
The blocks IP_CONNECT, IP_URCV and IP_USEND comply with the spe-
cifications for blocks in IEC 61131-5.
The IP_TIME block is not IEC 61131-5 compliant and requires special ope-
ration.
You can only use TCP/IP communication blocks on ETH controller boards
that are running firmware version ≥ 4.4a and PC WORX 2.0.
The following TCP/IP Communication Blocks are available:

Table 18-1 TCP/IP Communication Blocks

Function Short description


IP_CONNECT† Block for establishing an TCP/IP connection bet-
ween two ETH controller boards.
IP_URCV† Block for receiving data from an ETH controller board
via an TCP/IP connection.
IP_USEND† Block for transmitting data to an ETH controller board
via an TCP/IP connection.
IP_TIME† Block for synchronizing system time and system date
of ETH controller boards via an TCP/IP connection.
† Extended functions going beyond the standard functional range of
the IEC 61131-3.

5958B 18-3
PROGRAM WORX

18.2 IP_CONNECT

Description This block enables you to establish an TCP/IP connection between two
ETH controller boards.

Parameter Data type Description


EN_C BOOL If you set this input to "TRUE", the block will attempt to establish a
connection with the IP address specified in "PARTNER". However, it
will only be possible to establish the connection if you call up the block
at both communications partners, so that both partners are requesting
a communications link.
PARTNER STRING With this input, you specify the ETH controller board with which you
wish to communicate. To do this, you must enter the IP address of the
"Partner" and some optional parameters.
Use syntax as follows (example):
/IP=172.16.100.35 /CONTO=2500 /SNTO=750 /RCVTO=5000
Note capitalization and do not insert more than one space between
the parameters.

Parameter:
CONTO Connect-Timeout Default: 2500 ms
SNTO Send-Timeout Default: 750 ms
RCVTO Receive-Timeout Default: 5000 ms
If you do not specify any parameters, the defaults will be applied.
VALID BOOL This output shows you whether a valid communication link has been
established with an ETH controller board. The output remains "TRUE"
as long as the link exists.
ERROR BOOL This output indicates with a rising edge that an error has occurred.
You can read the error code at the "STATUS" output during the cycle
in which the rising edge occurs.
STATUS INT You can read the Error codes for the function block at the "STATUS"
output.
ID INT This parameter provides unique identification for a communication
link. Where more than one communication link exists, you can use the
ID parameter to distinguish between them. ID is only valid if the
VALID parameter is set to TRUE.

18-4 5958B
TCP/IP Communication Blocks

Representation
IL

LD (* BOOL *)
ST IP_CONNECT_1.EN_C
LD (* STRING *)
ST IP_CONNECT_1.PARTNER
CAL IP_CONNECT_1
LD IP_CONNECT_1.VALID
ST (* BOOL *)
LD IP_CONNECT_1.ERROR
ST (* BOOL *)
LD IP_CONNECT_1.STATUS
ST (* INT *)
LD IP_CONNECT_1.ID
ST (* INT *)

ST

IP_CONNECT_1(EN_C:=(* BOOL *),PARTNER:=(* STRING *));


(* BOOL *):= IP_CONNECT_1.VALID;
(* BOOL *):= IP_CONNECT_1.ERROR;
(* INT *):= IP_CONNECT_1.STATUS;
(* INT *):= IP_CONNECT_1.ID;

FBD

5958B 18-5
PROGRAM WORX

18.3 IP_URCV

Description This block enables you to receive data from an ETH controller board via an
TCP/IP connection.

Parameter Data type Description


EN_R BOOL Use this input to prepare the block to receive data.
EN_R = TRUE Data can be received.
EN_R = FALSE Data cannot be received.
ID INT When the "IP_CONNECT" block is used to establish the connection,
a unique ID is assigned to each communication link. You use this ID
to specify to the receiving block "IP_URCV" the communication de-
vice from which you wish to receive data. You can connect the "ID"
input directly with the "ID" output from the "IP_CONNECT" block.
R_ID STRING Since you can use multiple transmit and receive blocks in a commu-
nications link (using the ID for addressing purposes), you need an
input that allows you to specify the assignment of transmit block to re-
ceive block. The value you enter for this input is freely definable but
must not exceed 80 characters. Enter the value at the "R_ID" input of
this block and at the "R_ID" input of the "IP_USEND" transmit block
on the communicating ETH controller board.
NDR BOOL This output shows you whether the block has successfully received
all transmitted data. You can only evaluate the success of the trans-
mission during the cycle in which the rising edge occurs at this output.
ERROR BOOL This output indicates with a rising edge that an error has occurred.
You can read the error code at the "STATUS" output during the cycle
in which the rising edge occurs.
STATUS INT You can read the Error codes for the block at the "STATUS" output.
RD_1 ANY This input/output is the block’s receive buffer. The size of the variable
at the receive buffer "RD_1" must match the size of the variable at the
transmit buffer "SD_1" of the corresponding "IP_USEND" block. The
largest permissible size of the transmit/receive buffer is 32 kByte. The
size and name of the variable at "RD_1" must not be changed while
the block is in use.

18-6 5958B
TCP/IP Communication Blocks

Representation
IL
LD (* BOOL *)
ST IP_URCV_1.EN_R
LD (* INT *)
ST IP_URCV_1.ID
LD (* STRING *)
ST IP_URCV_1.R_ID
LD (* ANY *)
ST IP_URCV_1.RD_1
CAL IP_URCV_1
LD IP_URCV_1.NDR
ST (* BOOL *)
LD IP_URCV_1.ERROR
ST (* BOOL *)
LD IP_URCV_1.STATUS
ST (* INT *)
LD IP_URCV_1.RD_1
ST (* ANY *)

ST
IP_URCV_1(EN_R:=(* BOOL *),ID:=(* INT *),R_ID:=(* STRING *),
RD_1:=(* ANY *));
(* BOOL *):= IP_URCV_1.NDR;
(* BOOL *):= IP_URCV_1.ERROR;
(* INT *):= IP_URCV_1.STATUS;
(* ANY *):= IP_URCV_1.RD_1;

FBD

5958B 18-7
PROGRAM WORX

18.4 IP_USEND

Description This block enables you to transmit data to an ETH controller board via an
TCP/IP connection. Before you can transmit data, you must establish a
communications link with another ETH controller board using the
"IP_CONNECT" block.

Parameter Data type Description


REQ BOOL With a positive edge at this input, you trigger the data transmission.
The block is locked for the duration of the transmission and you
cannot interrupt or reset it.
ID INT When the "IP_CONNECT" block is used to establish the connection,
a unique ID is assigned to each communications link. You use this ID
to specify to the transmit block "IP_USEND" the communication de-
vice to which you wish to transmit data. You can connect the "ID" input
directly with the "ID" output from the "IP_CONNECT" block.
R_ID STRING Since you can use multiple transmit and receive blocks in a commu-
nications link (using the ID for addressing purposes), you need an
input that allows you to specify the assignment of transmit block to re-
ceive block. The value you enter for this input is freely definable but
must not exceed 80 characters. Enter the value at the "R_ID" input of
this block and at the "R_ID" input of the "IP_URCV" receive block on
the communicating ETH controller board.
DONE BOOL This output shows you whether the block has transmitted all data
completely and successfully. You can only evaluate the success of the
transmission during the cycle in which the rising edge occurs at this
output.
ERROR BOOL This output indicates with a rising edge that an error has occurred.
You can read the error code at the "STATUS" output during the cycle
in which the rising edge occurs.
STATUS INT You can read the Error codes for the block at the "STATUS" output.
SD_1 ANY This input/output is the block’s transmit buffer. The size of the variable
at the transmit buffer "SD_1" must match the size of the variable at
the receive buffer "RD_1" of the corresponding "IP_URCV" block. The
largest permissible size of the transmit/receive buffer is 32 kByte. The
size and name of the variable at "SD_1" must not be changed while
the block is in use.

18-8 5958B
TCP/IP Communication Blocks

Representation
IL
LD (* BOOL *)
ST IP_USEND_1.REQ
LD (* INT *)
ST IP_USEND_1.ID
LD (* STRING *)
ST IP_USEND_1.R_ID
LD (* ANY *)
ST IP_USEND_1.SD_1
CAL IP_USEND_1
LD IP_USEND_1.DONE
ST (* BOOL *)
LD IP_USEND_1.ERROR
ST (* BOOL *)
LD IP_USEND_1.STATUS
ST (* INT *)
LD IP_USEND_1.SD_1
ST (* ANY *)

ST
IP_USEND_1(REQ:=(* BOOL *),ID:=(* INT *),R_ID:=(* STRING *),
SD_1:=(* ANY *));
(* BOOL *):= IP_USEND_1.DONE;
(* BOOL *):= IP_USEND_1.ERROR;
(* INT *):= IP_USEND_1.STATUS;
(* ANY *):= IP_USEND_1.SD_1;

FBD

5958B 18-9
PROGRAM WORX

18.5 IP_TIME

Description This block allows you to effect cyclical synchronization of system time/sy-
stem date for ETH controller boards via an TCP/IP connection.
You can configure the block either as a server or a client. The server
functions as a time server and a reference for the clients’ system time and
date.
Only one "IP_TIME" block may be used on an ETH controller board.

Parameter Data type Description


TIMER INT With the value at this input, you specify the intervals at which the sy-
stem time and date are to be synchronized. You must specify a value
in seconds and you can change it while the block is in use.
If you enter "0" at this input, the block is configured as a server.
STATE INT This output allows you to see whether a connection with the server has
been established.
The following values are possible:
0 The block is in start-up mode or is attempting to establish a con-
nection with the server. The "TIME_OUT" output contains local
time.
16 Connection with the server has been established. The
"TIME_OUT" output contains the time synchronized with the ser-
ver.
32 The block itself is configured as the server or there is no connec-
tion with the server The "TIME_OUT" output contains local time.
TIME_OUT STRING This input/output contains the system time/system date in the following
format:
YYYY-MM-DD-HH:MM:SS.SSS

Example:
The string "1999-06-18-07:05:06.000" represents June 18 1999 at 7:05
(a.m.) and 6 and 000 thousandths of a second.
TIME_RCV BOOL You will see all successful time synchronizations on the rising edge of
the "TIME_RCV" output. This output remains "TRUE" for one cycle
only.

18-10 5958B
TCP/IP Communication Blocks

PARTNER STRING With this input/output, you specify the ETH controller board with which
you wish to synchronize the system date/system time. To do this, you
must enter the IP address of the "Partner" and some optional parame-
ters.
Use syntax as follows (example):
/IP=172.16.100.35 /SNTO=750
Note capitalization and do not insert more than one space between the
parameters.

Parameter:
SNTO Transmit Timeout Default: 750 ms
If you do not specify any parameters, the defaults will be applied.
If you have configured the block as a server, you do not need to specify
a value for the "PARTNER" input, since the connection is established
from the client.
If you have configured the block as a client, at the "PARTNER" input
you must enter the IP address of the server you wish to use to supply
the system time and system date.

Representation
IL
LD (* INT *)
ST IP_TIME_1.TIMER
LD (* STRING *)
ST IP_TIME_1.TIME_OUT
LD (* STRING *)
ST IP_TIME_1.PARTNER
CAL IP_TIME_1
LD IP_TIME_1.STATE
ST (* INT *)
LD IP_TIME_1.TIME_OUT
ST (* STRING *)
LD IP_TIME_1.TIME_RCV
ST (* BOOL *)
LD IP_TIME_1.PARTNER
ST (* STRING *)

5958B 18-11
PROGRAM WORX

ST
IP_TIME_1(TIMER:=(* INT *),TIME_OUT:=(* STRING *),
PARTNER:=(* STRING *));
(* INT *):= IP_TIME_1.STATE;
(* STRING *):= IP_TIME_1.TIME_OUT;
(* BOOL *):= IP_TIME_1.TIME_RCV;
(* STRING *):= IP_TIME_1.PARTNER;

FBD

18-12 5958B
TCP/IP Communication Blocks

18.6 Error Codes

The following error codes are used in the STATUS output:

Table 18-2 Error Codes

Error code Description Status only for:

0x0000 No error occurred.

0x0001 Creation of at least one task was unsuccessful

0x0002 Initialization of the socket interface unsuccessful (Win-


dows NT only).

0x0003 Dynamic memory could not be reserved. IP_USEND, IP_URCV,


IP_TIME, IP_CONNECT

0x0004 FB cannot be initialized because an error occurred du-


ring startup of the asynchronous communication task.

0x0010 Socket initialization unsuccessful.

0x0011 Error while transmitting a message.

0x0012 Error while receiving a message.

0x0013 Unknown service code in the telegram header.

0x0021 In valid condition switch while establishing a link. IP_CONNECT

0x0030 There are no more free channels available. IP_CONNECT

0x0031 Connection has been terminated. IP_CONNECT

0x0033 General timeout, receiver is no longer answering or the IP_USEND, IP_URCV


transmitter has not finished transmitting.

0x0034 Request for connection was denied. IP_CONNECT

0x0035 Receiver has not confirmed transmission, receiver may IP_USEND


be overloaded (repeat transmission).

0x0040 Partner string is too long (max. 255 characters). IP_CONNECT, IP_TIME

0x0041 The specified IP address is not valid or could not be in- IP_CONNECT, IP_TIME
terpreted correctly.

5958B 18-13
PROGRAM WORX

Table 18-2 Error Codes

Error code Description Status only for:

0x0050 Attempt to transmit using invalid link (transmitter or re- IP_USEND


ceiver) .

0x0061 Neg. confirmation by receiver. An incorrect sequence IP_USEND, IP_URCV


number has been used.

0x0062 Transmitter’s and receiver’s data types are not identical. IP_USEND, IP_URCV

0x0063 Receiver is not yet ready to receive (poss. cause: Re- IP_USEND
ceiver is disabled or is currently in transfer mode
(NDR=TRUE).

0x0064 No receiver block with the matching R_ID was found. IP_USEND

0x0070 Partner RFC was not configured as the time server.

18-14 5958B
Section 19
This section provides information on
– how to use the fast I/Os of the ILC 200 IB

Fast I/O Function Blocks for ILC 200 IB† ............................................................19-3


19.1 Overview ...................................................................................19-3
19.2 DIGITAL_IN...............................................................................19-5
19.3 DIGITAL_OUT...........................................................................19-7
19.4 DIO_CTU ..................................................................................19-9
19.5 DIO_CTD ................................................................................19-12
19.6 DIO_EXT_CTU .......................................................................19-15
19.7 DIO_EXT_CTD .......................................................................19-20
19.8 DIO_PPWA .............................................................................19-25
19.9 DIO_PWM ...............................................................................19-28
19.10 EVENT_INIT ...........................................................................19-31
19.11 GET_EVENT...........................................................................19-34
19.12 Explanations............................................................................19-36
19.13 Error Codes.............................................................................19-37

†. Extended functions going beyond the standard functional range of the IEC 61131-3.

5958B 19-1
19-2 5958B
Fast I/O Function Blocks for ILC 200 IB

19 Fast I/O Function Blocks for ILC 200 IB

19.1 Overview

The ILC 200 IB field controller is equipped with 4 local fast inputs and 2
local fast outputs. Of the fast inputs, 2 channels can be wired with either 5
V or 24 V, and 2 can be wired with 24 V only. The two outputs have an out-
put voltage of 24 V. The fast I/O’s are enabled on the processor with the
aid of the time processing unit (TPU). The TPU processes complex time
input and output signals without placing a burden on the CPU.
The ILC 200 IB’s local I/O’s can be used for the following functions:
– simple fast input/outputs
– counting events
– measuring pulse or period duration
– pulse width modulation
– processing alarms.
The firmware function blocks of the ILC 200 IB cannot be instantiated.

Each of the 4 input channels may be switched to only one operating mode
at any one time.
These channels are then not available for other tasks until they have been
released.

Operating Mode For example, if the count operating mode has been set with input channel
E1 as source and input channel E2 as gate, channels E1 and E2 are re-
served for this operating mode until they are changed, and cannot be used
for other operating modes or tasks.

Please refer to the data sheet and the user manual of the the ILC 200 IB
Field Controller for further information.

5958B 19-3
PROGRAM WORX

The following ILC 200 IB function blocks are available:

Table 19-1 ILC 200 IB function blocks

Function block Short description


DIGITAL_IN† Reads the digital I/O channel
DIGITAL_OUT† Sets the digital I/O channel
DIO_CTU† Simple up counter with gate function

DIO_CTD Simple down counter with gate function
DIO_EXT_CTU† Up counter with gate and additional function
DIO_EXT_CTD† Down counter with gate and additional function
DIO_PPWA† Measures pulse or period duration

DIO_PWM Generates a variable pulsed frequency
EVENT_INIT† Links an input to an event task
GET_EVENT† Reads the status of an event input
† Extended functions going beyond the standard functional range
of the IEC 61131-3.

19-4 5958B
Fast I/O Function Blocks for ILC 200 IB

19.2 DIGITAL_IN

Description Function block DIGITAL_IN serves to read the ILC 200 IB’s digital input
channels.
There are 4 input channels available.

Parameter Data type Description


CHANNEL INT Channel (1 – 4) that is to be used as the
digital input
ERROR BOOL This output parameter switches from
FALSE to TRUE to indicate that an error
has occurred in the DIGITAL_IN function
block and that a valid error code is present
in the ADD_ERROR output parameter.
The error code’s period of validity is lim-
ited to the single cycle in which ERROR
switched from FALSE to TRUE. If the out-
put parameter ADD_ERROR is not wired
or if it is incorrect, output parameter
ERROR switches to TRUE the first time
the function block is called.
STATE BOOL Current state of the channel when the
function block is called.
ADD_ERROR WORD Error code

5958B 19-5
PROGRAM WORX

Representation
IL

(* DIGITAL_IN *)
LD (* INT *)
ST DIGITAL_IN_2.CHANNEL
CAL DIGITAL_IN_2
LD DIGITAL_IN_2.ERROR
ST (* BOOL *)
LD DIGITAL_IN_2.STATE
ST (* BOOL *)
LD DIGITAL_IN_2.ADD_ERROR
ST (* WORD *)

ST

(* DIGITAL_IN *)
DIGITAL_IN_1(CHANNEL:=(* INT *));
(* BOOL *):= DIGITAL_IN_1.ERROR;
(* BOOL *):= DIGITAL_IN_1.STATE;
(* WORD *):= DIGITAL_IN_1.ADD_ERROR;

FBD

19-6 5958B
Fast I/O Function Blocks for ILC 200 IB

19.3 DIGITAL_OUT

Description Function block DIGITAL_OUT serves to set the ILC 200 IB’s digital output
channels.
There are 2 output channels available.

Parameter Data type Description

CHANNEL INT Channel (1 - 2) that is to be used as the


digital output

STATE BOOL Current state of the channel when the


function block is called.

ERROR BOOL This output parameter switches from


FALSE to TRUE to indicate that an error
has occurred in the DIGITAL_OUT func-
tion block and that a valid error code is
present in the ADD_ERROR output pa-
rameter.
The error code’s period of validity is lim-
ited to the single cycle in which ERROR
switched from FALSE to TRUE. If the out-
put parameter ADD_ERROR is not wired
or if it is incorrect, output parameter
ERROR switches to TRUE the first time
the function block is called.

ADD_ERROR WORD Error code

5958B 19-7
PROGRAM WORX

Representation
IL

(* DIGITAL_OUT *)
LD (* INT *)
ST DIGITAL_OUT_1.CHANNEL
LD (* BOOL *)
ST DIGITAL_OUT_1.STATE
CAL DIGITAL_OUT_1
LD DIGITAL_OUT_1.ERROR
ST (* BOOL *)
LD DIGITAL_OUT_1.ADD_ERROR
ST (* WORD *)

ST

DIGITAL_OUT_1(CHANNEL:=(* INT *),STATE:=(* BOOL *));


(* BOOL *):= DIGITAL_OUT_1.ERROR;
(* WORD *):= DIGITAL_OUT_1.ADD_ERROR;

FBD

19-8 5958B
Fast I/O Function Blocks for ILC 200 IB

19.4 DIO_CTU

Description Function block DIO_CTU is an up counter with gate function (Page 19-36).
Use of the gate function is optional.
Counters without a gate require one input channel; channels with a gate re-
quire two input channels.
There are 4 input channels available.
This counter counts the pulses on the projected input channel according to
the desired count condition. The count result is output at the ’CV’ output.
When the preset value is reached, output ’Q’ is set to ’True’ and the function
block stops counting.
If ’RESET = True’, the counter is initialized with 0 and the preset value is
used. In order to start the count process, input 'RESET must be ’False', oth-
erwise the counter will be constantly reinitialized.
Additionally for counters with gate function, a certain level or a certain edge
must also be at the gate.

Parameter Data type Description

CHANNEL INT Input channel (1 - 4) of count pulses

GATE INT Input channel (1 - 4) of gate signals


(not valid unless GATE_MODE ¹ 0)

GATE_MODE WORD

5958B 19-9
PROGRAM WORX

Parameter Data type Description


CNT_COND WORD

RESET BOOL False : the counter will be started

True : the counter will be initialized from 0 and the value at PV will
be used

PV DINT Preset value for counter

ERROR BOOL This output parameter switches from FALSE to TRUE to indicate
that an error has occurred in the DIO_CTU function block and that
a valid error code is present in the ADD_ERROR output parameter.
The error code’s period of validity is limited to the single cycle in
which ERROR switched from FALSE to TRUE. If the output param-
eter ADD_ERROR is not wired or if it is incorrect, output parameter
ERROR switches to TRUE the first time the function block is called.

Q BOOL True if CV = PV
Counter stops and must be restarted.

CV DINT Current counter state (if RESET = False)

ADD_ERROR WORD Error code

19-10 5958B
Fast I/O Function Blocks for ILC 200 IB

Representation

IL ST

LD (* INT *) DIO_CTU_1(CHANNEL:=(* INT *),GATE:=(* INT *),


ST DIO_CTU_1.CHANNEL GATE_MODE:=(* WORD *),CNT_COND:=(* WORD *),
LD (* INT *) RESET:=(* BOOL *),PV:=(* DINT *));
ST DIO_CTU_1.GATE (* BOOL *):= DIO_CTU_1.ERROR;
LD (* WORD *) (* BOOL *):= DIO_CTU_1.Q;
ST DIO_CTU_1.GATE_MODE (* DINT *):= DIO_CTU_1.CV;
LD (* WORD *) (* WORD *):= DIO_CTU_1.ADD_ERROR;
ST DIO_CTU_1.CNT_COND
LD (* BOOL *)
ST DIO_CTU_1.RESET
LD (* DINT *)
ST DIO_CTU_1.PV
CAL DIO_CTU_1
LD DIO_CTU_1.ERROR
ST (* BOOL *)
LD DIO_CTU_1.Q
ST (* BOOL *)
LD DIO_CTU_1.CV
ST (* DINT *)
LD DIO_CTU_1.ADD_ERROR
ST (* WORD *)
FBD

5958B 19-11
PROGRAM WORX

19.5 DIO_CTD

Description Function block DIO_CTD is a down counter with gate function


(Page 19-36). Use of the gate function is optional.
Counters without a gate require one input channel; channels with a gate re-
quire two input channels.
There are 4 input channels available.
This counter counts the pulses on the projected input channel according to
the desired count condition. The count result is output at the ’CV’ output.
When the preset value (0) is reached, output ’Q’ is set to ’True’ and the
function block stops counting.
If ’LOAD = True’, the counter is initialized with the preset value. In order to
start the count process, input 'LOAD must be ’False', otherwise the counter
will be constantly reinitialized. Additionally for counters with gate function,
a certain level or a certain edge must also be at the gate.

Parameter Data type Description

CHANNEL INT Input channel (1 - 4) of count pulses

GATE INT Input channel (1 - 4) of gate signals


(not valid unless GATE_MODE ¹ 0)

GATE_MODE WORD

19-12 5958B
Fast I/O Function Blocks for ILC 200 IB

CNT_COND WORD

LOAD BOOL False : the counter will be started

True : the counter will be initialized with the value at PV

PV DINT Preset value for counter

ERROR BOOL This output parameter switches from FALSE to TRUE to indicate
that an error has occurred in the DIO_CTD function block and that a
valid error code is present in the ADD_ERROR output parameter.
The error code’s period of validity is limited to the single cycle in
which ERROR switched from FALSE to TRUE. If the output param-
eter ADD_ERROR is not wired or if it is incorrect, output parameter
ERROR switches to TRUE the first time the function block is called.

Q BOOL True if CV = 0
Counter stops and must be restarted.

CV DINT Current counter state (if LOAD = False)

ADD_ERROR WORD Error code

5958B 19-13
PROGRAM WORX

Representation

IL ST

LD (* INT *) DIO_CTD_1(CHANNEL:=(* INT *),GATE:=(* INT *),


ST DIO_CTD_1.CHANNEL GATE_MODE:=(* WORD *),CNT_COND:=(* WORD *),
LD (* INT *) LOAD:=(* BOOL *),PV:=(* DINT *));
ST DIO_CTD_1.GATE (* BOOL *):= DIO_CTD_1.ERROR;
LD (* WORD *) (* BOOL *):= DIO_CTD_1.Q;
ST DIO_CTD_1.GATE_MODE (* DINT *):= DIO_CTD_1.CV;
LD (* WORD *) (* WORD *):= DIO_CTD_1.ADD_ERROR;
ST DIO_CTD_1.CNT_COND
LD (* BOOL *)
ST DIO_CTD_1.LOAD
LD (* DINT *)
ST DIO_CTD_1.PV
CAL DIO_CTD_1
LD DIO_CTD_1.ERROR
ST (* BOOL *)
LD DIO_CTD_1.Q
ST (* BOOL *)
LD DIO_CTD_1.CV
ST (* DINT *)
LD DIO_CTD_1.ADD_ERROR
ST (* WORD *)
FBD

19-14 5958B
Fast I/O Function Blocks for ILC 200 IB

19.6 DIO_EXT_CTU

Description Function block DIO_EXT_CTU is an up counter with gate and additional


function (Page 19-36). Use of the gate function is optional.
Counters without a gate require one input channel; channels with a gate re-
quire two input channels.
There are 4 input channels available.
This counter counts the pulses on the projected input channel according to
the desired count condition. The count result is output at the ’CV’ output.
When the preset value is reached, output ’Q’ is set to ’True’ and the function
block stops counting. A previously projected event task can also be acti-
vated or a previously projected output can be set.
If ’RESET = True’, the counter is initialized with 0 and the preset value is
used. In order to start the count process, input 'RESET must be ’False', oth-
erwise the counter will be constantly reinitialized.
Additionally for counters with gate function, a certain level or a certain edge
must also be at the gate.

Parameter Data type Description

CHANNEL INT Input channel (1 - 4) of the count pulses

GATE INT Input channel (1 - 4) of the gate signals


(not valid unless GATE_MODE ¹ 0)

GATE_MODE WORD

5958B 19-15
PROGRAM WORX

Parameter Data type Description


EVENT BOOL False : An event task is not activated when the preset value is
reached

True : When the preset value is reached, the event task


associated with the channel is activated

OUT_PIN WORD LOW BYTE

HIGH BYTE

Note:
If low byte is 0, bits 8 through 10 are invalid and consequently no out-
put function is selected!

DELAY INT Pulse length in ms


Possible range from 1 ms to 32767 ms

CNT_COND WORD

RESET BOOL False : the counter is started

True : the counter is initialized at 0 and the value at PV is used

19-16 5958B
Fast I/O Function Blocks for ILC 200 IB

Parameter Data type Description


PV DINT Preset value for counter

ERROR BOOL This output parameter switches from FALSE to TRUE to indicate
that an error has occurred in the DIO_EXT_CTU function block and
that a valid error code is present in the ADD_ERROR output param-
eter.
The error code’s period of validity is limited to the single cycle in
which ERROR switched from FALSE to TRUE. If the output param-
eter ADD_ERROR is not wired or if it is incorrect, output parameter
ERROR switches to TRUE the first time the function block is called.

Q BOOL True if CV = PV
Counter stops and must be restarted.

CV DINT Current counter state (if RESET = False)

ADD_ERROR WORD Error code

5958B 19-17
PROGRAM WORX

Representation

IL ST

(* DIO_EXT_CTU *) (* DIO_EXT_CTU *)
LD (* INT *) DIO_EXT_CTU_1(CHANNEL:=(* INT *),GATE:=(* INT *),
ST DIO_EXT_CTU_1.CHANNEL GATE_MODE:=(* WORD *),EVENT:=(* BOOL *),
LD (* INT *) OUT_PIN:=(* WORD *),DELAY:=(* INT *),
ST DIO_EXT_CTU_1.GATE CNT_COND:=(* WORD *),RESET:=(* BOOL *),
LD (* WORD *) PV:=(* DINT *));
ST DIO_EXT_CTU_1.GATE_MODE (* BOOL *):= DIO_EXT_CTU_1.ERROR;
LD (* BOOL *) (* BOOL *):= DIO_EXT_CTU_1.Q;
ST DIO_EXT_CTU_1.EVENT (* DINT *):= DIO_EXT_CTU_1.CV;
LD (* WORD *) (* WORD *):= DIO_EXT_CTU_1.ADD_ERROR;
ST DIO_EXT_CTU_1.OUT_PIN
LD (* INT *)
ST DIO_EXT_CTU_1.DELAY
LD (* WORD *)
ST DIO_EXT_CTU_1.CNT_COND
LD (* BOOL *)
ST DIO_EXT_CTU_1.RESET
LD (* DINT *)
ST DIO_EXT_CTU_1.PV
CAL DIO_EXT_CTU_1
LD DIO_EXT_CTU_1.ERROR
ST (* BOOL *)
LD DIO_EXT_CTU_1.Q
ST (* BOOL *)
LD DIO_EXT_CTU_1.CV
ST (* DINT *)
LD DIO_EXT_CTU_1.ADD_ERROR
ST (* WORD *)

19-18 5958B
Fast I/O Function Blocks for ILC 200 IB

FBD

5958B 19-19
PROGRAM WORX

19.7 DIO_EXT_CTD

Description Function block DIO_EXT_CTD is a down counter with gate and additional
function (Page 19-36). Use of the gate function is optional.
Counters without a gate require one input channel; channels with a gate re-
quire two input channels.
There are 4 input channels available.
This counter counts the pulses on the projected input channel according to
the desired count condition. The count result is output at the ’CV’ output.
When the preset value (0) is reached, output ’Q’ is set to ’True’ and the
function block stops counting. A previously projected event task can also
be activated or a previously projected output can be set.
If LOAD = True’, the counter is initialized with the preset value. In order to
start the count process, input LOAD must be ’False', otherwise the counter
will be constantly reinitialized.
Additionally for counters with gate function, a certain level or a certain edge
must also be at the gate.

Parameter Data type Description

CHANNEL INT Input channel (1 – 4) of the count pulses

GATE INT Input channel (1 – 4) of the gate signals


(not valid unless GATE_MODE ¹ 0)

GATE_MODE WORD

19-20 5958B
Fast I/O Function Blocks for ILC 200 IB

Parameter Data type Description


EVENT BOOL False : An event task is not activated when the preset value is
reached

True : When the preset value is reached, the event task


associated with the channel is activated

OUT_PIN WORD LOW BYTE

HIGH BYTE

Note:
If low byte is 0, bits 8 through 10 are invalid and consequently no out-
put function is selected!

DELAY INT Pulse length in ms


Possible range from 1 ms to 32767 ms

CNT_COND WORD

LOAD BOOL False : the counter is started

True : the counter is initialized with the value at PV

5958B 19-21
PROGRAM WORX

Parameter Data type Description


PV DINT Preset value for counter

ERROR BOOL This output parameter switches from FALSE to TRUE to indicate
that an error has occurred in the DIO_EXT_CTD function block and
that a valid error code is present in the ADD_ERROR output param-
eter.
The error code’s period of validity is limited to the single cycle in
which ERROR switched from FALSE to TRUE. If the output param-
eter ADD_ERROR is not wired or if it is incorrect, output parameter
ERROR switches to TRUE the first time the function block is called.

Q BOOL True when CV = 0


Counter stops and must be restarted.

CV DINT Current counter state (when LOAD = False)

ADD_ERROR WORD Error code

19-22 5958B
Fast I/O Function Blocks for ILC 200 IB

Representation

IL ST

(* DIO_EXT_CTD *) (* DIO_EXT_CTD *)
LD (* INT *) DIO_EXT_CTD_1(CHANNEL:=(* INT *),GATE:=(* INT *),
ST DIO_EXT_CTD_1.CHANNEL GATE_MODE:=(* WORD *),EVENT:=(* BOOL *),
LD (* INT *) OUT_PIN:=(* WORD *),DELAY:=(* INT *),
ST DIO_EXT_CTD_1.GATE CNT_COND:=(* WORD *),LOAD:=(* BOOL *),
LD (* WORD *) PV:=(* DINT *));
ST DIO_EXT_CTD_1.GATE_MODE (* BOOL *):= DIO_EXT_CTD_1.ERROR;
LD (* BOOL *) (* BOOL *):= DIO_EXT_CTD_1.Q;
ST DIO_EXT_CTD_1.EVENT (* DINT *):= DIO_EXT_CTD_1.CV;
LD (* WORD *) (* WORD *):= DIO_EXT_CTD_1.ADD_ERROR;
ST DIO_EXT_CTD_1.OUT_PIN
LD (* INT *)
ST DIO_EXT_CTD_1.DELAY
LD (* WORD *)
ST DIO_EXT_CTD_1.CNT_COND
LD (* BOOL *)
ST DIO_EXT_CTD_1.LOAD
LD (* DINT *)
ST DIO_EXT_CTD_1.PV
CAL DIO_EXT_CTD_1
LD DIO_EXT_CTD_1.ERROR
ST (* BOOL *)
LD DIO_EXT_CTD_1.Q
ST (* BOOL *)
LD DIO_EXT_CTD_1.CV
ST (* DINT *)
LD DIO_EXT_CTD_1.ADD_ERROR
ST (* WORD *)

5958B 19-23
PROGRAM WORX

FBD

19-24 5958B
Fast I/O Function Blocks for ILC 200 IB

19.8 DIO_PPWA

Description Function block DIO_PPWA serves to measure the period duration or the
duration of a high pulse.
Measurement may be carried out once to determine the period duration di-
rectly, or up to 265 times in order to calculate the mean period duration.
There are 4 input channels available.
This function block takes the signal on the projected input channel and
uses it to calculate the pulse or period duration according to the desired op-
erating mode. If output ’FIN = True’, the current measurement is terminated
and output ’DELAY’ contains the pulse or period duration in ms.

Parameter Data type Description

CHANNEL INT Input channel (1 - 4) of the count pulses

MODE WORD LOW BYTE

HIGH BYTE (MAX_COUNT)


Bits 8 through 15 contain the number (1 to 256 ) of period durations
or pulses to be measured. The duration is then calculated by aver-
aging. The number of measurements (MAX_COUNT) should be
chosen with a view to the purpose of measuring.

START BOOL False : the current measurement is in progress

True : measurement is edge-driven.


Pulse duration is measured when a rising edge is at
input ’CHANNEL’, period duration is measured when a
falling edge is at input ’CHANNEL’.

5958B 19-25
PROGRAM WORX

Parameter Data type Description


ERROR BOOL This output parameter switches from FALSE to TRUE to indicate
that an error has occurred in the DIO_PPWA function block and that
a valid error code is present in the ADD_ERROR output parameter.
The error code’s period of validity is limited to the single cycle in
which ERROR switched from FALSE to TRUE. If the output param-
eter ADD_ERROR is not wired or if it is incorrect, output parameter
ERROR switches to TRUE the first time the function block is called.
Possible overrun is also indicated as an error.

FIN BOOL True : current measurement terminated,


a valid value is present in 'DELAY'

DELAY REAL Pulse or period duration in ms


(not valid unless FIN = True)

ADD_ERROR WORD Error code

There is an indirect correlation between the measurable length of the signal


and the number of measurements necessary to determine the length of a
signal.
The maximum measurable length of a signal us calculated as follows:

With MAX_COUNT 0...FF and a resolution of 1,28 ms.

19-26 5958B
Fast I/O Function Blocks for ILC 200 IB

Representation

IL ST

(* DIO_PPWA *) (* DIO_PPWA *)
LD (* INT *) DIO_PPWA_1(CHANNEL:=(* INT *),MODE:=(* WORD *),
ST DIO_PPWA_1.CHANNEL START:=(* BOOL *));
LD (* WORD *) (* BOOL *):= DIO_PPWA_1.ERROR;
ST DIO_PPWA_1.MODE (* BOOL *):= DIO_PPWA_1.FIN;
LD (* BOOL *) (* REAL *):= DIO_PPWA_1.DELAY;
ST DIO_PPWA_1.START (* WORD *):= DIO_PPWA_1.ADD_ERROR;
CAL DIO_PPWA_1
LD DIO_PPWA_1.ERROR
ST (* BOOL *)
LD DIO_PPWA_1.FIN
ST (* BOOL *)
LD DIO_PPWA_1.DELAY
ST (* REAL *)
LD DIO_PPWA_1.ADD_ERROR
ST (* WORD *)

FBD

5958B 19-27
PROGRAM WORX

19.9 DIO_PWM

Description Function block DIO_PWM generates a variable pulsed frequency (pulse


width modulation) and outputs it to an output channel.
The period duration and the duration of the high phase can be preset within
certain limits. It is possible to define a high phase from 0 to 100%.
There are 2 output channels available.
A previously projected event task can be called at the start of every period.

Parameter Data type Description

CHANNEL INT Channel (1 - 2) on which the pulse width modulation signal is output

EVENT BOOL False : Event task is not called

True : Event task is called at the start of every period

PWMHI DINT High phase in µs

PWMPER DINT Period duration in µs

LOAD BOOL LOAD has two meanings, depending on the state of the block:
The function block is not yet active (Q = True), this means it is being
called for the first time.

False : PWMHI and PWMPER are not used and pulse width
modulation is not started with these values.

True : PWMHI and PWMPER are used and pulse width


modulation is started with these values immediately.
The function block is active (Q = False), this means it has already
been started.

False : PWMHI and PWMPER will not be used for calculation


until the next period.
(the current period is not altered).

True : PWMHI and PWMPER will be used immediately and


for the period just generated
(the current period is altered with the new values).

19-28 5958B
Fast I/O Function Blocks for ILC 200 IB

Parameter Data type Description


ERROR BOOL This output parameter switches from FALSE to TRUE to indicate
that an error has occurred in the DIO_PWM function block and that
a valid error code is present in the ADD_ERROR output parameter.
The error code’s period of validity is limited to the single cycle in
which ERROR switched from FALSE to TRUE.

Q BOOL False : Pulse width modulation is active and it is possible to use


new 'PWMHI' or 'PWMPER'.

True : PWM is not active

ADD_ERROR WORD Error code

Representation

IL ST

(* DIO_PWM *) (* DIO_PWM *)
LD (* INT *) DIO_PWM_1(CHANNEL:=(* INT *),EVENT:=(* BOOL *),
ST DIO_PWM_1.CHANNEL PWMHI:=(* DINT *),PWMPER:=(* DINT *),
LD (* BOOL *) LOAD:=(* BOOL *));
ST DIO_PWM_1.EVENT (* BOOL *):= DIO_PWM_1.ERROR;
LD (* DINT *) (* BOOL *):= DIO_PWM_1.Q;
ST DIO_PWM_1.PWMHI (* WORD *):= DIO_PWM_1.ADD_ERROR;
LD (* DINT *)
ST DIO_PWM_1.PWMPER
LD (* BOOL *)
ST DIO_PWM_1.LOAD
CAL DIO_PWM_1
LD DIO_PWM_1.ERROR
ST (* BOOL *)
LD DIO_PWM_1.Q
ST (* BOOL *)
LD DIO_PWM_1.ADD_ERROR
ST (* WORD *)

5958B 19-29
PROGRAM WORX

FBD

19-30 5958B
Fast I/O Function Blocks for ILC 200 IB

19.10 EVENT_INIT

Description Function block EVENT_INIT links an input channel to an event task.


In order to be able to respond as rapidly as possible to changes in the input
channels, the links between 4 event tasks numbered 2, 3, 4 and 5 and input
channels 1 to 4 can be programmed.
Channel 1 is always linked to event task 2, channel 2 always to event task
3, and so on.

Parameter Data type Description


CHANNEL INT Channel (1 - 4) of the event task
T_COND WORD Trigger Condition

OUT_PIN WORD LOW BYTE

HIGH BYTE

If low byte is 0, bits 8 through 10 are invalid and consequently no


output function is selected!

5958B 19-31
PROGRAM WORX

Parameter Data type Description


PULSE_DELAY INT Pulse length in ms
Possible range from 1 ms to 32767 ms
VALID BOOL False : Output parameter CHAN_ID is invalid and may not be
used to identify the projected channel.

True : Output parameter CHAN_ID is valid and may be used to


identify the projected channel.
CHAN_ID INT Projected channel of the event task
(not valid unless VALID = True)
ERROR BOOL This output parameter switches from FALSE to TRUE to indicate
that an error has occurred in the EVENT_INIT function block and
that a valid error code is present in the ADD_ERROR output pa-
rameter.
The error code’s period of validity is limited to the single cycle in
which ERROR switched from FALSE to TRUE. If the output pa-
rameter ADD_ERROR is not wired or if it is incorrect, output pa-
rameter ERROR switches to TRUE the first time the function
block is called.

ADD_ERROR WORD Error code

19-32 5958B
Fast I/O Function Blocks for ILC 200 IB

Representation

IL ST

(* EVENT_INIT *) (* EVENT_INIT *)
LD (* INT *) EVENT_INIT_1(CHANNEL:=(* INT *),T_COND:=(* WORD *),
ST EVENT_INIT_1.CHANNEL OUT_PIN:=(* WORD *),PULSE_DELAY:=(* INT *));
LD (* WORD *) (* BOOL *):= EVENT_INIT_1.VALID;
ST EVENT_INIT_1.T_COND (* INT *):= EVENT_INIT_1.CHAN_ID;
LD (* WORD *) (* BOOL *):= EVENT_INIT_1.ERROR;
ST EVENT_INIT_1.OUT_PIN (* WORD *):= EVENT_INIT_1.ADD_ERROR;
LD (* INT *)
ST EVENT_INIT_1.PULSE_DELAY
CAL EVENT_INIT_1
LD EVENT_INIT_1.VALID
ST (* BOOL *)
LD EVENT_INIT_1.CHAN_ID
ST (* INT *)
LD EVENT_INIT_1.ERROR
ST (* BOOL *)
LD EVENT_INIT_1.ADD_ERROR
ST (* WORD *)

FBD

5958B 19-33
PROGRAM WORX

19.11 GET_EVENT

Description Function block GET_EVENT serves for rapid readout of the state of an
event input within an event task.
The state stored at the time of the event’s occurrence is returned.
If the trigger condition signal change is set in the EVENT_INIT function
block, the GET_EVENT function block is used to detect whether the
EVENT_INIT function block has been triggered at rising or falling edge.
In the application program, it is possible to respond to the different trigger
conditions.

Parameter Data type Description


CHAN_ID INT Projected channel of the event task
(not valid unless EVENT_INIT VALID = True in the function block)
ERROR BOOL This output parameter switches from FALSE to TRUE to indicate
that an error has occurred in the GET_EVENT function block and
that a valid error code is present in the ADD_ERROR output pa-
rameter.
The error code’s period of validity is limited to the single cycle in
which ERROR switched from FALSE to TRUE. If the output param-
eter ADD_ERROR is not wired or if it is incorrect, output parameter
ERROR switches to TRUE the first time the function block is called.
STATE BOOL Current state of the event input
False : Function block EVENT_INIT has been triggered at
falling edge

True : Function block EVENT_INIT has been triggered at


rising edge
ADD_ERROR WORD Error code

19-34 5958B
Fast I/O Function Blocks for ILC 200 IB

Representation

IL ST

(* GET_EVENT *) (* GET_EVENT *)
LD (* INT *) GET_EVENT_1(CHAN_ID:=(* INT *));
ST GET_EVENT_1.CHAN_ID (* BOOL *):= GET_EVENT_1.ERROR;
CAL GET_EVENT_1 (* BOOL *):= GET_EVENT_1.STATE;
LD GET_EVENT_1.ERROR (* WORD *):= GET_EVENT_1.ADD_ERROR;
ST (* BOOL *)
LD GET_EVENT_1.STATE
ST (* BOOL *)
LD GET_EVENT_1.ADD_ERROR
ST (* WORD *)

FBD

5958B 19-35
PROGRAM WORX

19.12 Explanations

Explanation of Gate Function:

Explanation of Additional Function:


There are two options available for when it is important to be able to re-
spond rapidly when counter levels are reached.
In the first possibility, any event task that is present can be activated when
the preset value is reached, or a previously projected output can be set on
the basis of preset values using the Output option.
The following options are available for this case:

1. Switch output to High (change of state)


2. Switch output to Low (change of state)
3. High pulse of a certain length
4. Low pulse of a certain length
5. Output state is simply inverted (change of state)
Moreover, for the output option, the state of the output must also be pro-
jected at the start of the count process (set to low or high).

19-36 5958B
Fast I/O Function Blocks for ILC 200 IB

19.13 Error Codes

The following error codes are available in output ADD_ERROR:

Table 19-2 Error Codes

Error code Description


0x994 An invalid number has been specified for the output chan-
nel.
0x995 The output channel is already in use.
0x996 An invalid number has been specified for the input chan-
nel.
0x997 The input channel is already in use.
0x999 The trigger condition for the event task is incorrect.
0x99A The Parameter CHAN_ID is incorrect.
0x99B The trigger condition for the counter is incorrect.

5958B 19-37
PROGRAM WORX

19-38 5958B
Appendix A

A 1 List of Tables

Section 1
Table 1-1: Example to initialize a shared memory flag or area ....1-15
Table 1-2: System programs........................................................1-19
Table 1-3: Operational states in ProConOS.................................1-27
Table 1-4: ProConOS system flags..............................................1-33
Table 1-5: INTERBUS Master system flags.................................1-34
Table 1-6: INTERBUS Slave system flags...................................1-36
Table 1-7: Coprozessor system flags...........................................1-37
Table 1-8: Digital Inputs on the FC 486DX and
FC/DI controller boards...............................................1-37
Table 1-9: Remote Field Controller for IP65 Local Bus................1-38
Table 1-10: User task information ..................................................1-39
Table 1-11: Error catalogue information.........................................1-40
Table 1-12: Error reaction of string functions .................................1-41

Section 2
Table 2-1: Type conversion functions ............................................2-5

Section 3
Table 3-1: Numerical functions ......................................................3-3

Section 4
Table 4-1: Arithmetic functions ......................................................4-3

5958B A-1
List of Tables

Section 5
Table 5-1: Bitwise Boolean functions .............................................5-3

Section 6
Table 6-1: Bit-string functions ........................................................6-3

Section 7
Table 7-1: Selection functions........................................................7-3

Section 8
Table 8-1: Comparison functions ...................................................8-3

Section 9
Table 9-1: Character string functions .............................................9-3

Section 10
Table 10-1: Bistable function blocks ..............................................10-3

Section 11
Table 11-1: Edge detection function blocks ...................................11-3

Section 12
Table 12-1: Counter function blocks ..............................................12-3

Section 13
Table 13-1: Timer function blocks ..................................................13-3

A-2 5958B
List of Tables

Section 14
Table 14-1: ProConOS functions ...................................................14-3

Section 15
Table 15-1: ProConOS function blocks..........................................15-3

Section 16
Table 16-1: Bit manipulation functions ...........................................16-3

Section 17
Table 17-1: IB Communication Blocks ...........................................17-3
Table 17-2: Possible status of the copy process for
*_TO_BUF function blocks........................................17-31
Table 17-3: Possible status of the copy process for
BUF_TO_* function blocks........................................17-39

Section 18
Table 18-1: TCP/IP Communication Blocks...................................18-3
Table 18-2: Error Codes ..............................................................18-13

Section 19
Table 19-1: ILC 200 IB function blocks ..........................................19-4
Table 19-2: Error Codes ..............................................................19-37

5958B A-3
List of Tables

A-4 5958B
Appendix A

B 2 Index

Symbols Bit-string functions .................................. 6-3


Bitwise Boolean functions ....................... 5-3
*_TO_BUF........................................... 17-25
bitwise left rotation ........................... 6-4, 6-5
*_TO_STRING ........................................ 9-4
bitwise left shifting ............................ 6-8, 6-9
A bitwise right rotation ......................... 6-6, 6-7
bitwise right shifting...................... 6-10, 6-11
ABS ......................................................... 3-4
BOOL_TO_BYTE.................................. 2-12
absolute value ......................................... 3-4
BOOL_TO_DINT................................... 2-17
ACOS ...................................................... 3-5
BOOL_TO_DWORD ............................. 2-14
ADD......................................................... 4-4
BOOL_TO_INT ..................................... 2-16
ADD_T_T ................................................ 4-5
BOOL_TO_REAL.................................. 2-18
addition.................................................... 4-4
BOOL_TO_SINT................................... 2-15
addition of time values ............................ 4-5
BOOL_TO_WORD................................ 2-13
Additional Function.............................. 19-36
Boolean AND .......................................... 5-3
AND......................................................... 5-3
Boolean OR ............................................ 5-5
arc cosine................................................ 3-5
bootproject
arc sine.................................................... 3-6
download ........................................ 1-27
Arithmetic functions................................. 4-3
BUF_TO_* .......................................... 17-33
ASIN........................................................ 3-6
BUF_TO_BYTE .................................. 17-33
associating
BUF_TO_DINT ................................... 17-33
program to task............................... 1-24
BUF_TO_DWORD .............................. 17-33
AT.......................................................... 1-12
BUF_TO_INT ...................................... 17-33
B BUF_TO_REAL .................................. 17-33
BUF_TO_SINT.................................... 17-33
B_BCD_TO_DINT................................. 2-10
BUF_TO_STRING .............................. 17-33
B_BCD_TO_INT ..................................... 2-9
BUF_TO_TIME ................................... 17-33
B_BCD_TO_SINT ................................... 2-8
BUF_TO_WORD ................................ 17-33
BCD_TO_DINT ..................................... 2-11
BYTE_TO_BOOL.................................. 2-19
binary selection ............................ 7-10, 7-11
BYTE_TO_BUF .................................. 17-25
Bistable function blocks................ 10-3, 10-5
BYTE_TO_DINT ................................... 2-24
Bit manipulation functions - overview.... 16-3
BYTE_TO_DWORD.............................. 2-21
BIT_TEST ............................................. 16-4

5958B A-5
Index

BYTE_TO_INT ...................................... 2-23 Counter function blocks ........................ 12-3


BYTE_TO_REAL .................................. 2-25 counting down ....................................... 12-5
BYTE_TO_SINT.................................... 2-22 counting up ........................................... 12-3
BYTE_TO_STRING ................................ 9-4 counting up and down ........................... 12-7
BYTE_TO_WORD ................................ 2-20 CTD....................................................... 12-5
CTU....................................................... 12-3
C CTUD .................................................... 12-7
Character string functions ....................... 9-3 cut decimal places ................................ 2-79
CLR_OUT ............................................. 15-4 cyclic task.............................................. 1-19
COLD_RESTART ................................. 14-3
communication interface ......................... 1-4 D
comparing - equality................................ 8-4 D_BCD_TO_DINT ................................ 2-28
comparing - greater........................ 8-6, 9-14 D_BCD_TO_INT ................................... 2-27
comparing - greater/equal .............. 8-5, 9-13 D_BCD_TO_SINT................................. 2-26
comparing - inequal........................ 8-9, 9-24 debug ...................................................... 1-5
comparing - less............................. 8-8, 9-21 decimal places cut ................................ 2-79
comparing - less/equal ................... 8-7, 9-17 declaring
comparing - strings................................ 9-11 resource.......................................... 1-17
Comparison functions ............................. 8-3 task ................................................. 1-22
compiler................................................... 1-5 DEFAULT task ...................................... 1-18
complement - double............................. 4-13 DELETE .................................................. 9-9
complement - single ................................ 5-4 deletion ................................................... 9-9
CONCAT ................................................. 9-7 DERIVAT .............................................. 15-5
concatenation.......................................... 9-7 detecting position .................................. 9-12
configuration.......................................... 1-16 differentiation ........................................ 15-5
Connection between two ETH DIGITAL_IN .......................................... 19-5
controller boards ...................... 18-4 DIGITAL_OUT ........................... 19-7, 19-37
CONTINUE ........................................... 14-5 DINT_TO_B_BCD................................. 2-30
COP_DIAG_STATUS_REG_FAT_ERR 1-37 DINT_TO_BCD ..................................... 2-29
COP_DIAG_STATUS_REG_PON........ 1-37 DINT_TO_BOOL................................... 2-33
COP_DIAG_STATUS_REG_RT_ERR . 1-37 DINT_TO_BUF ................................... 17-25
COP_DIAG_STATUS_REG_WARN..... 1-37 DINT_TO_BYTE ................................... 2-34
COS ........................................................ 3-8 DINT_TO_D_BCD ................................ 2-32
cosine...................................................... 3-8 DINT_TO_DWORD............................... 2-36
counter ................................ 12-3, 12-5, 12-7 DINT_TO_INT ....................................... 2-38

A-6 5958B
Index

DINT_TO_REAL ................................... 2-39 E


DINT_TO_SINT..................................... 2-37 Edge detection function blocks .... 11-3, 11-5
DINT_TO_STRING ................................. 9-4 element bistable.................................... 10-3
DINT_TO_TIME .................................... 2-40 EQ ........................................................... 8-4
DINT_TO_W_BCD................................ 2-31 EQ_STRING ......................................... 9-11
DINT_TO_WORD ................................. 2-35 equality........................................... 8-4, 9-11
DIO_CTD ............................................ 19-12 error ............................................. 1-5, 18-13
DIO_CTU ................................... 19-9, 19-37 Error codes ......................................... 19-37
DIO_EXT_CTD ................................... 19-20 error manager ......................................... 1-4
DIO_EXT_CTU ................................... 19-15 error task ............................................... 1-19
DIO_PPWA ......................................... 19-25 Ethernet communication ....................... 18-3
DIO_PWM ........................................... 19-28 event task.............................................. 1-19
DIV .......................................................... 4-6 EVENT_INIT ....................................... 19-31
DIV_T_AN ............................................... 4-7 Example ................................................ 12-5
division .................................................... 4-6 exclusive OR........................................... 5-6
division of time values ............................. 4-7 executing - cold restart.......................... 14-3
dominant reset ...................................... 10-5 executing - hot restart ........................... 14-6
dominant set.......................................... 10-3 executing - warm restart ....................... 14-7
double complement............................... 4-13 EXP ......................................................... 3-9
down counting .............................. 12-5, 12-7
exponentiation.................................. 3-9, 4-8
downloading .......................................... 1-26
EXPT....................................................... 4-8
bootproject ...................................... 1-27
project ............................................. 1-26 F
zipped project ................................. 1-27
F_TRIG ................................................. 11-3
DWORD_TO_BOOL ............................. 2-41
falling edge detection ............................ 11-3
DWORD_TO_BUF .............................. 17-25
falling trigger ......................................... 11-3
DWORD_TO_BYTE.............................. 2-42
Fast I/O Function Blocks ....................... 19-3
DWORD_TO_DINT............................... 2-46
FIND...................................................... 9-12
DWORD_TO_INT ................................. 2-45
flags
DWORD_TO_REAL.............................. 2-47
memory........................................... 1-11
DWORD_TO_SINT ............................... 2-44
shared memory flags ...................... 1-14
DWORD_TO_STRING............................ 9-4
system flags........................... 1-14, 1-33
DWORD_TO_WORD............................ 2-43
function - arithmetic................................. 4-3
function - bit-string .................................. 6-3

5958B A-7
Index

function - bitwise Boolean ....................... 5-3 I


function - character string........................ 9-3 I/O image .............................................. 1-11
function - comparison.............................. 8-3 I/O interface ............................................ 1-4
function - logarithmic ............................... 3-3 I/O system
function - numerical................................. 3-3 decentral........................................... 1-4
function - ProConOS ............................. 14-3 local .................................................. 1-4
function - selection .................................. 7-3 I_BIT_IN_* .......................................... 16-10
function - trigonometric............................ 3-3 I_BIT_IN_BYTE .................................. 16-10
function - type conversion ....................... 2-5 I_BIT_IN_DWORD .............................. 16-10
function block - bistable................ 10-3, 10-5 I_BIT_IN_WORD ................................ 16-10
function block - counter ....... 12-3, 12-5, 12-7 IB communication function blocks......... 17-3
function block - edge detection .... 11-3, 11-5 IB_CONTROL ....................................... 17-4
function block - ProConOS.................... 15-3 IBS 24 RFC/486DX/ETH-T
function block - timer .......... 13-3, 13-5, 13-8, Error Codes .................................. 18-13
.....................................13-10, 13-15
IP_CONNECT ................................ 18-4
IP_TIME........................................ 18-10
G
IP_URCV ........................................ 18-6
Gate Function...................................... 19-36
IP_USEND...................................... 18-8
GE ........................................................... 8-5
IEC 1131-3
GE_STRING ......................................... 9-13
compliance ....................................... 1-6
GET_CHAR........................................... 16-5
ILC 200 IB
GET_EVENT....................................... 19-34
DIGITAL_IN .................................... 19-5
GET_LSB .............................................. 16-6
DIGITAL_OUT ................................ 19-7
GET_MSB ............................................. 16-7
DIO_CTD...................................... 19-12
GET_SYM ............................................. 15-8
DIO_CTU........................................ 19-9
greater............................................ 8-6, 9-14
DIO_EXT_CTD............................. 19-20
greater/equal .................................. 8-5, 9-13
DIO_EXT_CTU............................. 19-15
GT ........................................................... 8-6
DIO_PWA ..................................... 19-25
GT_STRING.......................................... 9-14
DIO_PWM .................................... 19-28
Error Codes .................................. 19-37
H
EVENT_INIT................................. 19-31
HALT ..................................................... 1-27
GET_EVENT ................................ 19-34
HOT_RESTART.................................... 14-6
ILC 200 IB field controller...................... 19-3
inequality ........................................ 8-9, 9-24

A-8 5958B
Index

initial task .............................................. 1-19 LIMIT_* ................................................... 7-5


input LIMIT_DINT ............................................ 7-5
memory........................................... 1-11 LIMIT_INT ............................................... 7-5
INSERT ................................................. 9-15 LIMIT_REAL ........................................... 7-5
insertion................................................. 9-15 LIMIT_SINT............................................. 7-5
INT_TO_B_BCD ................................... 2-48 LIMIT_STRING ....................................... 7-5
INT_TO_BOOL ..................................... 2-51 limitation.................................................. 7-5
INT_TO_BUF ...................................... 17-25 limitations ................................................ 1-6
INT_TO_BYTE ...................................... 2-52 LN ......................................................... 3-10
INT_TO_D_BCD ................................... 2-50 located variables ................................... 1-12
INT_TO_DINT ....................................... 2-56 LOG ...................................................... 3-11
INT_TO_DWORD ................................. 2-54 logarithm to base 10 ............................. 3-11
INT_TO_REAL ...................................... 2-57 logarithmic functions ............................... 3-3
INT_TO_SINT ....................................... 2-55 logical AND ............................................. 5-3
INT_TO_STRING .................................... 9-4 logical exclusive OR................................ 5-6
INT_TO_W_BCD .................................. 2-49 logical OR ............................................... 5-5
INT_TO_WORD .................................... 2-53 LT............................................................ 8-8
INTEGRAL .......................................... 15-11 LT_STRING .......................................... 9-21
IP_CONNECT ....................................... 18-4
IP_TIME .............................................. 18-10 M
IP_URCV............................................... 18-6 MASTER_DIAG_PARAM_REG............ 1-36
IP_USEND ............................................ 18-8 MASTER_DIAG_STATUS_REG_ACT . 1-35
MASTER_DIAG_STATUS_REG_BSA . 1-35
L MASTER_DIAG_STATUS_REG_BUS . 1-34
LE............................................................ 8-7 MASTER_DIAG_STATUS_REG_CTRL 1-34
LE_STRING .......................................... 9-17 MASTER_DIAG_STATUS_REG_DCR 1-35
LEFT ..................................................... 9-18 MASTER_DIAG_STATUS_REG_DTC . 1-35
left rotation ....................................... 6-4, 6-5 MASTER_DIAG_STATUS_REG_PF.... 1-34
left shifting ........................................ 6-8, 6-9 MASTER_DIAG_STATUS_REG_QUAL 1-35
leftmost character.................................. 9-18 MASTER_DIAG_STATUS_REG_RDY. 1-35
LEN ....................................................... 9-20 MASTER_DIAG_STATUS_REG_RES . 1-35
length .................................................... 9-20 MASTER_DIAG_STATUS_REG_RUN 1-35
less................................................. 8-8, 9-21 MASTER_DIAG_STATUS_REG_SSINFO ...
less/equal ....................................... 8-7, 9-17 .................................................. 1-36
LIMIT ....................................................... 7-4

5958B A-9
Index

MASTER_DIAG_STATUS_REG_SYNCRES N
.................................................. 1-35
natural exponential.................................. 3-9
MASTER_DIAG_STATUS_REG_SYSFAIL..
.................................................. 1-35 natural logarithm ................................... 3-10
MASTER_DIAG_STATUS_REG_USER 1-34 NE ........................................................... 8-9
MASTER_DIAG_STATUS_REG_WARN 1-35 NE_STRING ......................................... 9-24
MAX ........................................................ 7-6 NEG ...................................................... 4-13
MAX_* ..................................................... 7-7 NOT ........................................................ 5-4
MAX_DINT .............................................. 7-7 Numerical functions ................................ 3-3
MAX_INT................................................. 7-7
MAX_REAL ............................................. 7-7
O
MAX_SINT .............................................. 7-7 off-delay timing.................................... 13-15
MAX_STRING......................................... 7-7 ONBOARD_INPUT ............................... 1-37
maximum.......................................... 7-6, 7-7 on-delay timing........................... 13-8, 13-10
memory ................................................. 1-10 operational state ................................... 1-27
buffer............................................... 1-11 OR........................................................... 5-5
I/O image ........................................ 1-11 output
PLC program .................................. 1-11 memory........................................... 1-11
retentive data .................................. 1-13 output - set zero .................................... 15-4
MID........................................................ 9-22
middle of a string................................... 9-22 P
MIN.......................................................... 7-8 PARITY_*............................................ 16-16
MIN_* ...................................................... 7-9 PARITY_BYTE.................................... 16-16
MIN_DINT ............................................... 7-9 PARITY_DWORD ............................... 16-16
MIN_INT.................................................. 7-9 PARITY_WORD.................................. 16-16
MIN_REAL .............................................. 7-9 PCP_CLIENT ........................................ 17-7
MIN_SINT ............................................... 7-9 PCP_CONNECT................................. 17-11
MIN_STRING .......................................... 7-9 PCP_READ......................................... 17-14
minimum........................................... 7-8, 7-9 PCP_SERVER .................................... 17-18
MOD........................................................ 4-9 Period duration measurement............. 19-25
modulo .................................................... 4-9 platform ................................................... 1-5
MOVE.................................................... 4-10 PLC_SYS_TICK_CNT .......................... 1-34
movement ............................................. 4-10 PLC_TICKS_PER_SEC........................ 1-34
MUL....................................................... 4-11 PLCDEBUG_BPSET ............................ 1-34
multiplication ......................................... 4-11 PLCDEBUG_FORCE............................ 1-34

A-10 5958B
Index

PLCDEBUG_POWERFLOW ................ 1-34 RD_INPUT_GROUP ........................... 15-16


PLCMODE ............................................ 1-33 RD_INT_BY_SYM ................................ 14-9
PLCMODE_HALT ................................. 1-34 RD_SINT_BY_SYM .............................. 14-9
PLCMODE_ON ..................................... 1-33 RD_STRING_BY_SYM......................... 14-9
PLCMODE_RUN................................... 1-33 RD_WORD_BY_SYM ........................... 14-9
PLCMODE_STOP................................. 1-33 reading - input group........................... 15-16
Possible status of the copy process for REAL_TO_BOOL.................................. 2-58
*_TO_BUF function blocks ..... 17-31 REAL_TO_BUF .................................. 17-25
Possible status of the copy process for REAL_TO_BYTE .................................. 2-59
BUF_TO_* function blocks ..... 17-39
REAL_TO_DINT ................................... 2-64
POWER ON .......................................... 1-27
REAL_TO_DWORD.............................. 2-61
processor ................................................ 1-5
REAL_TO_INT...................................... 2-63
ProConOS function blocks .................... 15-3
REAL_TO_SINT ................................... 2-62
ProConOS functions ............................. 14-3
REAL_TO_STRING ................................ 9-4
ProConOS system flags........................ 1-33
REAL_TO_WORD ................................ 2-60
program................................................. 1-24
Receive data from an ETH
associate to task ............................. 1-24 controller board ........................ 18-6
in PROGRAM WORX ..................... 1-24 REPLACE ............................................. 9-25
program execution .................................. 1-4 reset dominant ...................................... 10-5
project resource ................................................ 1-16
download ........................................ 1-26 declare............................................ 1-17
pulse............................................. 13-3, 13-5 restart .................................. 14-3, 14-6, 14-7
Pulse width modulation ....................... 19-28 restrictions............................................... 1-6
retentive data
R memory........................................... 1-13
R_BIT_IN_* ......................................... 16-12 RFC_EMERGENCY_ STOP_NOT_SET 1-38
R_BIT_IN_BYTE ................................. 16-12 RFC_LED_START ................................ 1-38
R_BIT_IN_DWORD ............................ 16-12 RFC_OHP_LOGGED_ON .................... 1-38
R_BIT_IN_WORD ............................... 16-12 RFC_POWER_SWITCHED_ON .......... 1-38
R_TRIG ................................................. 11-5 RFC_PUSH_BUTTON_ START ........... 1-38
RD_*_BY_SYM ..................................... 14-9 RFC_SWITCH_ON_ POWER .............. 1-38
RD_BOOL_BY_SYM .......................... 15-14 RIGHT................................................... 9-27
RD_BYTE_BY_SYM ............................. 14-9 right rotation ..................................... 6-6, 6-7
RD_DINT_BY_SYM .............................. 14-9 right shifting.................................. 6-10, 6-11
RD_DWORD_BY_SYM ........................ 14-9 rightmost characters ............................. 9-27

5958B A-11
Index

rising edge detection ............................. 11-5 selection....................................... 7-10, 7-11


rising trigger .......................................... 11-5 Selection functions .................................. 7-3
ROL......................................................... 6-4 set dominant ......................................... 10-3
ROL_* ..................................................... 6-5 SET_LSB .............................................. 16-8
ROL_BYTE ............................................. 6-5 SET_MSB ............................................. 16-9
ROL_DWORD......................................... 6-5 setting - outputs to zero ........................ 15-4
ROL_WORD ........................................... 6-5 shared memory flags ............................ 1-14
ROR ........................................................ 6-6 shifting - left...................................... 6-8, 6-9
ROR_*..................................................... 6-7 shifting - right ............................... 6-10, 6-11
ROR_BYTE............................................. 6-7 SHL ......................................................... 6-8
ROR_DWORD ........................................ 6-7 SHL_*...................................................... 6-9
ROR_WORD........................................... 6-7 SHL_BYTE.............................................. 6-9
rotation - left ..................................... 6-4, 6-5 SHL_DWORD ......................................... 6-9
rotation - right ................................... 6-6, 6-7 SHL_WORD............................................ 6-9
RS ......................................................... 10-5 SHR ...................................................... 6-10
RUN ...................................................... 1-27 SHR_* ................................................... 6-11
SHR_BYTE ........................................... 6-11
S SHR_DWORD ...................................... 6-11
S_BIT_IN_* ......................................... 16-14 SHR_WORD ......................................... 6-11
S_BIT_IN_BYTE ................................. 16-14 SIN ........................................................ 3-12
S_BIT_IN_DWORD............................. 16-14 sine ....................................................... 3-12
S_BIT_IN_WORD ............................... 16-14 single complement .................................. 5-4
searching - symbolic name ................... 15-8 SINT_TO_B_BCD ................................. 2-65
SEL ....................................................... 7-10 SINT_TO_BOOL................................... 2-68
SEL_* .................................................... 7-11 SINT_TO_BUF.................................... 17-25
SEL_BOOL ........................................... 7-11 SINT_TO_BYTE ................................... 2-69
SEL_BYTE ............................................ 7-11 SINT_TO_D_BCD................................. 2-67
SEL_DINT ............................................. 7-11 SINT_TO_DINT .................................... 2-73
SEL_DWORD ....................................... 7-11 SINT_TO_DWORD ............................... 2-71
SEL_INT................................................ 7-11 SINT_TO_INT ....................................... 2-72
SEL_REAL ............................................ 7-11 SINT_TO_REAL ................................... 2-74
SEL_SINT ............................................. 7-11 SINT_TO_STRING ................................. 9-4
SEL_STRING........................................ 7-11 SINT_TO_W_BCD ................................ 2-66
SEL_TIME............................................. 7-11 SINT_TO_WORD ................................. 2-70
SEL_WORD .......................................... 7-11 SLAVE_DIAG_STATUS_ ..................... 1-36

A-12 5958B
Index

SLAVE_DIAG_STATUS_REG_FAIL .... 1-36 strings - delete ........................................ 9-9


SLAVE_DIAG_STATUS_REG_INIT ..... 1-36 strings - detect position ......................... 9-12
SLAVE_DIAG_STATUS_REG_POWER_ON strings - insert ....................................... 9-15
.................................................. 1-36 strings - leftmost characters .................. 9-18
SLAVE_DIAG_STATUS_REG_RDY .... 1-36 strings - length ...................................... 9-20
SPG....................................................... 1-19 strings - middle...................................... 9-22
SQRT .................................................... 3-13 strings - replace .................................... 9-25
square root ............................................ 3-13 strings - rightmost characters................ 9-27
SR ......................................................... 10-3 SUB....................................................... 4-14
STOP .................................................... 1-27 SUB_T_T .............................................. 4-15
string subtraction ................................... 4-14, 4-15
*TO_STRING functions .................. 1-46 SWAP ................................................. 16-19
compatibility .................................... 1-48 system flags ................................. 1-14, 1-33
construction of the format string ..... 1-47 Coprozessor ................................... 1-37
STRING_TO_* functions ................ 1-42 Digital Inputs................................... 1-37
String specialties of the function block INTERBUS Master ......................... 1-34
BUF_TO_STRING ................. 17-40
INTERBUS Slave ........................... 1-36
String specialties of the function block
Remote Field Controller.................. 1-38
STRING_TO_BUF ................. 17-32
system manager ..................................... 1-4
STRING_TO_* ...................................... 2-75
system task ........................................... 1-19
STRING_TO_BUF .............................. 17-25
system ticks .......................................... 1-34
STRING_TO_BUFFER ....................... 16-17
System time for ETH controller boards 18-10
STRING_TO_BYTE .............................. 2-75
systemprograms ................................... 1-19
STRING_TO_DINT ............................... 2-75
STRING_TO_DWORD.......................... 2-75
T
STRING_TO_INT.................................. 2-75
TAN....................................................... 3-14
STRING_TO_REAL .............................. 2-75
tangent .................................................. 3-14
STRING_TO_SINT ............................... 2-75
STRING_TO_TIME ............................... 2-75
STRING_TO_WORD ............................ 2-75
strings.................................................... 1-41
Error treatment of string errors ....... 1-41
strings - compare ............... 9-11, 9-13, 9-14,
................................9-17, 9-21, 9-24
strings - concatentation ........................... 9-7

5958B A-13
Index

task truncation .............................................. 2-79


cyclic task ....................................... 1-19 type conversion - cut decimal places .... 2-79
declare ............................................ 1-22 Type conversion functions ...................... 2-5
DEFAULT task................................ 1-18
error task......................................... 1-19 U
event task ....................................... 1-19 up counting .................................. 12-3, 12-7
initial task ........................................ 1-19
level ................................................ 1-17 V
ProConOS tasks ............................. 1-18 variable
supervisor task................................ 1-18 bitsize ............................................. 1-12
system task.............................. 1-5, 1-19 declaration ............................. 1-11, 1-12
user task ......................................... 1-18 in PROGRAM WORX ..................... 1-15
watchdog ........................................ 1-23 location ........................................... 1-12
TCP/IP Communication Blocks ............. 18-3 symbolic name................................ 1-11
TCP/IP connection .. 18-4, 18-6, 18-8, 18-10 variables
technical data .......................................... 1-6 located ............................................ 1-12
TIME_TO_BUF ................................... 17-25 symbolic variables .......................... 1-11
TIME_TO_DINT .................................... 2-78
TIME_TO_STRING ................................. 9-4 W
timer ............. 13-3, 13-5, 13-8, 13-10, 13-15 W_BCD_TO_DINT................................ 2-82
Timer function blocks ............................ 13-3 W_BCD_TO_INT .................................. 2-81
Timing diagram ........................ 17-28, 17-36 W_BCD_TO_SINT ................................ 2-80
TOF_R ................................................ 13-15 WARM_RESTART ................................ 14-7
TON....................................................... 13-8 watchdog............................................... 1-23
TON_R ................................................ 13-10 WORD_TO_BOOL................................ 2-83
TP.......................................................... 13-3 WORD_TO_BUF ................................ 17-25
TP_R ..................................................... 13-5 WORD_TO_BYTE ................................ 2-84
Transmit data to an ETH controller board 18-8 WORD_TO_DINT ................................. 2-88
trigger - falling ....................................... 11-3 WORD_TO_DWORD............................ 2-85
trigger - rising ........................................ 11-5 WORD_TO_INT.................................... 2-87
trigonometric functions ............................ 3-3 WORD_TO_REAL ................................ 2-89
TRUNC_* .............................................. 2-79 WORD_TO_SINT ................................. 2-86
TRUNC_DINT ....................................... 2-79 WORD_TO_STRING .............................. 9-4
TRUNC_INT.......................................... 2-79 WR_*_BY_SYM .................................. 14-11
TRUNC_SINT ....................................... 2-79

A-14 5958B
Index

WR_BOOL_BY_SYM............... 14-11, 15-18


WR_BYTE_BY_SYM .......................... 14-11
WR_DINT_BY_SYM ........................... 14-11
WR_DWORD_BY_SYM...................... 14-11
WR_INT_BY_SYM.............................. 14-11
WR_OUTPUT_GROUP ...................... 15-21
WR_SINT_BY_SYM ........................... 14-11
WR_STRING_BY_SYM ...................... 14-11
WR_WORD_BY_SYM ........................ 14-11
writing - output group .......................... 15-21

X
XOR ........................................................ 5-6
xx1....................................................... 19-37

Z
zipped project
download ........................................ 1-27

5958B A-15
Index

A-16 5958B
We Are Interested in Your Opinion!
We would like to hear your comments and suggestions concerning this
document.
We review and consider all comments for inclusion in future documen-
tation.
Please fill out the form on the following page and fax it to us or send your
comments, suggestions for improvement, etc. to the following address:
Phoenix Contact GmbH & Co.
Marketing Services
Dokumentation INTERBUS
32823 Blomberg
Germany
Phone +49 - (0) 52 35 - 3-00
Telefax +49 - (0) 52 35 - 3-4 20 66
E-Mail tecdoc@phoenixcontact.com

5050df17
FAX Reply
Phoenix Contact GmbH & Co. Date:
Marketing Services
Dokumentation INTERBUS Fax No: +49 - (0) 52 35 - 3-4 20 66

From:
Company: Name:
Department:
Address: Job function:
City, ZIP Phone:
code:
Country: Fax:

Document:
Designation: Revision: Order No.:

My Opinion on the Document


Form Yes In part No
Is the table of contents clearly arranged?
Are the figures/diagrams easy to understand/helpful?
Are the written explanations of the figures adequate?
Does the quality of the figures meet your expectations/needs?
Does the layout of the document allow you to find information easily?

Contents Yes In part No


Is the phraseology/terminology easy to understand?
Are the index entries easy to understand/helpful?
Are the examples practice-oriented?
Is the document easy to handle?
Is any important information missing? If yes, what?

Other Comments:

5050df17

Вам также может понравиться