If supported by the device, you can map entire function blocks to an input or output channel. This allows you to count the frequency of signal changes or scale a channel value for maintenance purposes, for example.
Here you will map a device output channel to a function block. In this example, the block scales the channel output value.
Requirement: A device with a digital output that supports FB mapping is linked in the project. There is a function block “Scale_Output_Int” with the following implementation. The attributes of the function block itself and before the output parameter with which the channel output is processed are important.
{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;
-
Open the ⮫ I/O Mapping tab of the device module. Double-click the output that should be connected to the function block. Click the
“Add FB for IO channel” button.
The “Select Function Block” dialog opens. On the left side, you see at least the function block “Scale_Output_int” below the “Application” node. Libraries linked in the project that contain corresponding function blocks are also displayed for selection.
-
Select the POU
myScaleOutputInt
.After clicking “OK”, the path of the function block parameter
iOutput
in the “Variable” is entered in the mapping dialog. The path comprises the application name, the device channel name, and the selected FB output (example:App1.Out_4_Int_myScale_Output_Int_1.iOutput
). -
Select the channel and click the
“Go to Instance” button.
The focus switches to the “<device name> IEC Objects” tab and the created entry for the new IEC object
Out_4_Int_myScale_Output_Int_1
. In this view in online mode, you see the current value of the parameteriOutput
for the channelOut_4_Int
scaled by the FB. You can also write and force the value as in other monitoring views.
For more information, see: ⮫ “Tab: '<device name> IEC Objects ” and ⮫ “Attribute: io_function_block, io_function_block_mapping ”