EF Function Code
EF Function Code
___________________________________________________________________________
Section Page
1 Introduction 5
1.1 Introduction 5
1.2 Installation 6
1.2-1 Target machine 6
1.2-2 PL7 SDKC product contents 6
1.2-3 Installation procedure 7
2.1 Creation 11
2.1-1 The EF family 11
2.1-2 The EF class 11
2.1-3 The EF 12
3.1 Creation 15
3.1-1 The EF family 15
3.1-2 The EF class 17
3.1-3 The EF 19
___________________________________________________________________________
1
Contents
___________________________________________________________________________
Section Page
5.3 Importing/Exporting 37
5.3-1 Class 37
5.3-2 C Source 38
___________________________________________________________________________
2
Contents
___________________________________________________________________________
Section Page
6 The EF code 43
7 System functions 51
8 Appendix 73
8.1 Example 73
8.1-1 Defining the EF 73
8.1-2 Generating a diskette and installing the family 78
___________________________________________________________________________
3
Contents
___________________________________________________________________________
Section Page
___________________________________________________________________________
4
Introduction1
Section
1 Introduction
1.1 Introduction
As it will in due course form part of the PL7 library, like the manufacturer functions, it can
be used in an identical way :
• accessible in all languages
• display via the PL7 library tool
• classified in families/functions
The development kit in "C" language (PL7 option) is designed to implement the entire
development cycle of an EF family :
• management of an EF family (creation, modification)
• development of each EF in “C” language
• individual debugging of an EF in the target PLC (TSX 37 or TSX 57)
• generation of an installable form containing the new EF family to be installed in the PL7
library, as well as its installation procedure on a user station.
Users of this product will be systems developers and therefore will necessarily be
familiar with :
• “C” language for development,
• PL7 (Micro and Junior) and their languages for debugging.
The access key (*) supplied with the kit, makes it possible to manage 5 families
(up to 25500 functions per family) in the form of 5 different codes.
(*) On page 8 of this manual, write the number of the access key marked on the
box in which your product was delivered.
___________________________________________________________________________
5
Introduction
1.2 Installation
___________________________________________________________________________
6
Introduction
The PL7 SDKC product should be installed on a development station, on which PL7
Micro or PL7 Junior has already been installed.
Once the diskette has been inserted into the drive, proceed with installation by means
of the following steps :
• Windows 3.1 : From the file manager, select the File-Run command, type a:\setup,
press enter.
Windows 95 : Open the Windows explorer, select drive (A) then double-click on
setup.exe or in Run from the Start Menu, type a:\setup then click on OK.
• Register your name and organization
• Select the installation language
• Enter the no. (your product's access key) marked on the delivery box (*). This key
is used to access the five family codes assigned to the product. Installation cannot
proceed if the number of this access key is incorrectly entered.
• Once installation is complete, simply double-click on the icon in the MODICON-
TELEMECANIQUE group to access PL7 SDKC.
(*) We strongly recommend making a note of the number of the access key on the
space provided on the following page.
___________________________________________________________________________
7
Introduction
1 ........................................................................
2 ........................................................................
3 ........................................................................
4 ........................................................................
5 ........................................................................
6 ........................................................................
7 ........................................................................
8 ........................................................................
9 ........................................................................
___________________________________________________________________________
8
Methodology for creating and using an EF in PL72
Section
2 Methodology for creating and using an EF in PL7
PL7 SDKC
Generate family
in Debug mode
error no error
▼
Development station
▼
▼
Develop Install the family on
the family ▼ the development station
Generate family
error in release mode
▼
no error
PL7 Micro/Junior
▼
Debug
an EF ▼
EF family
+
Setup.exe
User station
PL7 Micro/Junior
▼
EF
library
The object of the following sections is to present the various screens which appear
during this development cycle.
___________________________________________________________________________
9
Methodology for creating and using an EF in PL7
Clicking on the PL7 SDKC icon displays the following initial screen :
10
The left-hand side of this screen, which is empty the first time the kit is used, will be filled
with names of EF families, as they are created (Current and/or Archived).
A family consists of one or more classes, which themselves consist of one or more EFs
as shown by the diagram below :
Family name
Class1
EF1
EF2
Class2
EF1
EF2
EF3
A family is made up of 100 Classes maximum and 255 EFs per class. The class is an
entity which is only used while developing the family and which will not be displayed in
the PL7 Library tool.
The version, filled in when the description of the family is defined, is as displayed in the
PL7 Library tool.
___________________________________________________________________________
10
Methodology for creating and using an EF in PL7
2.1 Creation
It is possible to create a family by selecting the Create function from the Family menu.
Five families can be created. They correspond to five codes supplied by the product.
Once the family has been validated, by selecting the Create Class function from the
Utilities menu, it is possible to create one of the classes authorized by the family (1 to
100).
___________________________________________________________________________
11
Methodology for creating and using an EF in PL7
2.1-3 The EF
At the end of creation, the name of the class appears on the left-hand side of the screen,
and an EF can then be created by selecting the function Create EF from the Utilities
menu. 255 EFs can be created per class (1 to 255).
12
___________________________________________________________________________
12
Methodology for creating and using an EF in PL7
Generation is performed on the whole family, but it is possible to request partial or total
generation.
Once the family has been developed, it is advisable, at first, to generate it by selecting
the Generate Debug function from the Family menu. This then makes it possible to test
one of the EF of the family.
Generate means compile and then edit the links with the debug options of each EF of
this family.
Once generation is complete, a log file summarizing the errors and warnings (resul.log)
is created (see section 3.1-3), and the user should return to the .C or .H source screens
of any EF(s) which may be causing a problem.
Once the family has been generated without any errors (compilation or link editing), it
is possible to launch the Install function from the Family menu so that it can be entered
in the PL7 library.
The family which is being edited can be removed from the PL7 library. To do this, launch
the Uninstall function from the Family menu.
Once the family has been installed, PL7 (Micro or Junior) should be launched.
The user should test the new EF(s), by developing an application which calls them, and
then transferring this application to the PLC.
Since this application is designed to test behavior, it is advisable to include only one copy
of each EF to be tested.
___________________________________________________________________________
13
Methodology for creating and using an EF in PL7
To test the EF in the application, select Debug EF from the Application menu of PL7
(Micro or Junior).
It is then possible to insert breakpoints, proceed step by step, display local variables or
registers, etc.
If the tests are not conclusive, the user should return to the EF development environment
to review the process and restart the cycle described above.
Once all the tests on all the EF in the family have proved conclusive, it is then possible
to generate this family, for use, by selecting the Generate Release function from the
Family menu.
14 This action makes it possible to create an installation medium for the selected family
(diskette, local or networked hard disk directory, etc). This medium can then be
broadcast.
___________________________________________________________________________
14
Managing the EF usingSection
PL7 SDKC3
3 Managing the EF using PL7 SDKC
3.1 Creation
A family
number will
be assigned
automatically
(any of the 5
possible)
Integer beginning
at 1. This is used
In family display mode, to manage
this will display the updates which
created and/or archived would make the
families in the list (see texts (family
section 5.4) datasheet and
comments)
incompatible
___________________________________________________________________________
15
Managing the EF using PL7 SDKC
This area where text can be entered (optional), is used to note down the main data
concerning the family.
This datasheet can, for example, be used to enter log data on the versions of the family.
This datasheet only appears in PL7 if there is a conflict in versions between a family in
the library and the same family in the application.
It is possible to delete a family using the Delete command from the Utilities menu. When
a family is deleted, its contents (class(es) and EF(s)) are also deleted.
___________________________________________________________________________
16
Managing the EF using PL7 SDKC
Classes which belong to the same family must, without fail, have different names and
codes.
It is only possible to exit from the description tab once all the fields have been filled in.
This action confirms the parameters entered.
It is possible to delete a class using the Delete command from the Utilities menu. When
a class is deleted, the EF(s) which it comprises are also deleted.
___________________________________________________________________________
17
Managing the EF using PL7 SDKC
The "Import class" and "Export class" functions in the Utilities menu are used to import
a class from another family and export a class to another family (see section 5.3).
This area is used to enter the ( .h) interface file source code common to all the EFs in
the class. This file is used to create for example special types or constants which will be
reused in the C sources of all the EFs in the class.
This file should be ≤ 64 Kbytes.
___________________________________________________________________________
18
Managing the EF using PL7 SDKC
3.1-3 The EF
Create EF opens the
EF fields for data entry
and enters information
in the area defined by
the "Description" tab
Reminder of
the param-
eters defined
for the family
and the class
(read-only)
The EF type
is a proce-
dure
Number
between 1
Used to and 100
Used to enter
enter a text Used to define the size inclusive
the name of
commentary of the stack. Its default used to
the EF being
on the EF value is 512 bytes and ensure the
created (16
containing it is used to store the uniqueness
alphanumerical
a maximum EF parameters, local of the EF
characters + the
of 80 variables, and the developed.
underscore
characters parameters and It is filled in
character)
variables of the automatically
functions which it calls
(see section 6.1-3)
EFs developed and installed in library mode must, without fail, have different names. Be
careful not to use PL7 key words as names (see section 6.2).
It is only possible to exit from the description tab once all the fields have been filled in.
This action confirms the parameters entered.
It is possible to delete an EF using the Delete command from the Utilities menu.
___________________________________________________________________________
19
Managing the EF using PL7 SDKC
Clicking on the "Interface" tab opens the following area, comprising three zones which
are used to enter the EF formal parameters.
These formal parameters are those for inputs, outputs, and I/O.
Example :
Buttons used to
change the order
of the parameters
in the selected
grid
At the formal parameters level, there is a maximum of 7 inputs, 7 outputs and 17 I/O.
It is possible to delete one or more parameter lines by selecting the line and clicking on
the corresponding number. Type Ctrl+x on the keyboard (Ctrl+v repastes what has been
cut).
For the correspondence between PL7 types defined in this tab and C types present in
the function header, see the table in section 6.1.
___________________________________________________________________________
20
Managing the EF using PL7 SDKC
This tab accesses C code editing. The user can use his own editor if he wishes or if the
C file is greater than 64 K, using export and import.
As with other standard tools on the market, comments containing special key words are
generated.
When PL7 SDKC creates the function header for the first time, the key words
PL7SDK_BEGIN_FUNCTION_NAME and PL7SDK_END_FUNCTION_NAME are
inserted automatically.
On exiting this tab, or when modifying the interface in the previous tab, PL7 SDKC
automatically generates this header, which ensures consistency between the declared
interface and the interface in the code.
Using the Edit menu, the current functions are offered by EditText (cut, copy, paste, find,
replace).
Other functions are available, such as :
• Selecting by double-clicking
• Displaying the line number corresponding to the present position of the cursor, in the
Status Bar.
___________________________________________________________________________
21
Managing the EF using PL7 SDKC
To inform the user of errors resulting from the C source compilation, the source code line
containing the error is indicated.
A file giving the results of the compilation is generated. It can be accessed by the View
generation results command in the Family menu and provides information on any errors.
Definition of the EF interface automatically generates the prototype of the latter in the
FILE MAINxxyy.C where xx is the class code and yy the EF code. The user can export
the source if he wishes, work on it, and then re-import it.
There is no subsequent check on any manual modifications made to the EF main
function interface. If the user modifies the interface, these modifications will be ignored.
The interface is automatically regenerated from the interface tab.
If the file is too large to be displayed this will be indicated. However, the function
prototype will still be generated automatically.
• the user works with the editor supplied, and reaches the limit of 64K for the current
EF.
At that moment the following message is displayed :
«Your file is too large to be edited using PL7SDKC. Please export it, then re-import
it».
___________________________________________________________________________
22
Managing the EF using PL7 SDKC
T o g g l e
button (Nor-
mal size/Full
screen)
reduces/
enlarges the
e n t r y
window
This area is used to define constants, types or structures specific to the EF.
This file must be ≤ 64 Kbytes.
___________________________________________________________________________
23
Managing the EF using PL7 SDKC
Once the creation phase is complete, it is possible to proceed to generation of the family
in debug mode. To do this, select Generate all Debug from the Family menu as shown
in the screen below.
The role of this generation is to activate the various software tools used to obtain a new
family (all classes) and to check data consistency along the whole generation string.
If there is a problem, a screen indicating the nature of the error(s) to be corrected opens,
so that generation can be relaunched.
Partial generation (Generate from the Family menu) can save time if the family has
several classes and the modifications only affect one class. In this case, the
unmodified classes are not regenerated.
It is possible to monitor the generation process from the information line at the bottom
of the screen. Once generation is complete, the message "x error(s), y warning(s)" is
displayed and an audio beep emitted.
A "Generated in Debug mode" status followed by a generation date is written in the family
description zone, and this family can then be installed in the library.
Information about the generation can be accessed by opening the results file (View
generation results from the Family menu).
___________________________________________________________________________
24
Managing the EF using PL7 SDKC
The last phase is to proceed to generation of the family in release mode (code size
minimized). To do this, select Generate all Release from the Family menu as shown in
the screen below.
The role of this generation is to activate the various software tools used to obtain a new
family (all classes) and to create the corresponding files.
Partial generation (Generate from the Family menu) can save time if the family has
several classes and the modifications only affect one class. In this case, the
unmodified classes are not regenerated.
It is possible to monitor the generation process from the information line at the bottom
of the screen. Once generation is complete, the message "x error(s), y warning(s)" is
displayed and an audio beep emitted.
A "Generated in Release mode" status followed by a generation date is written in the
family description zone.
Information about the generation can be accessed by opening the results file (View
generation results from the Family menu).
Once generation is complete, the necessary elements (files) are automatically copied
into the medium selected for broadcasting (diskette, network disk, etc). This space is
part of the parameters defined in the tool customization menu (see section 5.1)
___________________________________________________________________________
25
Managing the EF using PL7 SDKC
If the code of the family to be installed already exists in the library, a dialog box opens
If the family is new and intended to replace an old one, click on "Overwrite".
If an error is made, or the user is unsure, it is possible to cancel installation in the library
by selecting Quit.
When installation is complete, the message "The family has been installed in the library"
appears and installation is effective.
It is possible to uninstall a family from the PL7 library. It is necessary to select the
Uninstall command from the Family menu when a family is being edited.
___________________________________________________________________________
26
Section
Testing the EF using the debugging tool4
4 Testing the EF using the debugging tool
4.1 Accessing EF debugging
As described in the previous section, the EFs of families generated in debug mode can
be debugged, one at a time, in PL7 Micro and Junior.
Once PL7 is launched and the program containing the EF to be tested loaded into the
PLC, the Debug EF command in the Application menu opens the following screen which
is used to select the development directory (dvt_ef, by default), then the family
containing the EF.
The name of the family (generated in debug mode) and its code number appear
Used to search
for the drive and
the development
directory
Summary of
information
about the
family
Once the family containing the EF to be tested has been found, clicking on OK opens
the EF debug environment, described in the next paragraph.
Opening the screen adds a "Debug EF" menu to the PL7 menu bar.
Selecting the EF command from the Debug EF menu, or clicking on the button
(2nd button from the left), opens the screen used to select the EF to be tested.
In our example, there is only one EF in the family (the "MAX_TABW" EF which we wish
to test), the code of the class to which it belongs, its EF code, its name and its comment
appear.
Clicking on OK opens a screen which gives the C source of the EF (see section 4.3-1).
Depending on the complexity of the EF, it may take several seconds to access this
screen.
___________________________________________________________________________
28
Testing the EF using the debugging tool
(4th button from the left) or the Go command from the Debug EF menu is used
to relaunch the PLC from the breakpoint or current step.
(5th button from the left) or the Step Into command from the Debug EF menu :
is used to go inside a function (if the function is present in the C source of the EF).
(6th button from the left) or the Step Over command from the Debug EF menu:
is used to skip a function (step over).
(7th button from the left) or the Step Out command from the Debug EF menu :
is used to exit a C function comprising a EF.
• the Registers command in the Debug EF menu is used to display a list of all the
registers used by the CPU µprocessor (see section 4.3-3).
• the Local variables command in the Debug EF menu is used to display a list of
variables used locally (see section 4.3-4).
• the Mix C/Asm command in the Debug EF menu is used to change from a presentation
in C language to a presentation in C language and in assembly language.
• the Breakpoints command from the Debug EF menu is used to display a screen giving
information on the position of breakpoints.
• the Step to Cursor command from the Debug EF menu is used to relaunch the PLC,
from the step where it is stopped back to the cursor.
___________________________________________________________________________
29
Testing the EF using the debugging tool
Following the procedure described above (see section 4.2-1), the C source code of the
EF is displayed on-screen and debugging can begin.
It will be possible, using the tool commands and buttons, to perform all the usual debug
operations, namely :
• Insert and remove breakpoints,
• Proceed step by step,
• Scroll through part of the program,
• Go inside a function,
• Analyze using the lists of registers and local variables,
• Edit the EF in C code and assembly language, to meet the needs of a more precise
analysis of part of the program which could cause problems.
Select a line by pointing the cursor at it, then press the button to insert a
breakpoint on this line. The same button is used to remove a breakpoint. Up to 7
breakpoints can be inserted simultaneously.
A breakpoint is indicated by a blue line. It is thus possible to insert or remove all the
breakpoints desired.
If the PLC is running and if the program moves to one of the breakpoints, the line in
question becomes yellow.
Using the , , buttons, it is easy to enter/exit from a function or skip a
function.
Extract of the EF C
source code with two
breakpoints (one blue
line, one yellow line)
___________________________________________________________________________
30
Testing the EF using the debugging tool
The Mix C/Asm command from the Debug EF menu is used to change from a
presentation in C language to a presentation in C language and in assembly
language.
4.3-3 Registers
The Registers command in the Debug EF menu is used to display a list of all the registers
used by the CPU µprocessor, as well as the contents of the execution stack which
contains the local variables and the parameters of the function in which the program has
stopped.
___________________________________________________________________________
31
Testing the EF using the debugging tool
The Local variables command from the Debug EF menu is used to display a list of the
local variables and parameters of the function in which the program has stopped.
All the numerical values displayed in this screen are expressed in hexadecimal
format.
The syntax used to define the types of local variables and parameters is described
below :
+: the "plus" sign indicates that the object on the line can be expanded.
- : the "minus" sign indicates that the object on the line can be shrunk.
{...} : indicates that the corresponding object is a structure.
[] : indicates that the corresponding object is a table.
0xabcd:0xabcd : indicates that the corresponding object is a pointer. By expanding
it, the type of object pointed to will appear.
%xxxxxxxx : where x takes the value 0 or 1, this indicates that the
corresponding object is a bit field.
___________________________________________________________________________
32
Testing the EF using the debugging tool
To exit at the end of an EF debug session, use either the tool button, or the usual
commands for exiting a Windows screen.
If a problem arises during an EF test, and it was not possible to close the debug
EF tool, the application will have to be reloaded into the PLC before restarting a
session.
___________________________________________________________________________
33
Testing the EF using the debugging tool
___________________________________________________________________________
34
Additional SDKC functions5
Section
5 Additional SDKC functions
5.1 Setting the tool parameters
The Customize command in the Utilities menu opens the following window. Here,
parameters can be set for a number of working directories which assist operation of the
tool.
The arrows located to the right of each field open a dialog box where another disk/
directory can be selected for that field.
___________________________________________________________________________
35
Additional SDKC functions
This action opens the "Name" and "Version" fields, where data can be entered.
This step could prove useful, for example, if the version number of a family needed
changing after being updated.
Clicking on "Confirm" takes this modification into account and opens the family, so that
a class/EF can be created/viewed (see section 3.1.2, section 3.1.3).
___________________________________________________________________________
36
Additional SDKC functions
5.3 Importing/Exporting
5.3-1 Class
When a family is open, two commands in the Utilities menu are used to import and/or
export class(es) into/from this family.
Exporting a class consists of copying the class into the appropriate directory defined
when customizing the tool (see section 5.1).
When the "Class1" class of this family is exported, a file called " CLASSE01.EXP",
containing all the intrinsic elements of this class, is copied into the directory.
Once export is complete, the message : The "Class1" class was successfully exported
to "C:\SDKCWTMP\IMPCLASS\CLASSE01.EXP" indicates that the operation is
complete.
The group of two numbers at the end of the file name "CLASSE01" indicates the code
for the class in hexadecimal format (code 1 class, in this example).
"Import-Export class" files are distinguished by the suffix .EXP.
which displays the contents of the "Import-export class" directory referred to earlier, and
choosing the file corresponding to the class you wish to import into a family.
___________________________________________________________________________
37
Additional SDKC functions
Select the " CLASSE01.EXP" file, which contains all the intrinsic elements of this class,
and click on OK.
Yes will import the new class (all the intrinsic elements of this class) and will
overwrite the old class with the same code (all the intrinsic elements of that
class).
No cancels the import instruction and reverts to the initial situation.
5.3-2 C Source
From the "C Source" tab of an EF, two buttons can be used to import and/or export the
C Source code from another EF.
Exporting the C Source of an EF consists of copying the code into the appropriate
directory defined when customizing the tool (see section 5.1).
When the content of the C Source tab of the "MAX_TABW" EF is exported, this code is
copied into a file "MAIN0101.C" in the directory.
Once export is complete, the message : The "MAIN0101.C" source file has been copied
to "C:\SDKCWTMP\IMPSRC\MAIN0101.C", indicates that the operation is complete.
The two groups of two numbers at the end of the file name "MAIN0101" indicate the class
code followed by the EF code (code 1 class, code 1 EF, in this example). These codes
are expressed in hexadecimal format.
"Import-Export C Source" files are distinguished by the suffix .C.
This type of MAINxxxx.C file can be opened by a commercial C editor (more sophisticated).
Once the C file exceeds the limits of the edit zone (64 Kbytes), this type of editor must
be used.
which displays the contents of the "Import-export C sources" directory referred to earlier,
and choosing the file corresponding to the C Source code you wish to import into the EF.
Example : If you wish to import the C Source contained in the file "MAIN0102.C"
Select this file and click on OK. This brings up the following message :
OK imports the new C Source code and overwrites the old one.
Cancel reverts to the initial situation.
___________________________________________________________________________
39
Additional SDKC functions
5.4-1 Archiving
Once a family has been created, and its class(es) and EF(s) have been created and their
parameters set, it is advisable to archive it.
This operation is performed by activating the Archive command in the Family menu, as
indicated on the following screen :
Once the family has been archived, if archive display is selected, the archive appears
on the left-hand side of the screen. When the archive is selected, a screen appears
which contains the main characteristics of the archived family.
A zone opens where comments about the archive can be entered ; these comments will
be extremely useful if the archive is ever retrieved.
___________________________________________________________________________
40
Additional SDKC functions
5.4-2 Restoring
The object of the "Restore" function is to replace a given family with a previously
archived one. This function is performed by activating the Restore command on the
Family menu, as indicated on the following screen :
When executing the Archive/Restore functions, the files created or manipulated are to
be found in the directory defined in the customization screen (see section 5.1) under the
item : General directory of EF families (C:\DVT_EF by default). These files are called,
respectively :
• CRD_xxxx.yyy : for the family datasheet
• CAT_xxxx.yyy : for information about the family
• FAM_xxxx.yyy : for the complete archive
where xxxx corresponds to the family code in hexadecimal format, and yyy to the archive
number.
___________________________________________________________________________
41
Additional SDKC functions
___________________________________________________________________________
42
The EF code6
Section
6 The EF code
6.1 Rules for implementing EFs
6.1-1 C Language
No. 8 The types and constants shown on the next page are an extract from the
CSTSYST.H file, which is included automatically at the beginning of each C
source describing an EF.
___________________________________________________________________________
43
The EF code
//Definition of constants
#define NIL
#define NILL
#define INVALID_ADDRESS
#define NULL_FPTR
#define GAMME_TSX37 4
#define REFCAT_TSX37_10 1
#define REFCAT_TSX37_21 2
#define REFCAT_TSX37_22 3
#define GAMME_TSX57 5
#define REFCAT_TSX57_10 1
#define REFCAT_TSX57_20 2
//Definition of types
#define BOOL short
#define BYTE unsigned char
#define WORD unsigned short
#define DWORD unsigned long
//Definition of structures
typedef struct {
void __near *off; // Offset
unsigned short sel; // Selector number
}PTR_LOG;
___________________________________________________________________________
44
The EF code
typedef struct {
unsigned short selecteur;
unsigned short offset;
} adrSCAL;
typedef struct {
unsigned short selecteur;
unsigned short offset;
unsigned short taille; // Size of table or string
} adrTABLE;
typedef struct {
unsigned short selecteur;
unsigned short offset;
} adrFBIT;
typedef struct {
unsigned short selecteur;
unsigned short offset;
unsigned short rang; // discrete value : 0..15
} adrNFBIT;
typedef struct {
unsigned char gamme; // Processor range
unsigned char version; // OS version present in the
processor
unsigned char codecat; // Catalog reference code for
the CPU model
unsigned char unused;
} PROC_IDENT;
typedef struct {
unsigned char reserved ;
unsigned char Second ;
unsigned char Minut ;
unsigned char Hour ;
unsigned char DayMonth ;
unsigned char Month ;
unsigned char Year ;
unsigned char Century ;
unsigned char DayWeek ;
} DATE_TIME ;
___________________________________________________________________________
45
The EF code
typedef struct {
unsigned Run : 1; /* 1 if run */
unsigned AppliExec : 1; /* 1 if compatibility index between
appli and processor ok */
unsigned CartMemDetect :1; /* 1 if mem. cart. detected */
unsigned Reservation : 1; /* 1 if reservation applied */
unsigned BrkptSet : 1; /* 1 if brkpt set */
unsigned AppliFailure : 1; /* 1 if appli «halted» */
unsigned PartialRun : 1; /* 1 if partial run */
unsigned CartFlashErase : 1; /* 1 if the FEPROM mem. cart. */
/* is being erased */
unsigned UserMemProtect : 1; /* 1 if the application memory */
/* is write-protected */
unsigned Reserved : 7; /* reserved bits */
} PROC_INDIC ;
A version number (VV.RR format) is allocated to an EF family and to each class in the
family.
A text information compatibility index is allocated to an EF family. If the family versions
in the library and an application are inconsistent, this indicator can be used to determine
the validity of help information associated with the EFs (general comment, name and
comment for its parameters) which make up the family.
No. 9 For a family already installed in the library, any modification within a class
must without fail involve upgrading its version number (the index and/or the
release index), as well as the version number of the family to which it belongs.
Adhering to this rule is compulsory in order to be able to update existing PL7
applications which contain EFs of the class in an older version.
Caution : the version number of a family does not necessarily correspond to the
highest version number associated with the classes it contains.
Example : a version 2.1 family F, consisting of classes C1, C2 and C3 which are
versions 1.0, 2.1 and 1.0 respectively.
If class C1 develops from 1.0 to 1.1, the version of family F should change from
2.1 to 2.2 at minimum.
___________________________________________________________________________
46
The EF code
No. 10 A new EF family version must still be completely compatible with the
previous version :
Note : during the EF debug phase, it is advisable to assign version numbers to classes
and families starting from 0.01, in order to subsequently be able to assign version 1.0
to the marketed product.
It is the user's responsibility to manage the size reserved for the EF execution stack. It
is important to make an accurate calculation, as :
• if it is too small, the PLC will show an error.
• if it is too large, there is that much less space for the PLC data memory.
To calculate the size, add together the sizes of :
• the EF parameters and local variables,
• the parameters and local variables of the functions which it calls, by examining the
longest call tree.
___________________________________________________________________________
47
The EF code
STRUCT WORD
SUB WRITE
SUB_DT WRITE_CMD
SUB_TOD WRITE_PARAM
SUM WRITE_VAR
SU_TYPE WRTC
S_T_AND_LINK WSHL_RBIT
S_T_OR_LINK WSHRZ_C
T WSHR_RBIT
TAN W_BIT
TASK XM
TASKS XM_MONO
THEN XM_MULTI
TIME XOR
TIMER XORF
TIME_OF_DAY XORN
TMAX XORR
TMOVE XOR_ARX
TO YES
TOD
TOF
TOFF
TON
TOP
TP
TRANSITION
TRANS_TIME
TRUE
TRUNC
TYPE
TYPES
T_S_AND_LINK
T_S_OR_LINK
U
UDINT
UINT
ULINT
UNMASKEVT
UNTIL
UP
USINT
USORT_ARD
USORT_ARW
UTIN_CHAR
VAR
VAR_ACCESS
VAR_EXTERNAL
VAR_GLOBAL
VAR_INPUT
VAR_IN_OUT
VAR_OUTPUT
VERSION
V_COMPARE
V_LINK
W
WHILE
WITH
___________________________________________________________________________
50
System functions7
Section
7 System functions
System functions present in the PLC CPU can be called within the body of an EF.
They are as follows :
Note : As it is possible, using these functions, to write to the PLC memory, the user
should take certain access precautions.
Example : Once a table has become an EF parameter, be careful not to access words
outside this table. This can be checked by testing the length of the table.
The following pages describe these functions, their parameters and the types used, with
the help of examples.
___________________________________________________________________________
51
System functions
Description
Reads system bit %Si identified by its number.
The consistency of the bit number is checked.
Input parameters
sysbit_range : Logical address of the bit to be read.
status : Far pointer on the system status word.
Feedback
When the status is STATUS_OK, the bit value is entered in the least significant bit ;
Bits numbers 1..15 are set to zero.
A bit number outside these limits produces the status value OUT_OF_BOUNDS.
Examples
//Reading system bit %S4
___________________________________________________________________________
52
System functions
Description
Writes system bit %Si identified by its number.
The consistency of the bit number is checked.
Input parameters
sysbit_range : Logical address of the bit to be written.
value : Value to be written ; only the least significant bit is taken into
account.
Feedback
The bit write report.
This is STATUS_OK when the write operation is accepted by the system.
A bit number outside these limits produces the status value OUT_OF_BOUNDS.
Examples
//Writing value 0 in system bit %S10
___________________________________________________________________________
53
System functions
Description
Reads system word %SWi identified by its number.
The consistency of the word number is checked.
Input parameters
sysword_range : Logical address of the word to be read.
status : Far pointer on the system status word.
Feedback
When the status is STATUS_OK, the word value is entered in the function feedback
value.
A word number outside these limits produces the status value OUT_OF_BOUNDS.
Examples
//Reading system word %SW48 (event number)
___________________________________________________________________________
54
System functions
Description
Writes system word %SWi identified by its number.
The consistency of the word number is checked.
Input parameters
sysword_range : Logical address of the word to be written.
value : Value to be written.
Feedback
STATUS_OK when the write operation is successful.
A word number outside these limits produces the status value OUT_OF_BOUNDS.
Examples
//Writing value 10 in system word %SW48
___________________________________________________________________________
55
System functions
Description
Reads a bit from the forceable memory identified by its address. The bits in the forceable
memory are : %Si, %Mi, %Xi, %Ii.j and %Qi.j.
Input parameters
address : Address of the bit to be read, type adrFBIT (see section 6.1-1).
Feedback
The attributes of the referenced bit, conforming to the structure of the forceable bit
memory.
V : Value
H : Historic
F : Forcing
V : Value
H : Historic
F : Forcing (local)
r.F. : Remote forcing
R. : Fallback value
ER : Fallback state only significant for I/O bits
VR : Fallback validation (Ii,j ; Qi,j)
Def. : Fault
___________________________________________________________________________
56
System functions
Examples
___________________________________________________________________________
57
System functions
Description
Reads several consecutive bits in the forceable memory.
Input parameters
address : Address of the first bit to be read, type adrFBIT (see section 6.1-1).
number : Number of bits to be read, the length cannot exceed 32 bits.
status : Far pointer on the system status word.
Feedback
The value of the referenced bit string.
The function will not perform any processing if the number of bits requested is greater
than 32.
status is then INVALID_LENGTH.
Examples
___________________________________________________________________________
58
System functions
Description
Writes consecutive bits of the forceable memory ; the function can be used to write up
to 32 bits located at the address provided on input.
Input parameters
address : Address of the first forceable bit to be written, type adrFBIT (see section
6.1-1).
number : Number of bits to be written ; this value must not exceed 32.
value : Values to be written to a double word.
type : Type of write operation to perform :
00h : DATA_WRITE : update values
04h : RVALUE_WRITE : write the fallback value
06h : RVALID_WRITE : write the fallback validation field
07h : DEFAULT_WRITE : write the fault to specified values
08h : global unforcing of bits (UNFORCE_ALL) : the «value» parameter is
not therefore significant
Feedback
The write report : STATUS_OK if the operation is successful.
The function will not perform any processing if the number of bits to be written is greater
than 32.
The function then returns INVALID_LENGTH.
The system returns UNAVAILABLE_SERVICE if it does not recognize the type of action
to be performed.
___________________________________________________________________________
59
System functions
Examples
void far pascal FUNCTION(adrFBIT BitAddress)
{
unsigned short Status;
:
:
Status = wr_bits (AdresseBit,17,0x194AC,DATA_WRITE);
:
:
}
___________________________________________________________________________
60
System functions
Description
Reads the value (data bit) of 16 consecutive bits in the forceable bit memory.
The EF using this utility must ensure the validity of the address which has become a
parameter ; the system does not check that the address refers to the PLC forceable bit
space, nor that the 16 bits are in this space.
Input parameters
address : Address of the first bit to be read, type adrFBIT (see section 6.1-1).
Feedback
The value of the referenced bit string.
Examples
void far pascal FUNCTION(adrFBIT BitAddress)
{
unsigned short Valeur;
:
:
Valeur = rd_16bits (AdresseBit);
:
:
}
___________________________________________________________________________
61
System functions
adrFBIT address
unsigned short value
Description
Writes the value of 16 consecutive bits of the forceable memory.
As the system does not perform any checks, the EF using this utility must ensure the
validity of the 16-bit address which has become a parameter.
Input parameters
address : Address of the first forceable bit to be written, type adrFBIT (see section
6.1-1).
value : Values to be written to a word.
Feedback
None
Examples
void far pascal FUNCTION(adrFBIT BitAddress)
{
:
:
wr_16bits (AdresseBit,0xAFC1);
:
:
}
___________________________________________________________________________
62
System functions
Description
Reads the value (data bit) of a forceable bit.
The EF using this utility must ensure the validity of the address which has become a
parameter ; the system does not check that this is included in the PLC forceable bit
space.
Input parameters
address : Address of the bit to be read, type adrFBIT (see section 6.1-1).
Feedback
The value of the referenced bit (0 or 1).
Examples
void far pascal FUNCTION(adrFBIT BitAddress)
{
unsigned short Valeur;
:
:
Valeur = rd_1bit (AdresseBit);
:
:
}
___________________________________________________________________________
63
System functions
adrFBIT address
unsigned short value
Description
Writes the value of a forceable bit.
As the system does not perform any checks, the EF using this utility must ensure the
validity of the address of the bit which has become a parameter.
Input parameters
address : Address of the forceable bit to be written, type adrFBIT (see section
6.1-1).
value : Values to be written to a word : this is 0 or 1.
Feedback
None
Examples
void far pascal FUNCTION(adrFBIT BitAddress)
{
:
:
wr_1bit (AdresseBit,0);
:
:
}
___________________________________________________________________________
64
System functions
Description
This function determines a physical address from a logical reference in the format
selector : offset .
Input parameters
address : Logical address, type PTR_LOG, to be converted to a 32-bit physical
pointer (see section 6.1-1).
Feedback
The far pointer corresponding to the logical address provided on input.
In the event of failure (logical address not valid for this configuration), the function returns
INVALID_ADDRESS.
Examples
//Converting a logical address type adrTABLE to a physical address
void far* CalculAdrPhy(adrTABLE far* pwTable)
{
PTR_LOG SLog;
SLog.sel = pwTable->selecteur;
SLog.off = (unsigned short near *)pwTable->offset;
return(phy_ptr_init(SLog));
}
___________________________________________________________________________
65
System functions
Description
Reads the current PLC date and time.
The data is coded in BCD on 9 usable bytes (ie. 18 digits), in the format below.
Leap years can be handled.
x x x x x x x x x x x x x x x x x x
Input parameters
date_ptr : A far pointer on the current date and time copy zone (9 bytes). The
DATA_TIME type is described in section 6.1-1
Feedback
The function returns CLOCK_UNAVAILABLE if it has not been able to update the result
zone (difficulty in accessing the realtime clock).
If the operation is successful (the date and time fields are filled in correctly), the status
is STATUS_OK.
The PLC responds with CLOCK_NOT_SUPPORTED if it has no realtime clock.
___________________________________________________________________________
66
System functions
Examples
DATE_TIME Buffer;
Status = date_and_time(&Buffer);
___________________________________________________________________________
67
System functions
Description
The system reads the value of an internal counter with a timebase of 100ms.
Input parameters
None
Feedback
The value of the counter, which has the following characteristics :
• unsigned value, from 0 to 4 294 967 295
• reset to zero on cold restart and when system bit %S0 is set to 1
• not incremented during power outages
___________________________________________________________________________
68
System functions
Description
System counter with a timebase of 10ms.
Input parameters
None
Feedback
The value of the counter, which has the following characteristics :
• unsigned value, from 0 to 4 294 967 295
• reset to zero on cold restart only
• not incremented during power outages
___________________________________________________________________________
69
System functions
PROC_IDENT info
Description
Identifies the type of processor executing the application.
Input parameters
None
Feedback
A structure type PROC_IDENT (see section 6.1-1) containing various identification
data :
• the processor range on one byte :
04h : TSX37
05h : TSX57
• the SMART software version on the processor, on one byte :
- on the high order 4-bit byte, the version number
- on the low order 4-bit byte, the revision number (release)
• the CPU model catalog reference code on one word :
01h : REFCAT_TSX37_10
02h : REFCAT_TSX37_21
03h : REFCAT_TSX37_22
01h : REFCAT_TSX57_10
02h : REFCAT_TSX57_20
Examples
PROC_IDENT Info;
Info = proc_type( );
___________________________________________________________________________
70
System functions
PROC_INDIC info
Description
Information about the application memory configuration in the PLC.
Input parameters
None
Feedback
A structure type PROC_INDIC (see section 6.1-1) containing information about :
• the PLC status :
- in Run, reserved, in Breakpoint stop, in Halt, in partial Run.
• the validity of the application
• the presence of a memory cartridge (if applicable)
• the type of application memory : non modifiable / modifiable
Examples
PROC_INDIC Info;
Info = proc_indic( );
___________________________________________________________________________
71
System functions
___________________________________________________________________________
72
Appendix8
Section
8 Appendix
8.1 Example
The following example gives the procedure to follow in order to create an EF which will
extract the maximum value from a word table.
___________________________________________________________________________
73
Appendix
___________________________________________________________________________
74
Appendix
The part above the dotted line is the common part of the C source code, and is
automatically inserted by the tool.
The part below the dotted line represents the body of C source code, entered or imported
by the user (only the beginning is visible on this screen, the whole code is described on
the next two pages).
___________________________________________________________________________
75
Appendix
EF C source 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>
Header
#include <Fctsyst.h>
#include <C:\ASAWTEMP\SDKC\CLASSE01.H>
#include <C:\ASAWTEMP\SDKC\MAIN0101.H>
void far pascal MAX_TABW(
adrTABLE TAB,
adrSCAL MAX)
//PL7SDK_END_FUNCTION_NAME
{
adrTABLE far *pwTable=&TAB; /* table logical address structure pointer*/
short far *pcPhyTable; /* word table physical address pointer*/
short Resultat= TABLEVIDEMAX_ARW; /* init function result */
short TailleTab;
short I;
short far* pResultat;
PTR_LOG SLog;
SLog.sel = MAX.selecteur;
SLog.off = (unsigned short near *)MAX.offset;
pResultat = phy_ptr_init(SLog);
/* calculate the physical address of the input table and the size of the table*/
pcPhyTable = CalculAdrPhy(pwTable);
TailleTab = LimTableOk(pwTable);
/* if address is incorrect
or if the length of the table is zero
or if the length of the table is greater than LGMAXTBWORD)
increase S20 and set result ‡ TABLEVIDE (done on init)*/
if (((DWORD)pcPhyTable == NILL)||(TailleTab == 0))
{
SetS20();
}
/* if not */
else
{
/* search */
Resultat=*pcPhyTable;
for (I=PREMELEMENT;I<TailleTab;I++)
___________________________________________________________________________
76
Appendix
{
if (*pcPhyTable>Resultat)
{
Resultat=*pcPhyTable;
}
pcPhyTable++;
}
}
/* fsi*/
*pResultat= Resultat;
}
___________________________________________________________________________
77
Appendix
To generate the installation diskette, first select Customize from the Utilities menu, to
set the parameters for the destination path.
Generate Release will copy the files required to install the family in the PL7 library onto
the diskette in drive A:.
On the client station, insert the diskette in the drive, launch the SETUP.EXE file and
follow the installation procedure.
___________________________________________________________________________
78