You can add an algorithm to a basic FB type with the New
item of the popup menu of the basic FB type's ECC (Execution Control Chart).
You can delete an algorithm by:
- Deleting all references to the algorithm in EC actions, then
- Using the Delete item of the algorithm's dialog (see
below).
You can use this dialog both for adding a new algorithm to a
basic FB type or for editing an existing algorithm. You invoke it by
double-clicking the name of an existing algorithm in the Navigation
area, or by selecting the New Algorithm item of the ECC popup menu. The dialog
contains:
- Text fields for entering a name and comment for the algorithm
- A set of radio buttons for selecting the language in which the
algorithm is programmed
- A Delete button for deleting the algorithm from the
basic FB type (this button is enabled only when the algorithm is not
referenced by any of the EC actions)
- A text area for editing algorithms in the ST or Java
languages (algorithms in the LD or FBD languages are edited in the
Worksheet area)

If you use the radio buttons to change languages, you will see
different results depending on the original and new language selections:
- If the original algorithm is empty (i.e., the text pane is
empty for ST and Java, or the FBD contains no
function blocks, or the LD contains no rungs), the new language
will be selected immediately.
- If the original algorithm is non-empty:
- If the new language is FBD, LD or ST, or
the new language is Java and the old language is FBD, a
dialog box will appear asking if you want to replace the original
algorithm by an empty algorithm in the new language.
- If the new language is Java and the old language is LD
or ST, a dialog box will appear asking if you want to generate
the Java equivalent of the old algorithm.
This
conversion is one-way: if you generate the Java you cannot go back to
the old algorithm except by starting over with an empty algorithm.
- If the new language is ST or Java, the text area
will appear for editing the algorithm; for FBD and LD the
text area will disappear since these algorithms will be edited
graphically.
You can save the changes to the algorithm by pressing the "OK"
button, and if no errors are detected, the requested changes (if any)
will be made and the dialog will close. If you changed the name of an
existing algorithm, references to the algorithm in EC actions will be
automatically updated to the new name.
If an error is detected when you press the "OK" button, the
dialog does not close, the system "beeps" and an error message appears
at the top line of the dialog in the same manner as for EC states.
You can close the dialog without making any changes to the
algorithm by pressing the "Cancel" button or the
in the upper right corner of the dialog.
The figure above illustrates an algorithm
written in the IEC 61131-3 Structured Text (ST) language. You do not
need to enter the block delimiters ALGORITHM STOP IN
ST...END_ALGORITHM.
You can write algorithms in the Java programming language as
shown below.
- The delimiters of the Java method declaration are
automatically generated and should not be included in the algorithm.
These include the opening delimeter "public void alg_<ANAME>(){"
where <ANAME> is the name of the algorithm, and the
closing curly bracket "}".
- Reference to the values of the variables contained in the
function block instance is of the form X.value, where X
is the name of the variable.
|
 |
| An algorithm may be written in Java without an ECC; in this
case the name of the algorithm must be the same as the name of the
associated input event, and appropriate output events must be
generated as part of the algorithm as illustrated below.
See the X2Y2_J and X2Y2_J2 function block types in
the student subdirectory for further details of these
examples. |
 |
Last updated: 2006-09-23.
©2006 Holobloc
Inc. All rights reserved.