Unity Super Pro
Unity Super Pro
33003021 10/2013
www.schneider-electric.com
The information provided in this documentation contains general descriptions and/or technical
characteristics of the performance of the products contained herein. This documentation is not
intended as a substitute for and is not to be used for determining suitability or reliability of these
products for specific user applications. It is the duty of any such user or integrator to perform the
appropriate and complete risk analysis, evaluation and testing of the products with respect to the
relevant specific application or use thereof. Neither Schneider Electric nor any of its affiliates or
subsidiaries shall be responsible or liable for misuse of the information contained herein. If you
have any suggestions for improvements or amendments or have found errors in this publication,
please notify us.
No part of this document may be reproduced in any form or by any means, electronic or
mechanical, including photocopying, without express written permission of Schneider Electric.
All pertinent state, regional, and local safety regulations must be observed when installing and
using this product. For reasons of safety and to help ensure compliance with documented system
data, only the manufacturer should perform repairs to components.
When devices are used for applications with technical safety requirements, the relevant
instructions must be followed.
Failure to use Schneider Electric software or approved software with our hardware products may
result in injury, harm, or improper operating results.
Failure to observe this information can result in injury or equipment damage.
© 2013 Schneider Electric. All rights reserved.
2 33003021 10/2013
Table of Contents
Safety Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
About the Book. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Chapter 1 Introduction to the EFB Toolkit Methodology . . . . . . . 11
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Chapter 2 EFB Toolkit Services and User Functions . . . . . . . . . . 13
Program Installation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
How to Register the Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Product Specifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
EFB Toolkit Commands. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Installable Families . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Comparison Between the Different Block Types . . . . . . . . . . . . . . . . . 29
Multi Language Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Help on Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Chapter 3 Coding Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Coding Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
Addressing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Constant Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Local Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
EFB Data Instances. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
EN/ENO Pins. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
Extensible Pins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
Chapter 4 Programming Examples . . . . . . . . . . . . . . . . . . . . . . . . 51
EF/EFB Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
EF Program Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
EFB Header File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
EFB Source Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
DDT Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
Chapter 5 Debugging. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
Debug Preparation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
Best Practices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
Recommendations. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
Chapter 6 System Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
6.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
System Service Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
33003021 10/2013 3
6.2 Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
s_AliGetProgStat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
s_log_to_phy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
s_obj_to_log. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
s_obj_nbr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
s_rd_16bits. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
s_rd_1bit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
s_rd_bit_attrib . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
s_rd_internalwords. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
s_rd_Nbits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
s_rd_sysbit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
s_rd_sysword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
s_wr_16bits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
s_wr_1bit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
s_wr_bits_attrib . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
s_wr_internalwords . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
s_wr_Nbits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
s_wr_sysbit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
s_wr_sysword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
s_cnt_100ms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
s_cnt_10ms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
s_cnt_1ms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
s_date_and_time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
s_syscnt_10ms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
s_current_task . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
s_set_ffb_error . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
s_set_ffb_error_addi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
s_diag_RegisterExtError . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
s_diag_DeregisterError . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
s_of_passw_check. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
s_of_passw_test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
s_demask_it . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
s_GetUSecs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
s_mask_it . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
s_proc_indic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
s_proc_type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
Appendices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
4 33003021 10/2013
Appendix A PL7/Concept EF/EFB Migration. . . . . . . . . . . . . . . . . . . 145
A.1 PL7 and Concept EF/EFB Migration . . . . . . . . . . . . . . . . . . . . . . . . . . 146
PL7 EF Migration. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
A.2 PL7 EF Migration Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
Retrieving Source Files from the PL7 Development Environment . . . 148
Migration Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
PL7 EF Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
Unity Pro EF Code. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
A.3 Concept EF/EFB Migration Procedure . . . . . . . . . . . . . . . . . . . . . . . . 155
Retrieving Source Files from a Concept Development Environment . 156
Migrating the Function Block Code to Unity Pro . . . . . . . . . . . . . . . . . 157
Concept EF/EFB Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160
Unity Pro EF Code. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
A.4 Other Case Studies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
User-defined Data Types (PL7 only) . . . . . . . . . . . . . . . . . . . . . . . . . 164
Floating Point Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
ANY... Data Types. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
REF... Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
Determining the PLC State . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
Reporting User Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
Extensible inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172
A.5 Comparison Between PL7/Concept and Unity Pro . . . . . . . . . . . . . . . 176
Common System for EF/EFBs in Unity Pro . . . . . . . . . . . . . . . . . . . . . 177
Data Types Comparison: PL7/Concept and Unity Pro . . . . . . . . . . . . 181
PL7 SDKC Include File: <Cstsyst.h> Versus <SystemLib.h> (PL7
Only) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
A.6 An Empty Frame for a Unity Pro EF . . . . . . . . . . . . . . . . . . . . . . . . . . 186
Example_EF1 Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
Example_EF1 Header File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188
Example_EF1 C-Source Template . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
Programming Hints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
Index ......................................... 197
33003021 10/2013 5
6 33003021 10/2013
Safety Information
Important Information
NOTICE
Read these instructions carefully, and look at the equipment to become familiar with the device
before trying to install, operate, or maintain it. The following special messages may appear
throughout this documentation or on the equipment to warn of potential hazards or to call attention
to information that clarifies or simplifies a procedure.
33003021 10/2013 7
PLEASE NOTE
Electrical equipment should be installed, operated, serviced, and maintained only by qualified
personnel. No responsibility is assumed by Schneider Electric for any consequences arising out of
the use of this material.
A qualified person is one who has skills and knowledge related to the construction and operation
of electrical equipment and its installation, and has received safety training to recognize and avoid
the hazards involved.
8 33003021 10/2013
About the Book
At a Glance
Document Scope
This documentation describes the EFB Toolkit.
Validity Note
This documentation is valid for EFB Toolkit V8.0.
If you are programming function blocks in ’C’, you have to be aware of such consequences. A ’C’
coded function block is a piece of code compiled from a standard ’C’ compiler used inside the PLC.
There are no security checks inside Unity Pro or inside the PLC that check the function block code
for correct operation. If the code is not correct, the PLC memory may be corrupted at any location
inside the PLC. As a consequence the PLC may crash or behave unexpectedly.
WARNING
UNEXPECTED PLC BEHAVIOR
Always check the function block code very carefully to make sure that it is working correctly. For
the test and debugging phase, always use the PLC Simulator of Unity Pro instead of a real PLC.
Failure to follow these instructions can result in death, serious injury, or equipment
damage.
Schneider Electric does not take any warranty for ’C’ coded function blocks written by users of the
EFB Toolkit. This is also valid for the consequences of damages or injuries caused by incorrectly
coded function blocks.
33003021 10/2013 9
Working Manually on The Function Block Files
WARNING
UNEXPECTED PLC BEHAVIOR
Do not modify or delete any file located in the family development directory (FFBDev) using tools
other than the EFB Toolkit. All these files are generated and managed by the EFB Toolkit and
absolutely necessary to generate the installable form of the family. Any modification within this
directory can lead to unexpected EFB Toolkit behavior or the generation of wrong executable
code and result in unexpected PLC behavior.
Failure to follow these instructions can result in death, serious injury, or equipment
damage.
WARNING
UNEXPECTED PLC BEHAVIOR
Do not move or delete any file located in the installable form directory (FFBInst). All these files
are generated and managed by the EFB Toolkit and necessary to install the family into the
UnityPro libset. Any modification within this directory can lead to a corrupted installable form and
result in unexpected PLC behavior.
Failure to follow these instructions can result in death, serious injury, or equipment
damage.
10 33003021 10/2013
EFB Toolkit for Unity Pro
The EFB Toolkit Methodology
33003021 10/2013
Chapter 1
Introduction to the EFB Toolkit Methodology
Introduction
General
The EFB Toolkit enables you to generate customized functions and function blocks. It provides a
complete development environment for programming, creating, and installing libraries. Tasks are
started via menu picks in the development environment. The menus launch batch processes that
carry out all required steps automatically.
Families
All of the elements in these user-defined functions and their associated content are stored in a unit
called a family. A family may comprise:
z elementary function (EF)
z elementary function block (EFB)
z derived data type (DDT)
z derived function block (DFB)
User-defined EFBs
The EFB Toolkit enables experienced users to generate custom EFBs for their applications. These
user-defined EFs and EFBs can be managed in libraries in a manner similar to the way standard
functions and function blocks are delivered with Unity Pro. (The libraries for EFB Toolkit functions
are not the same ones that are delivered with Unity Pro.)
NOTE: There is no difference between elementary and user-defined functions/function blocks
within Unity Pro.
DDTs
You can define data structures or data arrays in the DDT section of the family.
33003021 10/2013 11
The EFB Toolkit Methodology
IEC Languages
Unity Pro applications can be created in several languages (FBD, SFC, LD, ST, IL, LL984) using
blocks provided in accordance with IEC1131.
Programming Language
EFs and EFBs are developed with a reduced-functionality version of the ’C’ programming
language. The reduced functionality is described in more detail in following chapters.
Method Description
Function A function has 1 output value (return pin).
Procedure A procedure could have 1 to n output values (return pins) and 1 to m input values.
DSC Files
Do not modify any .dsc file using tools other than the EFB Toolkit. This can provide inconsistent
data.
12 33003021 10/2013
EFB Toolkit for Unity Pro
Services and User Functions
33003021 10/2013
Chapter 2
EFB Toolkit Services and User Functions
Introduction
This chapter provides an overview of the services and user functions of the EFB Toolkit.
33003021 10/2013 13
Services and User Functions
Program Installation
Product Content
The EFB Toolkit consists of:
z CD-ROM 1
z EFB Toolkit software
z installation software
z a registration tool (see page 15)
z the Microsoft C++ compiler
z user documentation
z an installation note
z CD-ROM 2
z GNU ARM C compiler
z DVD-ROM 3
z Microsoft Visual Studio
Operating Systems
The setup program for the EFB Toolkit must be launched on Windows XP Professional or Windows
7 Professional (32 or 64 bit).
Installation
The installation procedure for the EFB-Tookit is similar to the Unity Pro installation. The following
table shows the steps for installation.
Step Action
1 Install the EFB Toolkit CD-ROM.
If autostart of CD-ROM is deactivated, use \setup.exe to start the installation.
2 Install the Gnu ARM C compiler CD-ROM.
If autostart of CD-ROM is deactivated, use \setupGNU.exe to start the
installation.
3 Install the Microsoft Visual Studio DVD-ROM.
If autostart of DVD-ROM is deactivated, use \setup.exe to start the installation.
14 33003021 10/2013
Services and User Functions
At a Glance
To obtain permanent user rights for the EFB Toolkit software, you must register it with Schneider
Electric. Once the software is installed, you must register within 21 days.
Procedure
A wizard guides you through the registration procedure. Here is a flowchart:
33003021 10/2013 15
Services and User Functions
Product Specifications
16 33003021 10/2013
Services and User Functions
Navigation Pane
The navigation pane displays a structure view of the family. The root item describes the family.
Each sub-item corresponds to an EF or an EFB.
You can select a DDT defined in the family from the DDT folder.
Main Pane
The tabs on the main pane correspond to items selected in the navigation pane:
z Family
z Family description
Here you may select a family name, a version number and a name for the Unity Pro library.
You can also add comments.
Select or generate a library in Library Management ...
z EF/EFB
z EFB description
Here you may select or generate information such as an EF/EFB name, an author´s name
and a long or short description of the EF/EFB.
z EFB log file
This register displays read-only EF/EFB analysis information, i.e., errors and warnings.
z EFB header
The header file for an EF or EFB.
z EFB source
Here you may display and edit the source code for an EF or EFB.
z DDT
z DDT description
Here you may select or generate a DDT name, an author´s name and a long or short
description of a DDT.
z DDT header
The header file for the DDT.
Log Pane
The Log Pane shows operation results such as errors and warnings that may occur during the
generation, compilation or build of the function blocks.
33003021 10/2013 17
Services and User Functions
File
The File commands are used to create a new family or to open an existing family. You may install
the current family into the Unity Pro libset so that you may use the customized EFs, EFBs or DDTs.
To edit the EFB Toolkit settings, use the File → Settings... command. A dialog box will be
displayed.
You have 3 possible settings:
z Directories
Select the development and installation directory for the EFB Toolkit and the Target library.
z Build Options
The Build Options allow you to:
z select the Environment for Microsoft Visual C 32bit, GNU C ARM ELF, or GNU C ARM5
ELF
z insert or edit Compiler Options
z add additional link libraries
z edit the behavior of warning messages
z suppression of linker and compiler messages
WARNING
UNEXPECTED PLC BEHAVIOR
Normally, it’s not necessary to modify the compiler options, except you have to define symbols
or constants for your source code. Be careful when modifying any compiler option on the Build
Options sheet of the EFB Toolkit Settings dialog. Refer to the documentation of the compiler
for a detailed description of the different settings. Using bad compiler settings can lead to the
generation of wrong executable code and result in unexpected PLC behavior.
Failure to follow these instructions can result in death, serious injury, or equipment
damage.
18 33003021 10/2013
Services and User Functions
The File command also lets you specify some additional libraries to be linked with the family. It
also lets you modify the warning levels in the analysis messaging and hide the Microsoft and
Plink messages.The File command also lets you specify some additional libraries to be linked
with the family.
You may launch a browser to choose an EF or an EFB to import it into the current family. When
you import, all the needed files are copied to the family, and the family description is updated.
You must analyze and generate all the EFs or EFBs to validate the import. To avoid the problem
of having two EFs or EFBs with the same name, there is an option to remove the imported EFB
from its original family.
To print, select File → Print. Executing this command prints the whole family, including the
description file, EF/EFB source files and comments. When a print operation is launched, a
dialog box appears where you can select the printer settings.
z Language
Select the languages for your project (see also Multi Language Support, page 31).
33003021 10/2013 19
Services and User Functions
z Text Editor
You can choose different color, sizes, and font for the source code that is appearing on header
and source file. You can select different colors for Keyword, Comment, Text Selection,
Operator, Number and other text appearing in the source/header file.
Edit
The Edit menu contains items common to most other MS Windows applications. It also lets you
clear the log pane.
View
The View menu lets you select different views of the EFB Toolkit software. For example, you may
toggle between full screen mode and the standard screen display.
20 33003021 10/2013
Services and User Functions
Current family
The Current family menu appears as soon as a family has been opened or created. The options
available under this menu include:
z Create EF/EFB or Create DDT, where you can create or add an EF, EFB or DDT
z Add External DFB, which allows you to add DFBs into your current family that is defined by
Unity Pro and present in libset
z Add External DDT, which allows you to add DDTs into your current family that is defined by
Unity Pro and present in libset
z Analyze and Generate code for all EF/EFB, which analyzes the description file of each
EF/EFB. If no errors occur, it generates:
z default source code (*.c and *.h files)
z an EF/EFB comment file
z an EF/EFB template file
z Compile all EF/EFB code, which compiles each EF/EFB in 32-bit format
z Make the installable form of the family, which patches object files and copies the necessary
files to the install directory
z Rebuild all, which launches successively the three operations above (useful, for example,
when a comment is modified)
z Debug all EF/EFBs
These commands apply to the whole family. When a command is selected, it is executed
successively on each EF/EFB in the family.
Current Object
The Current Object menu allows the code of the current EF or EFB to be analyzed, generated and
compiled. Once an EF/EFB has been selected in the navigation pane, the following items are
enabled:
z Analyze and Generate code
z Compile code
z Delete Current Object
To delete an EF, EFB or DDT, you must select that item in this menu.
These are the same commands that appear in the Family menu. Here they are applied to the
current EF or EFB.
Help
The Help command invokes the help files in the EFB Toolkit software.
Context Menu
The programmer has the possibility to use the right mouse button dependent on the selected item.
33003021 10/2013 21
Services and User Functions
Installable Families
22 33003021 10/2013
Services and User Functions
Development Cycle
The following figure shows the development cycle within the EFB Toolkit.
33003021 10/2013 23
Services and User Functions
EF/EFB Options
The following figure shows the program window for the EF/ EFB definition after the selection of the
EF/EFB name.
The possible values for Kind are Function or Procedure in case of EF or only Function in case
of EFB.
The programmer is able to create different kinds of pins, basic data types or extended data. If the
pin is selected by the checkbox, this one is an extensible pin. That means the user has the
possibility to extend the number of pins within Unity Pro. The programmer can define the number
of pins from 2...32. The maximum number of all input pins is 32.
The pin position can be changed by the programmer.
Descriptive Form
The descriptive form is available within Unity Pro. The user has access to the information in Unity
Pro → Types Lib Browser → Properties.
24 33003021 10/2013
Services and User Functions
Kinds
For Kind you can select Structure or Array.
Additionally you have to enter the following information for the new DDT:
z Name
z Version
z Comment
This information is necessary for Unity Pro after changes within used DDTs.
The following figure shows the program window for selecting a variable structure (struct or
array).
The following figure shows the program window for selecting the DDT information for a structure.
33003021 10/2013 25
Services and User Functions
26 33003021 10/2013
Services and User Functions
The following figure shows the Add External DFBs dialog box for selecting the DFBs:
33003021 10/2013 27
Services and User Functions
The following figure shows the Add External DDTs dialog box for selecting the DDTs:
28 33003021 10/2013
Services and User Functions
Comparison Table
The following table gives the comparison between an elementary function and a procedure:
NOTE: LOOKUP_TABLE1 is a known exception to these rules. It has several outputs and extensible
pins. In this case, LOOKUP_TABLE1 will be a procedure.
33003021 10/2013 29
Services and User Functions
30 33003021 10/2013
Services and User Functions
Introduction
You can deliver new families of EFs, EFBs and/or DDTs with different description. These
descriptions will be written in a single source language. The EFB Toolkit creates different
directories for the possible languages. After the creation of the new family, the directories contain
the language files for the translation. After the translation the files can be bound to the family.
NOTE: The EFB Toolkit is not a translation tool. The language files must be translated by other
resources.
The check boxes enable the supported languages for the specific family. At least one check box
must be selected. For every selected language a directory with the language name will be created.
The radio buttons select the source language. In this example, English is the source language.
All other directories will get a copy of the language files from the source directory, in case the
Update comment check box is enabled. This copy will be created after every change within the
family.
33003021 10/2013 31
Services and User Functions
You can translate the copied language files. After translation, deselect the check box Update
comment files for other languages automatically from reference language files to avoid
overwriting them again.
This is useful, if you make only minor changes in the descriptions or if you make only changes at
the EFs, EFBs or DDTs.
WARNING
UNEXPECTED PLC BEHAVIOR
Be careful when modify any setting on the Language sheet of the EFB Toolkit Settings dialog.
Unchecking the automatic update of comment files can lead to inconsistent variable layout of the
EF/EFB or DDT. It’s highly recommended to uncheck this option only in the case when the
comment files were translated to prevent them from overwriting. Before changing the layout of an
EF/EFB or DDT check this option again to keep the comment files consistent, but be sure to
backup the translated comment files on a save location. Using inconsistent comment files can
lead to the generation of wrong executable code and result in unexpected PLC behavior. Best
practice is to translate the EF/EFB and DDT comment files not before all EF/EFB interfaces and
DDT layouts are stable.
Failure to follow these instructions can result in death, serious injury, or equipment
damage.
Supported Languages
The following languages are supported:
z English
z French
z German
z Spanish
z Italian
z Chinese
z Japanese
32 33003021 10/2013
Services and User Functions
Help on Type
General
You can create HTML help files for EFs, EFBs and DDTs generated with the EFB Toolkit.
These files will be copied to the Libset directory when installing the family in Unity Pro.
In Unity Pro dialogs for selecting FFBs there is a Help on Type button. With this button you can
launch the help for a selected FFB.
Directory Structure
For every user-defined family the EFB Toolkit creates a new directory (e.g. MyFamily) beneath
the installation directory with the following subdirectories:
z language subdirectories (e.g. CHI, ENG, FRE...)
z code subdirectory
33003021 10/2013 33
Services and User Functions
Step Action
1 Create an HTML help file for your FFB (e.g. with any kind of HTML editor).
Note: The HTML file name must be exactly the same as the name of your FFB and the extension
must be *.htm.
2 Copy this file into all language folders (ENG, FRE ...). See structure above.
3 Copy all the files (e.g. graphics) you are referencing in your HTML file to the HELP folder. See
structure above.
4 Install your user-defined family in Unity Pro.
Result:
All the files will be copied to the Libset directory and the HTML help file will be launched when you
click the Help on Type button.
34 33003021 10/2013
EFB Toolkit for Unity Pro
Coding Rules
33003021 10/2013
Chapter 3
Coding Rules
Coding Rules
Summary
This chapter provides an overview of the coding rules in the EFB Toolkit.
33003021 10/2013 35
Coding Rules
Coding Rules
General
The following coding examples are abstracts from complete programs. They are presented here
to clarify the declared rules.
Coding Rules
z EFs/EFBs are reentrant functions with a ’C’ interface that returns Boolean values (IECBool).
z All EFs/EFBs must return a valid value that describes the execution state:
z TRUE for no errors; warnings are possible
z FALSE for error
If an EF/EFB does not detect any errors, it always returns with TRUE.
z EFs/EFBs must not allocate dynamic memory; they always work with assigned memory.
z The generated EF/ EFB code is entirely portable within PLC memory, and moving it does not
introduce any changes.
z CONST segment and DATA segment cannot be used in EF/EFB code.
z Global data cannot be used in EF/EFB code.
z Switch cases cannot handle more than three cases.
z Physical pointers should be declared as __far.
z Only the LSB (bit 0) of a Boolean (IECBool) value is significant. Other bits should be masked
before testing for TRUE/FALSE.
z Temporary variables may use only processor stack space.
z EFs/EFBs may access system functions via System Service calls.
z EFs/EFBs may access PLC resources only through System Service calls, never directly.
z If necessary, EFs/EFBs can use self-written static sub-functions. To improve performance, you
may design functions, such as C++-inline functions, and you may write them in assembly
language.
z Ensure that all system service calls, all self-written sub-functions and all used C-library calls are
reentrant.
z Each EF/EFB type gets its own source module.
z Whenever possible, write the source codes of generic EFs with generic data type and function
names. The adaptation to the real data types is done by front-end compiler definitions when
compiled.
z EFs/EFBs may write only permitted type and range data in memory. For example, Boolean
(IECBool) values may be defined for only 0 (FALSE) and 1 (TRUE).
z The order of EF/EFB parameters is provided in the Unity EFB Toolkit.
z The passing type (by value or by logical address) of EF/EFB parameters is given by Unity
EFB Toolkit.
36 33003021 10/2013
Coding Rules
EBOOL
The EBOOL contains the value FALSE (=0) or TRUE (=1) and also information about the
management of falling or rising edges and forcing bits.
Example:
/////////////////////////////////////////////////////////
#if defined(__arm__) && defined(__GNUC__)
IECEBool far *pIN1;
#endif
unsigned short NbAcces16Bit,I;
#if defined(__arm__) && defined(__GNUC__)
pIN1 = s_log_to_phy(IN1.IECPtr_Log);
#endif
#if defined(__arm__) && defined(__GNUC__)
Tampon1 = rd_Nbits(pIN1,TAILLE_ACCES16_ARX);
#else
Tampon1 = s_rd_16bits(IN1.IECPtr_Log);
#endif
33003021 10/2013 37
Coding Rules
38 33003021 10/2013
Coding Rules
Addressing
Addressing Rules
Before using variables, the programmer must to convert logical into physical addresses.
33003021 10/2013 39
Coding Rules
40 33003021 10/2013
Coding Rules
Constant Values
Constant Values
The user must complete the following declaration to access the constants.
Constant Declaration
The programmer must to declare constant values at the global level. The following program codes
show the declaration.
// Constant declaration
const STRING32 cllbk_Tab2[32] = { "Motor 1", "Motor 2"
};s_Declare_Logical(cllbk_Tab2);
// Constant declaration
const IECInt cllbk_calendar[12] = {31,28,31,30,31,30,31,31,30,31,30,31}
;
s_Declare_Logical(cllbk_calendar);
const IECReal cllbk_Pi = (IECReal)3.1415999;
s_Declare_Logical(cllbk_Pi);
NOTE: Pay attention to the following:
z declaration should be global
z keyword const is mandatory
z constant name should start with cllbk_
z use of s_Declare_Logical macro is mandatory in the declaration
The following program code shows an example for the declaration of constants in the procedure.
// Declaration of local variables
// Declare and initialize a pointer on the same data type as the consta
nt to access
IECInt __far *phy_calendar = s_Const_Instance(cllbk_calendar);
IECReal __far * x = s_Const_Instance(cllbk_Pi);
33003021 10/2013 41
Coding Rules
42 33003021 10/2013
Coding Rules
Local Functions
Usual Case
If logical addresses in local functions are not needed, you should:
z start the subroutine names with s_
z prototype the function call model as __near for 16-bit compatibility
z use no more than four bytes (including structs and unions) for return values
z provide a parameter (a pointer to a buffer where the value will be returned) in the calling program
to return structs or unions larger than four bytes
z do not use floating-point return values
Special Case
If logical addresses in local functions are needed (e. g., callback functions), you should:
z start the subroutine names with cllbk_
z prototype the function call model as __near for 16-bit compatibility
z use no more than four bytes (including structs and unions) for return values
z provide a parameter (a pointer to a buffer where the value will be returned) in the calling program
to return structs or unions larger than four bytes
z do not use floating-point return values
33003021 10/2013 43
Coding Rules
NOTE:
z declarations are GLOBAL
z function names start with cllbk_
z the s_Declare_Logical macro is mandatory in the declaration
The cllbk_function function should be declared in the C code the same as any other ’C’
function.
44 33003021 10/2013
Coding Rules
33003021 10/2013 45
Coding Rules
EN/ENO Pins
Error Management
All function blocks return FALSE or TRUE, according to error/warning situation detected, to manage
ENO pins:
RETURN (TRUE); // ENO = TRUE (no error occurs)
RETURN (FALSE); // ENO = FALSE (an error occurs)
Additionally the function blocks can manage their own system errors by calling the system
diagnostic. The EFB-Toolkit provides two possible external prototypes for system functions:
s_set_ffb_error (int errno)
and
s_set_ffb_error_addi (int errno, int param
NOTE: You can analyze the error code with the diagnostic viewer in Unity Pro.
Here are the standard register error number errno messages in the diagnostic buffer:
z errno < 0
In this case, the value returned by the function block should be FALSE, setting the ENO pin to
FALSE.
The diagnostic viewer will display:
ERROR FFB /errno/
z errno > 0
In this case, the value returned by the function block should be TRUE, setting the ENO pin to
TRUE.
The diagnostic viewer will display:
WARNING FFB /errno/
46 33003021 10/2013
Coding Rules
33003021 10/2013 47
Coding Rules
Extensible Pins
Naming Convention for Extensible Pins and the Algorithm to Generate Names
An identifier is a sequence of letters, numbers, and underlines beginning with a letter or an
underline (for example, name of a function block type, an instance, a variable, or a section). You
can use the letters from national character sets (for example, ö, ü, é, õ) except in project and DFB
names.
Underlines are significant in identifiers (for example, A_BCD and AB_CD) are interpreted as
different identifiers. Multiple leading underlines and consecutive underlines are invalid.
Identifiers cannot contain spaces and are not case-sensitive (for example, ABCD and abcd are
interpreted as the same identifier).
48 33003021 10/2013
Coding Rules
33003021 10/2013 49
Coding Rules
The libraries have to provide 2 Intel object files for each C coded function block. 1 object file is
generated with alignment 2 and a second object file is generated with alignment 4. These 2
different object files are necessary to build Unity Pro applications with alignment 2 or 4 for the
simulator or real premium platform. Depending on the alignment setting, Unity Pro links the
application with the related object file from the libset.
For an alignment issue, use the below mentioned pragma inside the FFB/DDT as follows:
#if defined(__arm__)
#pragma pack()
# else
#pragma pack()
# endif
The memory layout of a DDT changes from alignment 2 to 4, when a DDT element with a size of
at least 4 bytes (for example, DWORD, REAL) is mapped on an address that is unaligned for
alignment 4.
The table shows the offset alignment 2 and 4 for the various elements:
50 33003021 10/2013
EFB Toolkit for Unity Pro
Programming Examples
33003021 10/2013
Chapter 4
Programming Examples
Programming Examples
Summary
This chapter provides programming examples of elementary function (EFs), elementary function
blocks (EFBs) and derived data types (DDTs).
33003021 10/2013 51
Programming Examples
EF/EFB Example
General
This example will show how to generate a standardized header and source frame for the user
defined function blocks (EF or EFB).
EF and EFB
The representation of EFs and EFBs for the Unity Pro user is the same. The user of the EFB Toolkit
can select to create an EF or EFB. The difference between EFs and EFBs is the possibility for the
developer to use internal states of variables within EFBs.
For the software developer the EF consists of inputs and outputs. For creating EFBs the developer
can use public/private variables and inputs/outputs additionally to the usual input and output pins,
e. g. for storing internal states of the function block (see also Introduction, page 11).
Each EFB has instance data.
First Steps
This table describes the steps to create an EF.
52 33003021 10/2013
Programming Examples
EF Header Example
The following program code shows the header frame which will be generated by the EFB Toolkit.
// SDKC_HEADER_BEGIN Do not edit. Any modification would be lost
// Filename : C:\Programme\Schneider Electric\
Unity EFB Toolkit\SDKC\FFB
// Dev\example_efb\code\CIRCLE.h
// PROCEDURE CIRCLE
// Version 1.0
// Author Auto generated EF/EFB
/*
This is the comment of the demonstration EFThis is the
descriptive form of the demonstration EF
*/
#include "SystemLib.h"
// Additional header :
// None
// +----------------------+
// | CIRCLE |
// +----------------------+
// | |
// --+- R AREA -+--
// | |
// | CIRCUM -+--
// | |
// +----------------------+
//
IECBool fb_call_model CIRCLE(
const IECReal R, // This is the input pin
IEC_PARAM_RTE_OFFSET AREA, // Circle area
IEC_PARAM_RTE_OFFSET CIRCUM // Circle circumference
);
SDKC_HEADER_END
// TODO : Write here additionnal declarations.
33003021 10/2013 53
Programming Examples
EF Source Example
The following program code shows the source frame which will be generated by the EFB Toolkit.
// SDKC_HEADER_BEGIN Do not edit. Any modification would be lost
// Filename: C:\Programme\Schneider Electric\ Unity EFB Toolkit\SDKC\
// FFBDev\example_efb\code\CIRCLE.c
// PROCEDURE: CIRCLE
// Version: 1.0
// Author: Auto generated EF/EFB
/*
This is the comment of the demonstration EF
This is the descriptive form of the demonstration EF
*/
#include "CIRCLE.h"
// SDKC_HEADER_END
// TODO : Write here additionnal declarations.
// SDKC_PROTOTYPE_BEGIN Do not edit.
Any modification would be lost
IECBool fb_call_model CIRCLE(
const IECReal R, // This is the input pin
IEC_PARAM_RTE_OFFSET AREA, // Circle area
IEC_PARAM_RTE_OFFSET CIRCUM // Circle circumference
)
//}} SDKC_PROTOTYPE_END
{
// TODO : Write here variables declarations.
// TODO : Write here the code for your function block.
return TRUE; // ENO value
}
54 33003021 10/2013
Programming Examples
EF Program Code
General
The following provides information about the integration of the user defined program code for the
new EF.
Circle Example
The circle example calculates the circumference and area of a circle. The function block gets the
information of the radius via an input pin.
33003021 10/2013 55
Programming Examples
// SDKC_PROTOTYPE_END
{
// TODO : Write here variables declarations.
IECReal *pArea, *pCircum, pi, c2;
// TODO : Write here the code for your function block.
pArea = s_log_to_phy( AREA );
pCircum = s_log_to_phy( CIRCUM );
pi = *((IECReal *)s_Const_Instance(cllbk_PI));
c2 = *((IECReal *)s_Const_Instance(cllbk_2_0));
// Area calculation
*pArea = (IECReal)( pi * R * R );
// Circumference calculation
*pCircum= c2 * pi * R;
return TRUE ; // ENO value
}
56 33003021 10/2013
Programming Examples
33003021 10/2013 57
Programming Examples
General
The following text provides information about the code header file for a new EFB.
The difference between an EF and an EFB is an EFB’s ability to intercept two different events. You
can use the LanguageEntryPoint event and the SystemEntryPoint event.
The EF deploys just the LanguageEntryPoint event, and it is not explicitly listed in the EF
header file.
LanguageEntryPoint
The LanguageEntryPoint is activated by the PLC when the program is using the EFB within a
section.
SystemEntryPoint
The SystemEntryPoint is activated by system events in the PLC, independent of the user
program. The SystemEntryPoint is not known by the application; it is always present, even if
the functions are empty.
The following table shows the possible system events. The events are defined in Systemlib.h
Event Indication
pu_INIT_S0 Called at the init of an application, at the end
of a download and at a cold start.
System bit %S0 = 1
pu_INIT_CONF Called at the beginning of a cold start when a
valid application is detected.
pu_INIT_RECONF Called at the beginning of a download.
pu_INIT_CLEAR Used for EFBs having private data. It it used
to tell the EFB to clear its data area without
destroying the private data.
pu_WARM Called at the beginning of a warm restart.
pu_RESTART Called at the end of a warm start.
NOTE: Avoid using the SystemEntryPoint in the EFB Toolkit. In case of a serious problem,
contact Schneider Electric support.
SINCOS Example
The SINCOS example demonstrates the use of sine and cosine floating point functions. It
calculates the sin(a) * sin(a) + cos(a) * cos(a) equation and generates an error when
the result is not 1.
58 33003021 10/2013
Programming Examples
33003021 10/2013 59
Programming Examples
60 33003021 10/2013
Programming Examples
The following code shows the definition of the input and output parameters and the internal and
public variables. Public variables can be used and modified during the runtime. They keep the
information stored independent of the cycle or state of the PLC. Internal variables cannot be used
by the PLC program.
#pragma pack(8)
typedef struct {
// Public variables...
// Internal variables...
// Function parameters...
IECReal ALPHA; // Radian value
IECReal OUTP; // Function result
} SINCOS_INSTANCE_T ;
#pragma pack()
#ifdef EFFBDBG
#undef LanguageEntryPoint
#undef SystemEntryPoint
#define LanguageEntryPoint LanguageEntryPoint_SINCOS
#define SystemEntryPoint SystemEntryPoint_SINCOS
#endif
The following code shows the description of the LanguageEntryPoint. The LanguageEn-
tryPoint is automatically used by the PLC program to start the function of the EFB.
IECBool fb_call_model LanguageEntryPoint(
PTR_LOG SINCOS_instance// Logical address of a SINCOS_INSTANCE_T
) ;
The following code shows the description of the SystemEntryPoint. The SystemEntryPoint
is activated by system events. See also SystemEntryPoint, page 58.
extern IECByte fb_call_model SystemEntryPoint(
IECUInt type,
PTR_LOG SINCOS_instance
) ;
//}} SDKC_HEADER_END
// TODO : Write here additional declarations.
33003021 10/2013 61
Programming Examples
General
The following text provides information about the integration of user-defined program code into a
new EFB.
62 33003021 10/2013
Programming Examples
Instance Data
The instance data are defined within the header file. They consist of the input and output pins as
well as the internal and external variables.
You may use the two functions LanguageEntryPoint and SystemEntryPoint to work with
instance data.
The following code shows an extract of the instantiation of the data:
IECBool fb_call_model LanguageEntryPoint(
PTR_LOG SINCOS_instance // Logical address of a
SINCOS_INSTANCE_T
)
extern IECByte fb_call_model SystemEntryPoint(
IECUInt type,
PTR_LOG SINCOS_instance
)
You can react to a system event by using the parameter type IECUInt type. See SystemEn-
tryPoint, page 58.
33003021 10/2013 63
Programming Examples
DDT Example
Creating a DDT
You may create data structures or arrays. After they have been created, the DDTs are available to
use in EFs or EFBs.
First Steps
To create a DDT:
64 33003021 10/2013
Programming Examples
33003021 10/2013 65
Programming Examples
Nested DDTs
If you have nested DDTs, you have to take care of the correct order of nested DDTs. The correct
order is: n → n–1 → n–2 → ... → n2 → n1
66 33003021 10/2013
EFB Toolkit for Unity Pro
Debugging
33003021 10/2013
Chapter 5
Debugging
Debugging
Introduction
This chapter provides an overview of how Microsoft Visual C++ .NET can be used to debug an
EF/EFB.
33003021 10/2013 67
Debugging
Debug Preparation
General
After generating the installable form of the family with the EFB Toolkit and after installing it in the
Unity Pro Type Library, you can debug the function blocks using Microsoft Visual C++ .NET.
First Steps
To prepare an EF/EFB for debugging:
The MS Visual C++ project workspace is used to build a DLL for the Unity Pro PLC Simulator. This
DLL contains all EFs/EFBs in the family and some additional code to support function block
debugging with the Unity Pro PLC Simulator.
The project workspace consists of the following files, which reside in the \debug folder of the
family directory:
File Description
Effbdbg.dsw The workspace used to start the debug session.
Effbdbg.dsp The Visual C++ project file.
DbgMain.c Contains a function that is called from the standard effblib.dll of the Unity Pro PLC
Simulator after an application has been downloaded. This function does the routing
of function block calls from the Unity Pro application to your dynamic link-library
effbdbg.dll generated by this Visual C++ project. This library contains your
EF/EFB code.
PostBuildExec.bat The batch file executed at the end of the project build process. It copies the
generated DLL into the PLC Simulator directory.
When the program is ready to start the debug session, double-click the effbdbg.dsw project
workspace. MS Visual C++ .NET automatically converts the effbdbg.dsw file to
effbdbg.vcproj for later use in the .NET environment. Launch the project conversion inVisual
C++ by clicking Yes in the popup window.
The project settings contain a path to the Unity Pro PLC Simulator as the executable for the debug
session (sim.exe). The project settings also contain the program argument (/effbdbg), which
enables the EF/EFB debug feature in the PLC Simulator.
68 33003021 10/2013
Debugging
Settings
The following figure shows an example of the project settings in debugging mode:
The project settings also contain a post-build command that can be used to copy the generated
DLL effbdbg.dll to the Unity Pro PLC Simulator directory. The used batch file is automatically
created by the EFB Toolkit while executing the Debug all EF/EFBs menu command.
By default, the EFB Toolkit uses a registry entry to find the location of the PLC-Simulator and
creates the commands that are inserted into the PostBuildExec.Bat batch file. For this to work,
a version of Unity Pro must be installed on the PC.
NOTE: The batch file could also contain a copy command for the standard PLC Simulator
component effblib.dll in the case where the DLL must be replaced by a newer version
brought in with the EFB Toolkit (if you use Unity Pro Version 1.0x).
33003021 10/2013 69
Debugging
Post-Build
The following figure shows the post-build settings:
70 33003021 10/2013
Debugging
33003021 10/2013 71
Debugging
After completing the above preparations, start the build process. The following figure shows an
example of the output of the build process:
The output shows two warning lines (LNK4006) for the __fltused symbol references.
NOTE: These warnings can be ignored.
NOTE: If the copy process is successful, the build output window shows up to two result lines for
file copy operations, as shown above.
If the copy process is not successful, check the environment before continuing with the next steps.
Start Debugging
When the build process completes successfully, start the debug session by pressing the F5 key or
via a menu command in MS Visual C++. (For additional information, refer to the MS Visual C++
documentation.)
This action launches the PLC Simulator with the newly generated DLL containing the function
blocks to debug.
NOTE: A notification windows will appear to inform the programmer the Simulator does not
contain any symbol. The programmer must select the check box and press OK. During the
debugging session the programmer will not be able to debug the simulator code, but the EF/EFB
code can be debugged without limitations.
Optionally, the programmer may set a breakpoint in function block code by selecting a source code
line and pressing the F9 key or by using the context menu accessed by right-clicking the mouse.
72 33003021 10/2013
Debugging
33003021 10/2013 73
Debugging
Summary
74 33003021 10/2013
Debugging
Best Practices
Best Practice
During a debug session the DLL program code is executed and not the function block code inside
the Unity Pro application. This knowledge can be used to continue the development completely
within an MS Visual C++ programming environment. The following section explains how to
proceed:
z Create a framework of the family that includes all DDTs and the complete function block
template definition. At this time, you do not need to insert statements in the *.c files of the
function blocks created by the EFB Toolkit.
z Build the empty function block family framework in the EFB Toolkit and install it in the Unity Pro
Type Library.
z Start Unity Pro and create an application that uses the next function block to be debugged.
z Create the debugging environment in the EFB Toolkit with the Debug all EF/EFBs menu
command.
z Start the workspace file effbdbg.dsw in the \debug folder of the family directory.
z Complete the project settings as described in this document (see Debug Preparation, page 68).
z Build the debugging dynamic library (effbdbg.dll) containing the empty function blocks.
z Start the debugging session in Visual C++ (F5 key).
z Connect Unity Pro to the running PLC Simulator and download the Unity Pro application.
z Stop the debug session and start the function block code implementation inside Visual C++ if
the steps above are working properly.
NOTE: Do not change source sections created from the EFB Toolkit with a comment text such as
// DO NOT EDIT .
z You do not need to leave Visual C++ until the requirements have changed a function block
template or DDT. If this happens, you must go back to the beginning of the list. Do not forget to
install the modifications in Unity Pro and to adapt it to the Unity Pro application changes.
z If the function block code works well, go back to the EFB Toolkit, rebuild the family and install it
again in Unity Pro. Now the Unity Pro Type Library contains the implemented and tested code.
z If Visual C++ and the EFB Toolkit are open at the same time, you should be able to switch from
one application to the other. The two tools detect the modifications and reload the affected files.
33003021 10/2013 75
Debugging
Recommendations
Recommendations
1. When you are debugging a function block with the Visual C++ debugger, the Unity Pro
application debugging features are not available. Under an MS Windows operating system, only
one debugger can be attached to a process at a time.
2. The connection from Unity Pro to the PLC Simulator interrupts when a breakpoint is reached.
You may reconnect Unity Pro when the debugging session is not on a breakpoint.
3. Do not modify project and workspace files used for function block debugging, especially the
project extension with additional function blocks.
CAUTION
FILE MODIFICATION HAZARD
Do not modify files outside the EFB Toolkit. Files externally modified may not be read correctly
by the EFB Toolkit.
Failure to follow these instructions can result in injury or equipment damage.
76 33003021 10/2013
EFB Toolkit for Unity Pro
System Services
33003021 10/2013
Chapter 6
System Services
System Services
Summary
This chapter provides an overview of the system services in the Unity PLC OS.
33003021 10/2013 77
System Services
Section 6.1
Overview
Overview
General
The following tables contains all available system services of the EFB Toolkit and a short
description.
Objects Access
78 33003021 10/2013
System Services
Diagnostics
Signature
RUNTIME
33003021 10/2013 79
System Services
Float
Microsoft intrinsic
80 33003021 10/2013
System Services
Operators
Function
long +, -, *, /
long %, <<, >>
long <, >, <=, >=, ==, !=
unsigned long +, -, *, /
unsigned long %, <<, >>
unsigned long <, >, <=, >=, ==, !=
float +, -, /, *
float <, >, <=, >=, ==, !=
double +, -, /, * (32-bit only)
double <, >, <=, >=, ==, != (32-bit only)
- (float change sign operator)
- (double change sign operator) (32-bit only)
cast float to (long)
cast float to (unsigned long)
cast float to (short)
cast float to (unsigned short)
cast to (float)
cast to (double) (32-bit only)
cast double to (float) (32-bit only)
cast float to (double) (32-bit only)
33003021 10/2013 81
System Services
Section 6.2
Description
Description
Summary
The following section describes the system services of the EFB Toolkit. It describes the input and
output parameters and presents program examples.
82 33003021 10/2013
System Services
Topic Page
s_set_ffb_error 125
s_set_ffb_error_addi 127
s_diag_RegisterExtError 129
s_diag_DeregisterError 131
s_of_passw_check 133
s_of_passw_test 134
s_demask_it 135
s_GetUSecs 136
s_mask_it 137
s_proc_indic 138
s_proc_type 140
33003021 10/2013 83
System Services
s_AliGetProgStat
Description
The s_AliGetProgStat system service writes program-specific state information into the
parameter structure.
s_AliGetProgStat(ProcessState)
Availability
The following table shows the availability of the system service on different PLCs:
Data Types
The following program code shows the data type or structure.
typedef struct { IECEBool coldInit; // TRUE during first cycle
// after initialization
// of application
// (download or init).
IECEBool warmInit; // TRUE during first cycle
// in run cycle or after
// power on.
//
// Note:
// During a cold start cycle
// both are TRUE
//
IECEBool progError; // TRUE when unconfirmed
// errors present in system
// error buffer
IECEBool clk1; // 0.3125 Hz system clock signal
IECEBool clk2; // 0.625 Hz system clock signal
84 33003021 10/2013
System Services
CAUTION
UNEXPECTED APPLICATION BEHAVIOR - CHANGE IN STARTTIME
The behavior of the ’StartTime’ timer changed from Concept to Unity. In Concept, the timer does
not count, when the PLC is in STOP. In Unity, the timer continues to count.
Check the application for correct operation before use.
Failure to follow these instructions can result in injury or equipment damage.
Input Parameter
The following table describes the input parameters.
Parameter Description
ProcessState Address of the structure to get the answer.
Return Values
None
Example
// Example: s_AliGetProgStat
// Start dimension
PROG_STATE ProcessState
// End dimension
s_AliGetProgStat(&ProcessState);
33003021 10/2013 85
System Services
s_log_to_phy
Description
The s_log_to_phy system service converts a logical address into a physical address.
ptr = s_log_to_phy(logp)
Availability
The following table shows the availability of the system service on different PLCs:
Data Types
The following program code shows the data type or structure.
// Parameter given using Relocation Table Entry (RTE)
typedef unsigned short int IEC_PARAM_RTE;
// The offset size in target dependent
typedef unsigned int IEC_PARAM_OFFSET;
typedef struct tag_IEC_RTE_OFFSET {
IEC_PARAM_RTE block;
IEC_PARAM_OFFSET offset;
} IEC_RTE_OFFSET;
Input Parameters
The following table describes the input parameters.
Parameter Description
logp Block number and offset to convert.
Return Values
The following table describes the output parameters.
Parameter Description
ptr Physical pointer to a block.
86 33003021 10/2013
System Services
Example
// Example: s_log_to_phy
// Start dimension
IEC_RTE_OFFSET logp
void *ptr;
// End dimension
ptr = s_log_to_phy(logp);
33003021 10/2013 87
System Services
s_obj_to_log
Description
The s_obj_to_log system service gets the logical address of an application object
(%S,%SW,%M,%MW,...)
value = s_obj_to_log (object_type, PtrIecRte)
Availability
The following table shows the availability of the system service on different PLCs:
Data Types
The following program code shows the data type or structure.
// Parameter given using Relocation Table Entry (RTE)
typedef unsigned short int IEC_PARAM_RTE;
// The offset size in target dependent
typedef unsigned int IEC_PARAM_OFFSET;
typedef struct tag_IEC_RTE_OFFSET {
IEC_PARAM_RTE block;
IEC_PARAM_OFFSET offset;
} IEC_RTE_OFFSET;
88 33003021 10/2013
System Services
Input Parameters
The following table describes the input parameters:
Parameter Description
object_type Type of application object
z QUANTUM and PREMIUM
SYSTEM_WORD_ID (0) : %SW
INTERNAL_BIT_ID (1) : %M
INTERNAL_WORD_ID (2) : %MW
COMMON_WORD_ID (5) : %NW
z QUANTUM only
INPUT_FLATBIT_ID (6) : %Iflat
INPUT_FLATWORD_ID (7) : %IWflat
PAGE0_ID (8) : page 0
SYSTABLE_ID (9) : system table
PtrIecRte Pointer on logical address (OUTPUT PARAMETER)
Return Values
The following table describes the output values:
Values Description
value 0 : STATUS_OK, read has been done
-1 : ERROR, invalid parameter
Example
// Example: s_obj_to_log
// Start dimension
IEC_RTE_OFFSET IecRte
unsigned short object_type;
unsigned short value;
// End dimension
value = s_obj_to_log(object_type, &IecRte);
33003021 10/2013 89
System Services
s_obj_nbr
Description
The s_obj_nbr system service gets the number of located objects of type
(%SW,%M,%MW,%NW,...)
value = s_obj_nbr (object_type)
Availability
The following table shows the availability of the system service on different PLCs:
Input Parameters
The following table describes the input parameters:
Parameter Description
object_type SYSTEM_WORD_ID (0) : %SW
INTERNAL_BIT_ID (1) : %M
INTERNAL_WORD_ID (2) : %MW
COMMON_WORD_ID (5) : %NW
INPUT_FLATBIT_ID (6) : %Iflat
INPUT_FLATWORD_ID (7) : %IWflat
Return Values
The following table describes the output parameters:
Values Description
value Value of the word.
0 : In case of no object of this type
Example
// Example: s_obj_nbr
unsigned short object_type;
unsigned short value;
// End dimension
value = s_obj_nbr(object_type);
90 33003021 10/2013
System Services
s_rd_16bits
Description
The s_rd_16bits system service concatenates the value bit of 16 IECBool type objects in a 16-
bit value. The value bit of an IECBool is bit 0.
value = s_rd_16bits(address)
Availability
The following table shows the availability of the system service on different PLCs:
Data Types
The following program code shows the data type or structure.
// Parameter given using Relocation Table Entry (RTE)
typedef unsigned short int IEC_PARAM_RTE;
// The offset size in target dependent
typedef unsigned int IEC_PARAM_OFFSET;
typedef struct tag_IEC_RTE_OFFSET {
IEC_PARAM_RTE block;
IEC_PARAM_OFFSET offset;
} IEC_RTE_OFFSET;
Input Parameters
The following table describes the input parameters:
Parameter Description
address Logical address of the first bit to be read.
33003021 10/2013 91
System Services
Return Values
The following table describes the output values:
Value Description
value Value to the referenced bit string.
Example
// Example: s_rd_16bits
// Start dimension
unsigned short value;
IEC_RTE_OFFSET address;
// End dimension
value = s_rd_16bits(address);
92 33003021 10/2013
System Services
s_rd_1bit
Description
The s_rd_1bit system service gets the value bit of a single IECBool type object. The value bit of
an IECBool is bit 0.
value = s_rd_1bit(address)
Availability
The following table shows the availability of the system service on different PLCs:
Data Types
The following program code shows the data type or structure.
// Parameter given using Relocation Table Entry (RTE)
typedef unsigned short int IEC_PARAM_RTE;
// The offset size in target dependent
typedef unsigned int IEC_PARAM_OFFSET;
typedef struct tag_IEC_RTE_OFFSET {
IEC_PARAM_RTE block;
IEC_PARAM_OFFSET offset;
} IEC_RTE_OFFSET;
Input Parameters
The following table describes the input parameters:
Parameter Description
address Logical address of the first bit to be read.
33003021 10/2013 93
System Services
Return Values
The following table describes the output values:
Value Description
value Value to the referenced bit.
Example
// Example: s_rd_1bit
// Start dimension
unsigned short value;
IEC_RTE_OFFSET address;
// End dimension
value = s_rd_1bit(address);
94 33003021 10/2013
System Services
s_rd_bit_attrib
Description
The s_rd_bit_attrib system service reads an entire IECBool type object and all its attributes.
For state RAM access on Quantum PLCs, only bits 0, 1 and 2 are read (value, history and force
on/force off attributes, respectively).
value = s_rd_bit_attrib(address, resultptr)
Availability
The following table shows the availability of the system service on different PLCs:
Data Types
The following program code shows the data type or structure.
// Parameter given using Relocation Table Entry (RTE)
typedef unsigned short int IEC_PARAM_RTE;
// The offset size in target dependent
typedef unsigned int IEC_PARAM_OFFSET;
typedef struct tag_IEC_RTE_OFFSET {
IEC_PARAM_RTE block;
IEC_PARAM_OFFSET offset;
} IEC_RTE_OFFSET;
Input Parameters
The following table describes the input parameters:
Parameter Description
address Address of the bit to read.
resultptr Pointer that will contain the result (OUTPUT PARAMETER).
The function returns the IECBool with IOIM format:
bit 0: Value
bit 1: History
bit 2: Forcing
33003021 10/2013 95
System Services
Return Values
The following table describes the output values:
Value Description
value 0: No error.
<0: In case of an error.
Example
// Example: s_rd_bit_attrib
// Start dimension
IEC_RTE_OFFSET address;
unsigned char result;
int value;
// End dimension
value = s_rd_bit_attrib (address, &result);
96 33003021 10/2013
System Services
s_rd_internalwords
Description
The s_rd_internalwords system service reads n consecutive %MWi bits.
value = s_rd_internalwords(number, length, BuffAddr)
Availability
The following table shows the availability of the system service on different PLCs:
Input Parameters
The following table describes the input parameters:
Parameter Description
number ID number of the first word to be read
length Number of words to be read
BuffAddr Pointer to the buffer that contains the word values
Return Values
The following table describes the output values:
Value Description
value 0: Work has been made.
< 0: Wrong parameters number or length.
33003021 10/2013 97
System Services
Example
// Example: s_rd_internalwords
// Start dimension
short value;
unsigned short number;
unsigned short length;
unsigned short Buffer;
// End dimension
value = s_rd_internalwords(number, length, &Buffer);
98 33003021 10/2013
System Services
s_rd_Nbits
Description
The s_rd_Nbits system service concatenates the value bit of n IECBool type objects in a 32-bit
value. The value bit of an IECBool is its 0 bit.
value = s_rd_Nbits(address, length, state)
Availability
The following table shows the availability of the system service on different PLCs:
Data Types
The following program code shows the data type or structure.
// Parameter given using Relocation Table Entry (RTE)
typedef unsigned short int IEC_PARAM_RTE;
// The offset size in target dependent
typedef unsigned int IEC_PARAM_OFFSET;
typedef struct tag_IEC_RTE_OFFSET {
IEC_PARAM_RTE block;
IEC_PARAM_OFFSET offset;
} IEC_RTE_OFFSET;
Input Parameters
The following table describes the input parameters:
Parameter Description
address Logical address of the first object.
length Number of objects to read (must be <= 32).
state Contains the state of the function. Negative value in case of an error
or 0 if its OK.
33003021 10/2013 99
System Services
Return Values
The following table describes the output values:
Value Description
value 0: In case of an error (invalid block number in logical address).
<> 0: The concatenation of the value bits.
Example
// Example: s_rd_Nbits
// Start dimension
unsigned long value;
IEC_RTE_OFFSET address;
unsigned short length;
short state;
// End dimension
value = s_rd_Nbits(address, length, &state);
s_rd_sysbit
Description
The s_rd_sysbit system service reads a system bit %Si identified by its number. The
consistency of the bit number is checked.
value = s_rd_sysbit(id, state)
Availability
The following table shows the availability of the system service on different PLCs:
Input Parameters
The following table describes the input parameters:
Parameter Description
id Number of the bit to be read.
state Pointer to the system status word.
Return Values
When the status is STATUS_OK, the bit value is entered in the least significant bit.
Bit numbers 1 .. 15 are set to zero.
A bit number outside these limits produces the status value OUT_OF_BOUNDS.
Example
// Example: s_rd_sysbit
// Start dimension
unsigned short value;
unsigned short far state;
// End dimension
value = s_rd_sysbit(4, &state);
s_rd_sysword
Description
The s_rd_sysword system service reads a system word %SWi identified by its number. The
consistency of the bit number is checked.
value = s_rd_sysword(sysword_range, state)
Availability
The following table shows the availability of the system service on different PLCs:
Input Parameters
The following table describes the input parameters:
Parameter Description
sysword_range Logical address of the word to be read.
state Pointer to the system status word.
Return Values
The following table describes the output parameters:
Parameter Description
value Value of the word.
0: In case of error or if there is no application loaded.
Example
// Example: s_rd_sysword
// Start dimension
unsigned short value;
unsigned short state;
// End dimension
value = s_rd_sysword(4, &state);
s_wr_16bits
Description
The s_wr_16bits system service writes the value of 16 consecutive bits of forcible memory.
Because the system does not perform any checks, the EF using this utility must ensure the validity
of the 16-bit address that has become a parameter.
s_wr_16bits(IEC_RTE_OFFSET address, value1)
Availability
The following table shows the availability of the system service on different PLCs:
Data Types
The following program code shows the data type or structure.
// Parameter given using Relocation Table Entry (RTE)
typedef unsigned short int IEC_PARAM_RTE;
// The offset size in target dependent
typedef unsigned int IEC_PARAM_OFFSET;
typedef struct tag_IEC_RTE_OFFSET {
IEC_PARAM_RTE block;
IEC_PARAM_OFFSET offset;
} IEC_RTE_OFFSET;
Input Parameters
The following table describes the input parameters:
Parameter Description
address Logical address of the first bit to be written.
value1 The value of the 16 bits, from bit 0 to 15.
Return Values
none
Example
// Example: s_wr_16bits
// Start dimension
unsigned short value1;
IEC_RTE_OFFSET AdresseBit;
// End dimension
s_wr_16bits(AdresseBit, value1);
s_wr_1bit
Description
The s_wr_1bit system service writes the value of a forcible bit. Because the system does not
perform any checks, the EF using this utility must ensure the validity of the address of the bit that
has become a parameter.
s_wr_1bit(IEC_RTE_OFFSET address, value1)
Availability
The following table shows the availability of the system service on different PLCs:
Data Types
The following program code shows the data type or structure.
// Parameter given using Relocation Table Entry (RTE)
typedef unsigned short int IEC_PARAM_RTE;
// The offset size in target dependent
typedef unsigned int IEC_PARAM_OFFSET;
typedef struct tag_IEC_RTE_OFFSET {
IEC_PARAM_RTE block;
IEC_PARAM_OFFSET offset;
} IEC_RTE_OFFSET;
Input Parameters
The following table describes the input parameters:
Parameter Description
address Address of the forcible bit to be written.
value1 Values to be written to a bit, either 0 or 1.
Return Values
none
Example
// Example: s_wr_1bit
// Start dimension
unsigned short value1;
IEC_RTE_OFFSET far AdresseBit;
// End dimension
s_wr_1bit(AdresseBit, value1);
s_wr_bits_attrib
Description
The s_wr_bits_attrib system service writes n consecutive IECBool type objects, where n <=
32. Several fields of the objects can be accessed depending on the type parameter. A type may be:
z DATA_WRITE (0)
Writes value bits (according to the forcing attribute, history is also updated).
z UNFORCE_ALL (8)
Resets forcing bits (bit 3).
z DEFAULT_WRITE (7)
Writes default bit (bit 7).
z RVALUE_WRITE (4)
Writes fallback bit (bit 4).
z RVALID_WRITE (6)
Writes fallback validation bit (bit 6).
value = s_wr_bits_attrib (address, length, value1, type)
Availability
The following table shows the availability of the system service on different PLCs:
Data Types
The following program code shows the data type or structure.
// Parameter given using Relocation Table Entry (RTE)
typedef unsigned short int IEC_PARAM_RTE;
// The offset size in target dependent
typedef unsigned int IEC_PARAM_OFFSET;
typedef struct tag_IEC_RTE_OFFSET {
IEC_PARAM_RTE block;
IEC_PARAM_OFFSET offset;
} IEC_RTE_OFFSET;
Input Parameters
The following table describes the input parameters:
Parameter Description
address Logical address of the first bit to be written.
length Number (n) of bits to be written (n <=32).
value1 The n bits values to be write, from 0 to n - 1 bit. Not used if type is
equal to UNFORCE_ALL.
type Attribute to write.
Return Values
The following table describes the output values:
Value Description
value 0 if OK, negative value in case of an error.
Example
// Example: s_wr_bits_attrib
// Start dimension
short value;
unsigned short length;
unsigned long value1;
unsigned short type;
IEC_RTE_OFFSET address;
// End dimension
value = s_wr_bits_attrib(address, length, value1, type);
s_wr_internalwords
Description
The s_wr_internalwords system service writes n consecutive %MWi words.
value = s_wr_internalwords(number, length, BuffAddr)
Availability
The following table shows the availability of the system service on different PLCs:
Input Parameters
The following table describes the input parameters:
Parameter Description
number Number of the first word to be written.
length Number of words to be written.
BuffAddr Far pointer to the buffer that contains the words values.
Return Values
The following table describes the output values:
Value Description
value 0: Work has been made.
< 0: Wrong number or length parameter.
Example
// Example: s_wr_internalwords
// Start dimension
short value;
unsigned short number;
unsigned short length;
unsigned short Buffer;
// End dimension
value = s_wr_internalwords(number, length, &Buffer);
s_wr_Nbits
Description
The s_wr_Nbits system service writes the value bit of n consecutive IECBool objects. The value
bit of an IECBool is its bit 0. This function updates the history bit (bit 1).
s_wr_Nbits(address, length, value1)
Availability
The following table shows the availability of the system service on different PLCs:
Data Types
The following program code shows the data type or structure.
// Parameter given using Relocation Table Entry (RTE)
typedef unsigned short int IEC_PARAM_RTE;
// The offset size in target dependent
typedef unsigned int IEC_PARAM_OFFSET;
typedef struct tag_IEC_RTE_OFFSET {
IEC_PARAM_RTE block;
IEC_PARAM_OFFSET offset;
} IEC_RTE_OFFSET;
Input Parameters
The following table describes the input parameters:
Parameter Description
address Logical address of the first object to be written.
length Number of objects to be written.
value1 Value of the n bits, from bit 0 to n - 1.
Return Values
none
Example
// Example: s_wr_Nbits
// Start dimension
IEC_RTE_OFFSET address;
unsigned short length;
unsigned long value1;
// End dimension
s_wr_Nbits(address, length, value1);
s_wr_sysbit
Description
The s_wr_sysbit system service writes a system bit identified by its number.
value = s_wr_sysbit(id, value1)
Availability
The following table shows the availability of the system service on different PLCs:
Input Parameters
The following table describes the input parameters.
Parameter Description
id Number of the bit to be written.
value1 Value of the bit, only bit 0 of the word is significant.
Return Values
The following table describes the output values.
Value Description
value z STATUS_OK: 0
Work has been made.
z <0
Wrong number (outside valid range)
Example
// Example: s_wr_sysbit
// Start dimension
short value;
unsigned short id;
unsigned short value1;
// End dimension
value = s_wr_sysbit (id, value1);
s_wr_sysword
Description
The s_wr_sysword system service writes a system word %SWi identified by its number.
value = s_wr_sysword(number, value1)
Availability
The following table shows the availability of the system service on different PLCs:
Input Parameters
The following table describes the input parameters:
Parameter Description
number Number of the word to be written
value1 Value of the word.
Return Values
The following table describes the output parameters:
Parameter Description
value STATUS_OK: Work has been made.
OUT_OF_BOUNDS: Wrong number.
Example
// Example: s_wr_sysword
// Start dimension
short value;
unsigned short number;
unsigned short value1;
// End dimension
value = s_wr_sysword(number, value1);
s_cnt_100ms
Description
The s_cnt_100ms system service is a system-time-base 100 ms counter. This internal counter
may be modified at any moment by a WarmStandBy IOB and EF to synchronize it with another
WarmStandBy PLC.
The counter is set to zero only on a cold start. The counter does not increment during power
breaks.
value = s_cnt_100ms()
Availability
The following table shows the availability of the system service on different PLCs:
Input Parameters
none
Return Values
The output value of the counter has the following characteristics:
Value Description
value Unsigned value, from 0 to 4 294 967 295
Example
// Example: s_cnt_100ms
// Start dimension
unsigned long value;
// End dimension
value = s_cnt_100ms();
s_cnt_10ms
Description
The s_cnt_10ms system service is a system-time-base 10 ms counter. This internal counter may
be modified at any moment by a WarmStandBy IOB and EF to synchronize it with another
WarmStandBy PLC.
The counter is set to zero only on a cold start. It does not be increment during power breaks.
value = s_cnt_10ms()
Availability
The following table shows the availability of the system service on different PLCs:
Input Parameters
none
Return Values
The output value of the counter has the following characteristics:
Value Description
value Unsigned value, from 0 to 4 294 967 295
Example
// Example: s_cnt_10ms
// Start dimension
unsigned long value;
// End dimension
value = s_cnt_10ms();
s_cnt_1ms
Description
The s_cnt_1ms system service is a system-time-base 1 ms counter. This internal counter may be
modified at any moment by a WarmStandBy IOB and EF to synchronize it with another
WarmStandBy PLC.
The counter is set to zero only on a cold start. It does not increment during power breaks.
value = s_cnt_1ms()
Availability
The following table shows the availability of the system service on different PLCs:
Input Parameters
none
Return Values
The output value of the counter has the following characteristics:
Value Description
value Unsigned value, from 0 to 65 535
Example
// Example: s_cnt_1ms
// Start dimension
unsigned short value;
// End dimension
value = s_cnt_1ms();
s_date_and_time
Description
The s_date_and_time system service enables access to the real-time clock. The information
(the date and current time for the PLC) is coded in BCD in nine bytes (or 18 digits), according to
the format below:
Type Range
Day of the week 01 .. 07
01: Monday
02: Tuesday
03: Wednesday
04: Thursday
05: Friday
06: Saturday
07: Sunday
Year 0000 .. 9999
Month 01 .. 12
Day 01 .. 31
Hour 00 .. 23
Minute 00 .. 59
Second 00 .. 59
Reserved 00
Availability
The following table shows the availability of the system service on different PLCs:
Data Types
The following code shows the data type or structure:
typedef struct tagIECDate
{
union
{
struct
{
IECByte Day;
IECByte Month;
IECUInt Year;
}DMY;
IECUDInt UDIntValue;
};
} IECDate;
Input Parameters
The following table describes the input parameters:
Parameter Description
date_ptr Pointer to the copying zone of the date and current time
(9 bytes).
Return Values
The following table describes the output values:
Value Description
value z STATUS_OK
the date and time fields are correctly indicated
z CLOCK_UNAVAILABLE
the fields cannot update correctly
z CLOCK_NOT_SUPPORTED
no a real-time clock present
Example
// Example: s_date_and_time
// Start dimension
unsigned short value;
DATE_TIME date;
// End dimension
value = s_date_and_time(&date);
s_syscnt_10ms
Description
The s_syscnt_10ms system service is a 10 ms system-time-base counter. It is an internal
counter that you cannot modify. It is set to zero only on a cold start. It does not increment during
power breaks.
value = s_syscnt_10ms()
Availability
The following table shows the availability of the system service on different PLCs:
Input Parameters
none
Return Values
The following table describes the output values:
Value Description
value Unsigned value, from 0 to 4 294 967 295
Example
// Example: s_syscnt_10ms
// Start dimension
unsigned long value;
// End dimension
value = s_syscnt_10ms();
s_current_task
Description
The s_current_task system service sends back the value of the current task.
value = s_current_task()
Availability
The following table shows the availability of the system service on different PLCs:
Input Parameters
none
Return Values
The following table describes the output values:
Value Description
value task number
z user tasks: event tasks
pu_TSK_PRIO0 : 0
pu_TSK_PRIO1 : 1
pu_TSK_PRIO2 : 2
z user tasks: standard tasks: Run/Stop
pu_TSK_FAST : 3
pu_TSK_MAST : 4
pu_TSK_AUX0 : 5
pu_TSK_AUX1 : 6
pu_TSK_AUX2 : 7
pu_TSK_AUX3 : 8
Example
// Example: s_current_task
// Start dimension
unsigned short value;
// End dimension
value = s_current_task();
s_set_ffb_error
Description
The s_s_set_ffb_error system service registers an FFB error without an additional error
parameter. This function simultaneously registers and deregisters an FFB error—i.e., it registers
the error in reg-dereg mode. This service is similar to s_set_ffb_error_addi, except that no
additional error parameter is passed to the function.
NOTE: If the ErrNum parameter contains one of the following values:
STRINGERROR, CARRY, OVERFLOW, INDEXOVF
then it writes the corresponding %S system bit.
value = s_set_ffb_error(sErrNum)
Availability
The following table shows the availability of the system service on different PLCs:
Input Parameters
The following table describes the input parameters:
Parameter Description
sErrNum Error number.
Return Values
The following table describes the output values:
Value Description
value unequal 0: operation successful, else error
err_DIAG_NO_BUFFER: no diagnostic buffer
err_DIAG_BUFFER_FULL: too many errors or no more free memory
err_OBJUSED: diagnostic buffer being use by another task
Example
// Example: s_set_ffb_error
// Start dimension
unsigned short value;
short sErrNum;
// End dimension
value = s_set_ffb_error(sErrNum);
s_set_ffb_error_addi
Description
The s_set_ffb_error_addi system service registers an FFB error together with an additional
error parameter. This function simultaneously registers and deregisters an FFB error—i.e., it
registers the error in reg-dereg mode. An additional descriptive parameter may optionally be
passed.
NOTE: If the ErrNum parameter contains one of the following values:
STRINGERROR, CARRY, OVERFLOW, INDEXOVF
then it writes the corresponding %S system bit.
Availability
The following table shows the availability of the system service on different PLCs:
Input Parameters
The following table describes the input parameters:
Parameter Description
sErrNum Error number.
sParam Additional error parameter.
Return Values
The following table describes the output values:
Value Description
value unequal 0: operation was successful, else error
err_DIAG_NO_BUFFER: no diagnostic buffer
err_DIAG_BUFFER_FULL: too many errors or no more free memory
err_OBJUSED: diagnostic buffer being use by other task
Example
// Example: s_set_ffb_error
// Start dimension
unsigned short value;
short sErrNum;
unsigned short sParam;
// End dimension
value = s_set_ffb_error(sErrNum, sParam);
s_diag_RegisterExtError
Description
The s_diag_RegisterExtError system service registers a diagnostic system extension error.
The function allows the caller to preset the whole error information, which normally is provided by
the diagnostic subsystem and lets the diagnostic subsystem store the information transparently,
when registering the error. This function returns the error registration id (ErrorId).
Canceling of the error is done with the function diag_DeregisterError.
value = s_diag_RegisterExtError(OpControl, ECode, CmntAdr, EtxtAdr,
DataLen, DataAdr, pErrorId)
Availability
The following table shows the availability of the system service on different PLCs:
Input Parameters
The following table describes the input parameters:
Parameter Description
OpControl Type: unsigned char
1: with (ACK required)
0: without operator control (auto ACK)
ECode Type: unsigned long
error code number
CmntAdr Type: IEC_RTE_OFFSET
comment address
EtxtAdr Type: IEC_RTE_OFFSET
error text address
DataLen Type: unsigned short
length of the additional information
Parameter Description
DataAdr Type: IEC_RTE_OFFSET
additional error information address
pErrorId Type: unsigned short FAR *
error registration id -returned
Return Values
The following table describes the output values:
Value Description
value unequal 0: operation successful, else error
err_DIAG_NO_BUFFER: no diag buffer
err_DIAG_BUFFER_FULL: too much errors or no more free memory
err_OBJUSED: diagnostic buffer in use by other task
err_OUTOFBOUNDS: the length of the additional information raises
the limitation
Example
// Example: s_diag_RegisterExtError
// Start dimension
unsigned short value, DataLen;
unsigned char OpControl;
unsigned long ECode;
unsigned long ECode;
IEC_RTE_OFFSET CmntAdr, EtxtAdr, DataAdr;
unsigned short FAR * pErrorId;
// End dimension
value = s_diag_RegisterExtError(OpControl, ECode, CmntAdr,
EtxtAdr, DataLen, DataAdr, pErrorId);
s_diag_DeregisterError
Description
The s_diag_DeregisterError system service unregisters a diagnostic system extension
error.
When a registered error disappears, the producer (FB, SFC or system) can call this function to
unregister the error.
value = s_diag_DeregisterError(usErrorId)
Availability
The following table shows the availability of the system service on different PLCs:
Input Parameters
The following table describes the input parameters:
Parameter Description
usErrorId Type: unsigned short
Error identifier which comes from registration.
Return Values
The following table describes the output values:
Value Description
value unequal 0: operation successful, else error
err_DIAG_NO_BUFFER: no diag buffer
err_DIAG_WRONG_ERROR_ID: wrong error identifier
err_OBJUSED: diagnostic buffer in use by other task
Example
// Example: s_diag_DeregisterError
// Start dimension
unsigned short value, usErrorId;
// End dimension
value = s_diag_DeregisterError(usErrorId);
s_of_passw_check
Description
The s_of_passw_check system service checks the signature and returns a STATUS_OK if it is
correct. If the signature is not correct, the PLC goes to halt state with value 0002 in %SW125.
value = s_of_passw_check(sign_ptr)
Availability
The following table shows the availability of the system service on different PLCs:
Input Parameters
The following table describes the input parameter:
Parameter Description
sign_ptr Pointer to signature code array
Return Values
The following table describes the output value:
Value Description
value STATUS_OK: operation successful
Example
// Example: s_of_passw_check
// Start dimension
unsigned short value;
unsigned char sign(16);
// End dimension
value = s_of_passw_check(&sign);
s_of_passw_test
Description
The s_of_passw_test system service tests the password. This routine checks the signature and
returns a STATUS_OK if the signature is correct. If the signature is not correct, it returns an error.
value = s_of_passw_test(sign_ptr)
Availability
The following table shows the availability of the system service on different PLCs:
Input Parameters
The following table describes the input parameter:
Parameter Description
sign_ptr Pointer to signature code array
Return Values
The following table describes the output value:
Value Description
value STATUS_OK: operation successful
Example
// Example: s_of_passw_test
// Start dimension
unsigned short value;
unsigned char sign;
// End dimension
value = s_of_passw_test(&sign);
s_demask_it
Description
The s_demask_it system service enables you to unprotect a critical section from interrupts.
void s_demask_it(unsigned short value1)
Availability
The following table shows the availability of the system service on different PLCs:
Input Parameters
The following table describes the input parameter:
Parameter Description
value1 Value of the CPU flag register to restore
(gotten from s_mask_it).
Return Values
none
Example
// Example: s_demask_it
// Start dimension
unsigned short value1;
// End dimension
s_demask_it(value1);
s_GetUSecs
Description
The s_GetUSecs system service gets the current value of a microsecond counter. The overflow
from the counter (in the range 0xFFFFFFFF to 0) must be managed by the caller in case of gap
time calculations.
unsigned int s_GetUSecs(void)
Availability
The following table shows the availability of the system service on different PLCs:
Input Parameters
none
Return Values
The following table describes the output value:
Value Description
value Current value of the microsecond counter
Example
// Example: s_GetUSecs
// Start dimension
unsigned int value;
// End dimension
value = s_GetUSecs();
s_mask_it
Description
The s_mask_it system service enables you to protect a critical section from interrupts.
unsigned short s_mask_it(void)
Availability
The following table shows the availability of the system service on different PLCs:
Input Parameters
none
Return Values
The following table describes the output value:
Value Description
value Content of the CPU flag register
Example
// Example: s_mask_it
// Start dimension
unsigned short value;
// End dimension
value = s_mask_it();
s_proc_indic
Description
The s_proc_indic system service returns the current state of an indicator.
s_proc_indic(StrInd)
Availability
The following table shows the availability of the system service on different PLCs:
Data Types
The following code shows the data type or structure:
typedef struct {
unsigned short bRun : 1; // 1 if run
unsigned short bAppliExec : 1; // 1 if i.c. and
// configuration
// application is
// okay
unsigned short bCartMemDetect : 1; // 1 if a memory
// card is
// detected
unsigned short bReservation : 1; // 1 if reservation
// is in progress
unsigned short bBrkptSet : 1; // 1 if break
// point is SET
unsigned short bAppliFailure : 1; // 1 if application
// is HALT
unsigned short bPartialRun : 1; // 1 if partially
// is RUN
unsigned short bCartFlashErase : 1; // 1 if memory
// card type EPROM
// delete in
// progress
unsigned short bUserMemProtect : 1; // 1 if application
// in memory
// protected write
unsigned short bPhaseInit : 1; // Allow RUN with
// internal
// restore
unsigned short bRestoreBck : 1; // Internal Backup
// restore
unsigned short bAppliInit : 1; // Application
// initialized,
// %S %SW
// available
unsigned short cUnused : 4; // Alignment
} SGenInd ;
Input Parameters
The following table describes the input parameter:
Parameter Description
StrInd Address of the buffer that will be filled.
Return Values
none
Example
// Example: s_proc_indic
// Start dimension
unsigned short value;
SGenInd StrInd;
// End dimension
s_proc_indic(&StrInd);
s_proc_type
Description
The s_proc_type system service returns the processor’s identification.
s_proc_type(DeviceId)
Availability
The following table shows the availability of the system service on different PLCs:
Data Types
The following code shows the data type or structure:
typedef struct {
unsigned short ProductRange;
unsigned short PlcIdentification;
unsigned short PlcModel;
unsigned short ReservedForFuture;
unsigned short ComVersion;
unsigned short NumPatch;
} DEVICEID;
Input Parameters
The following table describes the input parameter:
Parameter Description
DeviceId Address of a buffer that will contain
the identification of the device.
Return Values
none
Example
// Example: s_proc_type
// Start dimension
DEVICEID DeviceId;
// End dimension
s_proc_type(&DeviceId);
33003021 10/2013
Appendices
Appendix A
PL7/Concept EF/EFB Migration
Overview
This chapter provides an overview of PL7 and Concept EF/EFB migration.
Section A.1
PL7 and Concept EF/EFB Migration
PL7 EF Migration
Introduction
This document answers the question: How can I transfer my EFs to Unity Pro? It does not describe
any special tools that could be used; it simply describes the process generically and gives an
example.
The following discussion points out how a practical conversion of Concept EF/EFBs to Unity Pro
can be done. The goal of this document is to provide some guidelines for EF/EFB migration from
Concept to Unity Pro. Changes are considered from the Unity Pro point of view. For a detailed
discussion of procedures, refer to the toolkit documentation.
Since the functionality of the EF/EFB should be the same in Unity Pro as in Concept, make the
needed changes in the calling interface of the function block whenever possible. Changes to the
function code itself should be kept to an absolute minimum.
Preparation
PL7 EF migration is primarily a copy-and-paste process. Before you begin to migrate C-coded
functions, make sure that a complete programming environment is installed on your system.
You will need the old as well as new programming tools:
z PL7 SDKC
z Unity Pro EFB Toolkit
For example if you want to migrate functions created with the PL7 SDKC tool, you need at least
the source files (headers and C-files) from your old function blocks.
Section A.2
PL7 EF Migration Procedure
Summary
The following section describes the PL7 EF migration procedure.
WARNING
UNEXPECTED EQUIPMENT OPERATION
Migrated applications may not operate exactly as the original. All applicable tests for safe
operation must be performed before release of the migrated code.
Failure to follow these instructions can result in death, serious injury, or equipment
damage.
Retrieval
Step Action
1 Start the PL7 EF Toolkit, and open a family class.
2 Export an EF class with the Export dialog.
Result: A message appears indicating the location of the newly created file.
The export file is a ZIP archive that contains, among other things, all the function
block sources needed for EF migration.
3 Open the archive file with a standard ZIP tool such as WinZip and extract the
contents.
Result: In the archive file you will see files for each EF of the class with the name
CLASS01.H and a pair of header and C-File named as MAIN01xx.H(.C). For
example:
Migration Procedure
Sample Procedure
Step Action
1 Start the Unity EFB Toolkit.
2 Create a new family (File → New family...) using the same family name as in PL7.
3 Complete the family description with the comment line in the Target Library in
Unity. The Library Management... button leads you to a dialog where you can
define the name of the Target Library in Unity that will be the repository for your
EFs.
Step Action
4 Create the family functions using Current family → Create EF/EFB.
Attention: The Kind of the migrated EF can change from FUNCTION to
PROCEDURE if an EF uses more than one output pin. Refer to EFB Toolkit
documentation for details.
Step Action
5 Start the translation of the EF interface from PL7 to Unity Pro.
Note: Some data types have been changed from PL7 to Unity Pro. You can find a
reference table for this in chapter Data Types Comparison: PL7/Concept and Unity
Pro, page 181.
PL7 EF interface:
6 After the interface definition is complete, select Current Object → Analyze and
Generate code.
Result: An empty EF frame appears that must be filled with the code from the old
EF. See an old PL7 EF Code, page 152 and the new EF code adapted for Unity Pro
(see page 153).
7 Copy the PL7 source data and paste it into the new Unity Pro source created by the
Unity Pro EFB Toolkit.
Note: This example also shows the different ways in which floating point constants
and operations are used in PL7 and Unity Pro function blocks. Unity Pro lets you
replace the PL7 macros such as MUL with a normal operator.
PL7 EF Code
Sample Code
//PL7SDK_BEGIN_FUNCTION_NAME
// do not modify the generated function prototype please
// The main EF Function must be the first in this file
#include <Cstsyst.h>
#include <Fctsyst.h>
#include <C:\ASAWTEMP\SDKC\CLASSE01.H >
#include <C:\ASAWTEMP\SDKC\MAIN0101.H >
void far pascal CIRCLE(
unsigned long RAD, //
adrSCAL AREA, //
adrSCAL CIRC //
)
//PL7SDK_END_FUNCTION_NAME
{
FLOAT radius, pi, c2;
unsigned long far *pArea, far *pCirc ;
/// processing
pi = 0x40490FF9UL; // corresponds with the float value PI=3.1415999
c2 = 0x40000000UL; // corresponds with the float value 2.0
Sample Code
//{{ SDKC_HEADER_BEGIN Do not edit. Any modification would be lost
// Filename : C:\Program Files\Schneider Electric\
EFBToolkit\ FFBDev\Sample\code\CIRCLE.c
//PROCEDURE : CIRCLE
//Version : 1.0
//Author : Auto generated EF/EFB
/*
PL7 migration example
This EF calculates the area and the circumference
to a given radius of a circle. */
#include “CIRCLE.h”
//}} SDKC_HEADER_END
pi = *((IECReal *)s_Const_Instance(cllbk_PI));
c2 = *((IECReal *)s_Const_Instance(cllbk_2_0));
// Area calculation
*pArea = (IECReal)( pi * RAD * RAD );
// Circumference calculation
*pCirc = c2 * pi * RAD;
Section A.3
Concept EF/EFB Migration Procedure
Summary
The following section describes the Concept EF/EFB migration procedure.
WARNING
UNEXPECTED EQUIPMENT OPERATION
Migrated applications may not operate exactly as the original. All applicable tests for safe
operation must be performed before release of the migrated code.
Failure to follow these instructions can result in death, serious injury, or equipment
damage.
Retrieval
The Concept EFB tool stores the sources for an EF/EFB in a folder named for the function itself;
here we find the sources for migration:
<Library.Name>
.BLD Build information for 16-bit and 32-bit
.<EF/Efb> Function (block) definition file, C-
and Header files.
The table below compares the Concept file types to corresponding file types in Unity Pro:
Sample Procedure
Step Action
1 Start the Unity Pro EFB Toolkit.
2 Create a new family (File → New family...) using the same name as used in
Concept.
3 Complete the family description with the comment line in the Target Library in
Unity. The Library Management... button leads you to a dialog where you can
define the name of the Target Library in Unity that will be the repository for your
EFs.
Step Action
5 Start the translation of the EF interface from Concept to Unity Pro, using the
content from the <efb>.FB file. Here is an example:
//:-------------------------------------------------------
//:SUBSYSTEM: EFB - Elementary Function
//:
//:MODULE: ..\MIGRATE\CIRCLE.FB
//:
//:-------------------------------------------------------
//:Revision: 2.1 Modtime: 22 Jan 1998 AUTHOR: Any User
//:-------------------------------------------------------
Declaration of Elementary Function Block: CIRCLE
Author: Any User
Editor Group: Test Function
Major Version: 1
Minor Version: 0
Description: A full working test example.
//
// Not sure what to do ?
// Try generate-
files, make and install on this working example!
//
//Example:
// --------
Input: REAL RAD # Circle radius
Output: REAL AREA # Calculated circle area
Output: REAL CIRC # Calculated circle circumference
6 From the <efb>.H file, you also can get a graphical view of the function block
interface:
// Elementary Function Block: CIRCLE
//
//
// +-------------------+
// | CIRCLE |
// REAL ---| RAD AREA |--- REAL
// | CIRC |--- REAL
// +-------------------+
//
Step Action
7 Transfer the old Concept interface to Unity Pro:
8 Complete the interface definition. Then select the Current Object → Analyze
and Generate code menu operation.
Result: An empty EF frame appears that must be filled with the code from the
old EF. See an example of old Concept EF/EFB Code, page 160 and the new
EF code adapted for Unity Pro (see page 161).
9 Copy the code from the Concept source and paste it into the new Unity Pro
source created by the Unity Pro EFB Toolkit.
Note
This example shows the different ways in which floating point constants and operations are used
in Concept and Unity Pro function blocks. In Concept all values are passed to EFBs by reference;
this fact should be considered when migrating Concept EF/EFBs to Unity Pro.
Sample Code
//:-------------------------------------------------------
//:SUBSYSTEM: EFB - Elementary Function Block
//:
//:MODULE: CIRCLE
//:
//:-------------------------------------------------------
//:Revision: 1.0 Modtime: 17 Dec 2003 AUTHOR: Any User
//:-------------------------------------------------------
//:DESCRIPTION: A full working test example.’
//:
//:REMARKS:
//:-------------------------------------------------------
#include “MIGRATE.I”
radius = *RAD;
Sample Code
//{{ SDKC_HEADER_BEGIN Do not edit. Any modification would be lost
// Filename : C:\Program Files\Schneider Electric\
EFBToolkit\FFBDev\Sample\code\CIRCLE.c
//PROCEDURE : CIRCLE
//Version : 1.0
//Author : Auto generated EF/EFB
/*
PL7 migration example
This EF calculates the area and the circumference
to a given radius of a circle. */
#include “CIRCLE.h”
//}} SDKC_HEADER_END
pi = *((IECReal *)s_Const_Instance(cllbk_PI));
c2 = *((IECReal *)s_Const_Instance(cllbk_2_0));
// Area calculation
*pArea = (IECReal)( pi * RAD * RAD );
// Circumference calculation
*pCirc = c2 * pi * RAD;
Section A.4
Other Case Studies
Summary
The following section describes the use of defined data types (PL7 only), floating point constants,
ANY data types, extensible inputs (Concept only), PLC state determination and user error
reporting.
Introduction
The following migration example is for user-defined data types. EFs often require the use of
structured data types (derived data types in Unity Pro) to allow better and more formalized access
to variables inside an EF. If these data types were to be used in a PL7 EF interface, the PL7
application would need to reserve sufficient memory as required by EF.
Typically in a PL7 implementation, the address to the reserved word space is passed to the EF;
internally the EF maps the memory to a structured variable type.
short far pascal VT_AGCOM(
adrTABLE CONF, //configuration table
...
)
//PL7SDK_END_FUNCTION_NAME
{
CONFIG far *pConfig; // Ptr. To the configuration table
// Get the pointer and check that enough
memory has been reserved from application
// for configuration data.
...
}
The first impression is that there is no difference between PL7 and Unity Pro, but in fact the
difference is on the application side. As in Unity Pro, you may (and should) define a variable of type
CONFIG, but in PL7 it is only an array of words such as %MWxyz:NN.
There is no additional check necessary inside the Unity Pro function block code. Unity Pro ensures
that only variables of the correct type are connected to the function block.
The DDTs defined in the Unity Pro EFB Toolkit are available inside Unity Pro together with the
function block family.
Example
The following example shows the procedure for the EF code described above:
Step Action
1 Create a new DDT named CONFIG for the structure from the PL7 code shown
below. Select Current family → Create DDT to create the DDT. Define all the
structure components, including the sub-type DDTs if required.
2 Change the EF interface for the use of the defined data types:
//{{ SDKC_PROTOTYPE_BEGIN Do not edit. Any modification
would be lost
IECBool fb_call_model VT_AGCOM(
IEC_PARAM_RTE_OFFSET CONF, // Configuration
table
IEC_PARAM_RTE_OFFSET OUT // RETURNED VALUE -
This is the output pin
//}} SDKC_PROTOTYPE_END
{
// TODO : Write here variables declarations.
CONFIG *pConfig;
Step Action
4 Select File → Install family to install the family.
5 Start Unity PRO and create a new project. Define a new variable of type CONFIG
and pass it to the EF instance.
....
FunctionA(...)
{
IECReal r1, fconst_0;
....
Introduction
Data types of type ANY are always passed to an EF by reference, whereby the member parameter
length represents:
z the number of bytes for ANY_<type>
z the number of elements for ANY_ARRAY_<type>
Example
The following example shows the use of ANY_ARRAY_WORD in the EF interface
IECBool fb_call_model EF1(
IEC_PARAM_RTE_OFFSET_LG ARWORD, // This is the input pin
IEC_PARAM_RTE_OFFSET OUT // RETURNED VALUE -
This is the output pin
)
//}} SDKC_PROTOTYPE_END
{
// TODO : Write here variables declarations.
struct
{
IECWord a, b, c;
}
structure_X;
// TODO : Write here the code for your function block.
if( ARWORD.Length < sizeof( structure_X )/2 )
{
// Problem with the size of passed input
return FALSE; // ENO false, because of problems
}
else // processing
{
IECWord *pWordArr;
pWordArr = ( IECWord *)s_log_to_phy
( ARWORD.IECPtr_Log );
// Make a copy of the incoming data and then
process the structure_X structure_X.a = *pWordArr;
// ...
}
return TRUE ; // ENO value
}
Introduction
Data types of type REF are always passed to an EF by reference, whereby the member parameter
length represents:
z the number of bytes for REF_<type>
z the number of elements for REF_<type>
Example
The following example shows the use of REF_ANY in the EF interface
IECBool fb_call_model REF EX(
IEC_PARAM_RTE_OFFSET_LG INP, // This is the input pin
IEC_PARAM_RTE_OFFSET OUTP // RETURNED VALUE -
This is the output pin
)
//}} SDKC_PROTOTYPE_END
{
// TODO : Write here variables declarations.
struct
{
IECWord a, b, c;
}
structure_X;
// TODO : Write here the code for your function block.
if( INP.Length < sizeof( structure_X )/2 )
{
// Problem with the size of passed input
return FALSE; // ENO false, because of problems
}
else // processing
{
IECWord *pWordArr;
pWordArr = ( IECWord *)s_log_to_phy ( INP.IECPtr_Log );
}
return TRUE ; // ENO value
}
Introduction
In some cases, an EF may need to know whether the PLC has performed a cold or warm-start.
The EF may execute special code to reset or initialize data.
PROG_STATE ps;
s_AliGetProgStat( &ps );
// ...
}
Introduction
An EF/EFB can report its own error code when processing faults occur. The EF/EFB may call the
system function s_set_ffb_error with an error code derived from codes predefined in the
"SystemLib.h" header file. The system function creates an error record in the diagnostic buffer that
is shown later in a diagnostic display.
Extensible inputs
Introduction
The following example demonstrates migration for functions that use a variable number of inputs
(extensible pins). The code comes from the Concept SAMPLE library.
Concept Definition
EXTINP.FB
//:------------------------------------------------------
//:SUBSYSTEM: EFB - Elementary Function
//:
//:MODULE: ..\SAMPLE\EXTINP.FB
//:
//:------------------------------------------------------
Declaration of Elementary Function: SMPL_EXTINP
Author:
Editor Group: Sample
Major Version: 1
Minor Version: 0
Description: A sample to show usage of extensible inputs
The sum of all inputs is calculated and copied to the output OUT
Note: No error checks are made on overflow!
Input (2..32, default=2): INT IN # extensible inputs
Output: INT hide (OUT) # computed output
Concept implementation: EXTINP.C
//:------------------------------------------------------
//:SUBSYSTEM: EFB - Elementary Function
//:
//:MODULE: SAMPLE_EXTINP
//:
//:------------------------------------------------------
//:Revision: 1.0 Modtime: 17 Dec 1996
//:AUTHOR: Jochen Lichtenfels
//:------------------------------------------------------
//:DESCRIPTION: A sample to show usage of extensible inputs
//:
//:REMARKS:
//:------------------------------------------------------
#include “SAMPLE.I”
extern”C” BOOL FB_CALL_CONV SMPL_EXTINP(
INT nin , // No. of inputs
PTR_INT OUT , //computed output
// const PTR_INT IN , //extensible inputs
... )
{
open_IN;
{
INT sum = 0;
for (int n = 0; n < nin; n++)
{
sum += *next_IN;
}
*OUT = sum;
}
close_IN;
return TRUE;
}
Section A.5
Comparison Between PL7/Concept and Unity Pro
Summary
The following section describes the use of system functions, data types and definitions in the
include file.
Introduction
Introduction
The types and constants shown below are extracted from the SystemLib.h file, which is included
in the code of an EF.
Continuation:
Continuation:
Section A.6
An Empty Frame for a Unity Pro EF
Summary
The following section provides an example that shows the interface, header file, C-source template
and some programming hints.
Example_EF1 Interface
Characteristics
z The Kind type of this function block is PROCEDURE and not FUNCTION because it uses more
than one output.
z The values IO_BO1 and IO_ANYNU should be used for read/write operations. Therefore they
are inserted into the input/output section.
z The EF contains four code templates because of the ANY_NUM type of IO_ANYNU variable.
NOTE: When an EF has an ANY type parameter that is based on other elementary data types, it
must implement the code for each function template type created by the EFB Toolkit.
Template Definition
Coding Sample
//{{ SDKC_HEADER_BEGIN Do not edit. Any modification would be lost
//Filename : C:\Program Files\Schneider Electric\
EFBToolkit\FFBDev\Example1\code\EXAMPLE_EF1.h
//PROCEDURE : EXAMPLE_EF1
//Version : 1.0
//Author : Auto generated EF/EFB
/*
This is the comment of the demonstration EF
This is the descriptive form of the demonstration EF */
#include “SystemLib.h”
//Additional header :
//None
// +-------------------+
// | EXAMPLE_EF1 |
// +-------------------+
// | |
// --+- I_BO1 O_STR1 -+--
// | |
// --+- I-INT1 |
// | |
// --+- I_REAL1 |
// | |
// --+- I_AR_W1 |
// | |
// --+----- IO_BO1 ------+--
// | |
// --+----- IO_ANYNU-----+--
// | |
// +-------------------+
//
#ifdef SDKC_COMPILING_EXAMPLE_EF1_REAL
IECBool fb_call_model EXAMPLE_EF1_REAL(
const IECBool I_BO1, // Boolean value
const IECInt I_INT1, // Integer value
const IECReal I_REAL1, // Real value
IEC_PARAM_RTE_OFFSET_LG I_AR_W1, // Any array of words
IEC_PARAM_RTE_OFFSET IO_BO1, // Boolean variable
that keeps its value
IEC_PARAM_RTE_OFFSET IO_ANYNU, // Any number
variable that keeps its value
IEC_PARAM_RTE_OFFSET_LG O_STR1, // This is string output
#ifdef SDKC_COMPILING_EXAMPLE_EF1_UINT
IECBool fb_call_model EXAMPLE_EF1_UINT(
const IECBool I_BO1, // Boolean value
const IECInt I_INT1, // Integer value
const IECReal I_REAL1, // Real value
IEC_PARAM_RTE_OFFSET_LG I_AR_W1, // Any array of words
IEC_PARAM_RTE_OFFSET IO_BO1, // Boolean variable
that keeps its value
IEC_PARAM_RTE_OFFSET IO_ANYNU, // Any number
variable that keeps its value
IEC_PARAM_RTE_OFFSET_LG O_STR1, // This is string output
IEC_PARAM_RTE_OFFSET O_BO1 // This is a boolean output
) ;
#endif // SDKC_COMPILING_EXAMPLE_EF1_UINT
// }} SDKC_HEADER_END
TODO : Write here additional declaration.
Coding Sample
//{{ SDKC_HEADER_BEGIN Do not edit. Any modification would be lost
//Filename : C:\Program Files\Schneider Electric\
EFBToolkit\FFBDev\Example1\code\EXAMPLE_EF1.c
//PROCEDURE : EXAMPLE_EF1
//Version : 1.0
//Author : Auto generated EF/EFB
/*
This is the comment of the demonstration EF
This is the descriptive form of the demonstration EF */
#include “EXAMPLE_EF1.h”
//}} SDKC_HEADER_END
//{{ SDKC_PROTOTYPE_EXAMPLE_EF1_DINT_BEGIN
Do not edit. Any modifications would be lost
#ifdef SDKC_COMPILING_EXAMPLE_EF1_DINT
IECBool fb_call_model EXAMPLE_EF1_DINT(
const IECBool I_BO1, // Boolean value
const IECInt I_INT1, // Integer value
const IECReal I_REAL1, // Real value
IEC_PARAM_RTE_OFFSET_LG I_AR_W1, // Any array of words
IEC_PARAM_RTE_OFFSET IO_BO1, // Boolean variable
that keeps its value
IEC_PARAM_RTE_OFFSET IO_ANYNU, // Any number
variable that keeps its value
IEC_PARAM_RTE_OFFSET_LG O_STR1, // This is string output
IEC_PARAM_RTE_OFFSET O_BO1 // This is a boolean output
)
//}} SDKC_PROTOTYPE_EXAMPLE_EF1_DINT_END
{
// TODO : Write here variables declarations.
//{{ SDKC_PROTOTYPE_EXAMPLE_EF1_INT_BEGIN
Do not edit. Any modifications would be lost
#ifdef SDKC_COMPILING_EXAMPLE_EF1_INT
IECBool fb_call_model EXAMPLE_EF1_INT(
const IECBool I_BO1, // Boolean value
const IECInt I_INT1, // Integer value
const IECReal I_REAL1, // Real value
IEC_PARAM_RTE_OFFSET_LG I_AR_W1, // Any array of words
IEC_PARAM_RTE_OFFSET IO_BO1, // Boolean variable
that keeps its value
IEC_PARAM_RTE_OFFSET IO_ANYNU, // Any number
variable that keeps its value
IEC_PARAM_RTE_OFFSET_LG O_STR1, // This is string output
IEC_PARAM_RTE_OFFSET O_BO1 // This is a boolean output
)
//}} SDKC_PROTOTYPE_EXAMPLE_EF1_INT_END
{
// TODO : Write here variables declarations.
//{{ SDKC_PROTOTYPE_EXAMPLE_EF1_UDINT_BEGIN
Do not edit. Any modifications would be lost
#ifdef SDKC_COMPILING_EXAMPLE_EF1_UDINT
IECBool fb_call_model EXAMPLE_EF1_UDINT(
const IECBool I_BO1, // Boolean value
const IECInt I_INT1, // Integer value
const IECReal I_REAL1, // Real value
IEC_PARAM_RTE_OFFSET_LG I_AR_W1, // Any array of words
IEC_PARAM_RTE_OFFSET IO_BO1, // Boolean variable
that keeps its value
IEC_PARAM_RTE_OFFSET IO_ANYNU, // Any number
variable that keeps its value
IEC_PARAM_RTE_OFFSET_LG O_STR1, // This is string output
IEC_PARAM_RTE_OFFSET O_BO1 // This is a boolean output
)
//}} SDKC_PROTOTYPE_EXAMPLE_EF1_UDINT_END
{
// TODO : Write here variables declarations.
//{{ SDKC_PROTOTYPE_EXAMPLE_EF1_UINT_BEGIN
Do not edit. Any modifications would be lost
#ifdef SDKC_COMPILING_EXAMPLE_EF1_UINT
IECBool fb_call_model EXAMPLE_EF1_UINT(
const IECBool I_BO1, // Boolean value
const IECInt I_INT1, // Integer value
const IECReal I_REAL1, // Real value
IEC_PARAM_RTE_OFFSET_LG I_AR_W1, // Any array of words
IEC_PARAM_RTE_OFFSET IO_BO1, // Boolean variable
that keeps its value
IEC_PARAM_RTE_OFFSET IO_ANYNU, // Any number
variable that keeps its value
IEC_PARAM_RTE_OFFSET_LG O_STR1, // This is string output
IEC_PARAM_RTE_OFFSET O_BO1 // This is a boolean output
)
//}} SDKC_PROTOTYPE_EXAMPLE_EF1_UINT_END
{
// TODO : Write here variables declarations.
Programming Hints
Introduction
The following coding provides an interface to the example described in this section. There are no
restrictions for variable inputs passed by a value. All variables passed as their logical addresses
may be accessed only by their physical addresses. You must resolve the addressing differences
before accessing variables.
Coding Sample
// Floating point constants declaration
const float in_Code cllbk_float0 = (float)0.0;
s_Declare_Logical (cllbk_float0);
//{{ SDKC_PROTOTYPE_EXAMPLE_EF1_REAL_BEGIN
Do not edit. Any modifications would be lost
#ifdef SDKC_COMPILING_EXAMPLE_EF1_REAL
IECBool fb_call_model EXAMPLE_EF1_REAL(
const IECBool I_BO1, // Boolean value
const IECInt I_INT1, // Integer value
const IECReal I_REAL1, // Real value
IEC_PARAM_RTE_OFFSET_LG I_AR_W1, // Any array of words
IEC_PARAM_RTE_OFFSET IO_BO1, // Boolean variable
that keeps its value
IEC_PARAM_RTE_OFFSET IO_ANYNU, // Any number
variable that keeps its value
IEC_PARAM_RTE_OFFSET_LG O_STR1, // This is string output
IEC_PARAM_RTE_OFFSET O_BO1 // This is a boolean output
)
//}} SDKC_PROTOTYPE_EXAMPLE_EF1_REAL_END
{
// TODO : Write here variables declarations.
IECReal *pReal;
// Reset an string
// Caution! DON’T OVERWRITE the ’Length’
configuration parameter of a STRING type.
Index
Symbols debug
best practices, 75
*.dsc, 11
test of boolean variables, 38
edit dsc files, 12
directory, 32
*.h, 60
dsc
edit dsc files, 12
A
Address E
Logical, 39
edit
Physical, 39
dsc files, 12
Addressing, 39
EF/EFB, 51
addressing
EF/EFB differences, 58
at the global level, 43
EFB source code, 62
ARM architecture, 37
EFB Toolkit installation, 14
Array, 24, 25
EFB toolkit services and user functions
comparison between the different block
B types, 29
EFBs, 11
best practices, 75 EFs, 11
elementary function blocks, 11
elementary functions, 11
C EN/ENO, 46
coding rules, 36 error, 47
compiler options error management, 46
GNU C ARM ELF, 18 event
Microsoft Visual C 32bit, 18 LanguageEntryPoint, 58
Concept EF/EFB migration procedure, 155 SystemEntryPoint, 58
Constants, 41 example, 51
Global Level, 41
In procedures, 41
F
family
D description file, 11
data Family descriptor., 22
access to unaligned data, 37 fb_call_model, 56
unaligned data, 37 for the EFB Toolkit software, 15
data instance function
EFB, 45 characteristics, 12
DDT, 51
G P
GNU C ARM ELF, 18 PL7 EF migration, 146
graphical user interface PL7 EF migration procedure, 147
for the EFB Toolkit, 16 procedure
GUI, 16 characteristics, 12
public variables, 61
H
Header file, 60 R
help files for EFBs, 33 recommendations, 76
help on type, 33 registration, 15
requirements, 14
return code, 46
I
instance, 11
Instance, 52 S
Instance Data, 63 s_AliGetProgStat, 84
internal variables, 61 s_cnt_100ms, 116
s_cnt_10ms, 117
s_cnt_1ms, 118
K s_Const_Instance, 57
Kind, 25 s_current_task, 123
s_date_and_time, 119
s_Declare_Logical, 56
L s_demask_it, 135
language, 31 s_diag_DeregisterError, 131
multi language support, 31 s_diag_RegisterExtError, 129
supported languages, 32 s_GetUSecs, 136
LanguageEntryPoint, 58, 61 s_Local_Instance, 41
s_log_to_phy, 57, 86
s_log_to_phy(), 40
M s_mask_it, 137
Microsoft Visual C 32bit, 18 s_obj_nbr, 90
multi language support s_obj_to_log, 88
directory structure, 32 s_of_passw_check, 133
s_of_passw_test, 134
s_proc_indic, 138
N s_proc_type, 140
nested DDTs, 66 s_rd_16bits, 91
s_rd_1bit, 93
s_rd_bit_attrib, 95
O s_rd_internalwords, 97
s_rd_Nbits, 99
operating system
s_rd_sysbit, 101
EFB Toolkit requirements, 14
s_rd_sysword, 102
s_set_ffb_error, 125
s_set_ffb_error_addi, 127
s_syscnt_10ms, 122
s_wr_16bits, 103
s_wr_1bit, 105
s_wr_bits_attrib, 107
s_wr_internalwords, 109
s_wr_Nbits, 111
s_wr_sysbit, 113
s_wr_sysword, 115
Structure, 24, 25
SystemEntryPoint, 58
T
test
boolean variables, 38
U
unaligned data, 37
user functions, 13
V
variables, 61
W
warning, 47
warnings, 72