Mapping a Device and a Function Block Instance

Overview

If supported by the device, you can map function blocks to an input or output channel. This allows you, for example, to count the frequency of signal changes or scale a channel value for maintenance purposes.

The following code example maps a device output channel to a function block. The function block scales the channel output value.

The following prerequisites must apply:

  • A device with an analog output of type INT that supports function block mapping is available in the project.

  • A function block Scale_Output_Int with the following implementation is available.

Consider the attributes of the function block itself and the attributes preceding the output parameter for processing the channel output.

{attribute 'io_function_block'}
FUNCTION_BLOCK Scale_Output_Int
VAR_INPUT
    iInput : INT;
    iNumerator : INT;
    iDenominator : INT :=1;
    iOffset : INT := 0;
END_VAR
VAR_OUTPUT
 {attribute 'io_function_block_mapping'}
    iOutput : INT;
END_VAR
VAR
END_VAR
IF iDenominator <> 0 THEN
    iOutput := TO_INT(TO_DINT(iInput) * TO_DINT(iNumerator) / TO_DINT(iDenominator)) + iOffset;

Procedure

To map a device and a function block instance, proceed as follows:

Step

Action

Comment

1

Open the <device name> I/O Mapping tab of the device editor.

2

Select the output you want to map to the function block.

3

Click the plus button .

Result: The Select Function Block dialog box opens. The left-hand side displays at least the function block Scale_Output_int below the Application node.

Libraries available in the project that contain the corresponding function blocks are also displayed for selection.

4

Select the function block Scale_Output_int and click OK.

Result: The path of the function block parameter iOutput is entered in the column Variable of the I/O mapping table.

5

Select the channel and click the Go to Instance button.

Result: The focus switches to the <device name> IEC Objects view and to the new entry.

The IEC Objects view in online mode displays the function block. You can write and force the value in this monitoring view.