Calculate the I/O offset of an expansion unit
This instruction calculates the relevant offset values of an expansion unit in the slot number specified by iSlot for accessing the input/output or unit memories via index modifiers.
Input
Slot number
Output
The starting I/O word number
The starting I/O word number multiplied by 16
Slot number minus 1
iSlot = 5 and starting word number = 16
Starting word number |
Corresponding address |
Application example |
Explanation |
---|---|---|---|
diOffset_WX0_WY0 = 16 |
DIX |
DIXWX1 or DIXWY1 |
Access to I/O word 1 of the unit in slot 5 |
diOffset_X0_Y0 = 16*16=256 |
DIY |
DIYX12 or DIYY12 |
Access to I/O bit hex 12 of the unit in slot 5 |
diOffset_S1 = 4 |
DI2 |
DI2S1:UM1A |
Access to unit memory word hex 1A of the unit in slot 5 |
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
iSlot: INT:=1;
bEnable: BOOL:=FALSE;
wSlotFirstInputWord: WORD:=0;
bSlotFirstInputFlag: BOOL:=FALSE;
wSlotFirstUnitMemoryWord: WORD:=0;
bGetSlotFirstInputWord: BOOL:=FALSE;
bGetSlotFirstInputFlag: BOOL:=FALSE;
bGetSlotFirstMemoryWord: BOOL:=FALSE;
END_VAR
When the variable bEnable is set to TRUE, the function is carried out.
BODY
WORKSPACE
NETWORK_LIST_TYPE := NWTYPELD ;
ACTIVE_NETWORK := 0 ;
END_WORKSPACE
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 6 ;
NETWORK_BODY
B(B_F,FP_GET_UNIT_OFFSETS1!,,17,0,30,6,,?DEN?DiSlot?AENO?AdiOffset_WX0_WY0?AdiOffset_X0_Y0?AdiOffset_S1);
B(B_VARIN,,iSlot,15,2,17,4,);
B(B_VAROUT,,DIX,30,2,32,4,);
B(B_VAROUT,,DIY,30,3,32,5,);
B(B_VAROUT,,DI2,30,4,32,6,);
B(B_CONTACT,,bEnable,6,1,8,3,);
L(1,2,6,2);
L(8,2,17,2);
L(1,0,1,6);
END_NETWORK_BODY
END_NET_WORK
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 4 ;
NETWORK_BODY
B(B_F,E_MOVE!,,17,0,23,4,,?DEN?D?AENO?C);
B(B_VARIN,,DIXWX0,15,2,17,4,);
B(B_VAROUT,,wSlotFirstInputWord,23,2,25,4,);
B(B_CONTACT,,bGetSlotFirstInputWord,6,1,8,3,);
L(8,2,17,2);
L(1,2,6,2);
L(1,0,1,4);
END_NETWORK_BODY
END_NET_WORK
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 4 ;
NETWORK_BODY
B(B_F,E_MOVE!,,17,0,23,4,,?DEN?D?AENO?C);
B(B_VARIN,,DIYX0,15,2,17,4,);
B(B_VAROUT,,bSlotFirstInputFlag,23,2,25,4,);
B(B_CONTACT,,bGetSlotFirstInputFlag,6,1,8,3,);
L(8,2,17,2);
L(1,2,6,2);
L(1,0,1,4);
END_NETWORK_BODY
END_NET_WORK
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 4 ;
NETWORK_BODY
B(B_F,E_MOVE!,,17,0,23,4,,?DEN?D?AENO?C);
B(B_VARIN,,DI2S1:UM0,15,2,17,4,);
B(B_VAROUT,,wSlotFirstUnitMemoryWord,23,2,25,4,);
B(B_CONTACT,,bGetSlotFirstMemoryWord,6,1,8,3,);
L(8,2,17,2);
L(1,2,6,2);
L(1,0,1,4);
END_NETWORK_BODY
END_NET_WORK
END_BODY
if (bEnable) then
FP_GET_UNIT_OFFSETS1(iSlot := iSlot,
diOffset_WX0_WY0 => DIX,
diOffset_X0_Y0 => DIY,
diOffset_S1 => DI2);
end_if;
if (bGetSlotFirstInputWord) then
wSlotFirstInputWord := DIXWX0;
end_if;
if (bGetSlotFirstInputFlag) then
bSlotFirstInputFlag := DIYX0;
end_if;
if (bGetSlotFirstMemoryWord) then
wSlotFirstUnitMemoryWord := DI2S1:UM0;
end_if;