Adding an Algorithm to a Basic Function Block Type

You can add an algorithm to a basic FB type with the New item of the popup menu of the Algorithms node in the Navigation tree.

Deleting an Algorithm

You can delete an algorithm by:
  1. Deleting all references to the algorithm in EC actions, then
  2. Using the Delete item of the algorithm's node in the Navigation tree (this item will only be present if the Algorithm has been removed from all EC Actions).

Editing with the Algorithm Dialog

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 an existing algorithm in the Navigation tree or clicking the Edit item of its popup menu, or by selecting the New Algorithm item of the Algorithms popup menu in the Navigation tree. 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 text area for editing algorithms in the ST or Java languages (algorithms in the LD or FBD languages are edited in the Worksheet area)
  • Buttons and text fields for performing find/replace operations in the text 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.

Editing ST Algorithms

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.
The FBDK performs a token-wise conversion of ST algorithms to Java using regular expressions with minimal parsing of the ST source text. As a result, only a subset of the IEC 61131-3 ST syntax is supported. Limitations include:
  • Each source statement must be on a separate line, for instance the contents of a FOR loop must be on a separate line from END_FOR.
  • Non-base 10 literals (except for base 16 literals, e.g., 16#FE) and literals of type TIME, STRING and WSTRING may not be correctly translated from IEC 61131-3 syntax to Java. This can be overcome by using variables that are initialized to the desired constant values outside of the ST algorithm.
  • The ST constructs WHILE...DO...END_WHILE and CASE are not supported.

Editing Java® Algorithms

You can write algorithms in the Java programming language as shown at right.
  • 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.
  • See the X2Y2_J and X2Y2_J2 function block types in the student subdirectory for further details.
To avoid namespace conflicts, don't use words in Java literals (double-quoted strings) that are the same as names of variables, events, etc. For instance, if you have an input variable named QI, don't have a statement in your Java program such as
OUT.value = "QI"+"1";
However, it would be OK to say
OUT.value = "QI1";
because here QI is only part of the full word QI1.
Last updated: 2011-02-11.
©2011 Holobloc Inc.
Licensed under the Academic Free License version 3.0.
Java is a registered trademarks of Oracle Corporation.