Function to calculate the I/O offset of an analog expansion unit connected directly to the CPU (without adapter).
I/O starting addresses vary, depending on the installation position of the expansion unit. The function block calculates the I/O word offset based on the unit position relative to the CPU.
Input
Set the position of the FP0/FP0R expansion unit relative to the CPU.
Values: 1 to 3
Output
Returns the offset of the I/O word (WX/WY2, 4, or 6)
All input and output variables used for programming this function have been declared in the POU header. The same POU header is used for all programming languages.
VAR
Inst_FP0R_A21: Unit_AnalogInOut_FP0R_A21;
iAnalogOut0: INT:=0;
bIO_Config_done: BOOL:=FALSE;
iAnalogIn0: INT:=0;
iAnalogIn1: INT:=0;
END_VAR
The function converts the position number (1 to 3) of the FP0/FP0R expansion unit, where 0 is the CPU, to the corresponding I/O word offset 2, 4, or 6.
BODY
WORKSPACE
NETWORK_LIST_TYPE := NWTYPELD ;
END_WORKSPACE
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 8 ;
NETWORK_BODY
B(B_VARIN,,1,9,2,11,4,);
B(B_F,ExpansionUnitNumberToIOWordOffset_FP0!,,11,1,31,4,,?DiExpansionUnitNumber?C);
B(B_FB,Unit_AnalogInOut_FP0R_A21!,Inst_FP0R_A21,35,1,50,8,,?BiIOWordOffset?BiOutChannel0?BiOutChannel0_Config?BiInChannel0_Config?BiInChannel1_Config?CbConfigIsDone?CiInChannel0?CiInChannel1);
B(B_VAROUT,,bIO_Config_done,50,2,52,4,);
B(B_VARIN,,iAnalogOut0,33,3,35,5,);
B(B_VAROUT,,iAnalogIn0,50,3,52,5,);
B(B_VARIN,,0,33,4,35,6,);
B(B_VAROUT,,iAnalogIn1,50,4,52,6,);
B(B_VARIN,,0,33,5,35,7,);
B(B_VARIN,,0,33,6,35,8,);
L(1,0,1,8);
L(31,3,35,3);
END_NETWORK_BODY
END_NET_WORK
END_BODY
Inst_FP0R_A21(iIOWordOffset := ExpansionUnitNumberToIOWordOffset_FP0(1),
iOutChannel0 := iAnalogOut0,
iOutChannel0_Config := 3,
iInChannel0_Config := 0,
iInChannel1_Config := 0,
bConfigIsDone => bIO_Config_done,
iInChannel0 => iAnalogIn0,
iInChannel1 => iAnalogIn1);