Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
SYPT PRO User Guide / SYPT PRO User Guide.doc
Скачиваний:
244
Добавлен:
03.03.2016
Размер:
17.32 Mб
Скачать

Calling udfBs

The following show examples of different ways of calling function blocks.

The example shows that there are three ways of calling function blocks. Whichever way is used, values must be specified for all input arguments whenever a UDFB is called.

UDFB Call Format 1

(MyIntVal%, MyFloat) = _DemoArguments2(1)

When a UDFB is called in this way the actual output arguments are listed between brackets prior to the UDFB name. After the call, the variables inside the brackets will be updated with the output values from the function block. All the output arguments of the UDFB must be listed between the brackets.

UDFB Call Format 2

MyIntVal% = _DemoArguments2(2)

This way of calling a UDFB allows the caller to access the primary or first output argument from a function block and ignore the remaining outputs.

UDFB Call Format 3

_DemoArguments2(4)

This way of calling a UDFB allows the caller to ignore all outputs of a UDFB. This is also the format of a call to a UDFB which has no outputs at all.

Note:

UDFBs can be called from QLD and LD/ FB diagrams as well as from DPL.

See Also

  • UDFB Argument Restrictions

  • UDFB Code Sections

  • UDFB Instances

  • User-Defined Function Blocks (UDFBs)

  • Variables

  • Arrays

________________________________________________________________________________

Udfb Argument Restrictions

For the UD7X and MD29 option modules only, there is a restriction on the number of inputs and outputs for a UDFB. These modules also place restrictions on the order in which inputs and outputs can be specified.

The quantity of inputs and outputs is dependent upon the data types. The maximum is 10 integer inputs and 10 integer outputs.

Input and output arguments can be a mixture of integer and floating-point types. A floating-point input or output is the equivalent of two integer inputs or outputs, however there are restrictions governing the order of mixed integer and floating point inputs and outputs.

The basic rules are that a floating point variable on a UDFB input or output must either:

1. Be the first input or output.

2. Follow another floating point input or output.

3. Follow after two integer inputs or outputs.

From these rules, it can be seen that having one integer input followed immediately by a floating point input is illegal. SYPT will display the error "Bad alignment, insert an integer parameter before this one to fix alignment.".

See Also

  • User-Defined Function Blocks (UDFBs)

  • UDFB Input and Output Arguments

  • Calling UDFBs

________________________________________________________________________________

Udfb Instances

When a program makes a call to a UDFB an instance of the UDFB is created. When an instance is created an independent copy of the input arguments, output arguments and local variables for the UDFB are allocated. In DPL, function block instances are automatically created when calls to UDFBs are made in the code. In the following example two instances of _DemoArguments2 are created in the Background task because two calls are made to the UDFB.

The _DemoArguments2 UDFB contains the following data:

  • Out1%

  • Out2%

  • In1%

  • LocalVal%

These data occupy approximately 16 bytes of RAM. Each instance of _DemoArguments2 will add 16 bytes of RAM usage to the user program. In the above example two instances of _DemoArguments2 are created (in CALL 1 and CALL 2) so 32 bytes of RAM will be taken from the available target RAM. The 32 bytes will be statically allocated when the user program begins execution on a target and will only be released when the user program stops.

The local variables in each instance will be stored or remembered between each call to the instance. Each instance has independent copies of the local variables. The following example shows the effect of independent instances.

The two instances of _RunningTotal are completely independent so Val2% increments at twice the rate of Val1% - because the second call to _RunningTotal increments by 2 each time.

See Also

  • User-Defined Function Blocks (UDFBs)