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;
To map a device and a function block instance, proceed as follows:
Step |
Action |
Comment |
---|---|---|
1 |
Open the tab of the device editor. |
– |
2 |
Select the output you want to map to the function block. |
– |
3 |
Click the plus button |
Result: The Scale_Output_int below the node. dialog box opens. The left-hand side displays at least the function blockLibraries 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 . |
Result: The path of the function block parameter iOutput is entered in the column of the I/O mapping table. |
5 |
Select the channel and click the |
Result: The focus switches to the view and to the new entry. view in online mode displays the function block. You can |