Build and Test a Function

You can build custom functions for use in the functional programming of FBD algorithms in Basic function block types. Such functions do not themselves produce compilable code; rather, they serve as templates for the production of compilable code when they are used in FBD algorithms.

  1. Start the FBDK.
  2. Import library elements if and as needed.
  3. Create a new function type in the editor by double-clicking on the Function element of the template folder in the Library Navigator.
  4. Edit the function's elements:
    • Edit the function type's name and comment by double-clicking on the root node of the Element Navigator.
    • Edit the function type's properties by double-clicking on the corresponding entry in the Element Navigator:
    • Edit the function type's interface.
      • Make sure that the function only has a single output, named OUT.
    • Enter the functional expression to be evaluated.
      • In the Compiler Info classdef field, enter a parenthesized expression in the IEC 61131-3 ST language, expressing the value of OUT in terms of the function's input variables. Each usage of an input variable name should be set off with a blank space, for instance
        ( IN1 + IN2 ) or (( X + Y )*( X - Y )).
  5. When your editing is complete, save your work with the Save As...=>XML dialog.
    It is a good idea to save your work from time to time while editing, too!
  6. You can't save this element as a Java® file - It's used as a template for code generation in FBD algorithms.
  7. Since this element doesn't generate code, it can't be tested by itself, but only as part of an FBD algorithm of a Basic FB Type. See X2Y2_FN and X2Y2_FN_FBD in the FBDK's src/student folder for an example.