Exchange higher bytes and lower bytes
This FP instruction exchanges the higher bytes with the lower bytes of all words within the data area specified by s_Start and n_Words if the trigger EN is TRUE. The result is transferred to d_Start.
Input
Starting address of the source data area
Number of words (1–65535, in case of 0 no operation is executed)
Output
Starting address of the destination data area
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
arrWordValues: ARRAY [0..7] OF WORD:=[8(16#88AA)];
arraWordValuesSwapped: ARRAY [0..7] OF WORD:=[8(0)];
bEnable: BOOL:=FALSE;
iNumberOfWords: INT:=8;
END_VAR
When the variable bEnable is set to TRUE, the function is executed.
BODY
WORKSPACE
NETWORK_LIST_TYPE := NWTYPELD ;
ACTIVE_NETWORK := 0 ;
END_WORKSPACE
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 5 ;
NETWORK_BODY
B(B_F,FP_SWAP_BYTES_BLOCK!,,15,0,28,5,,?DEN?Ds_Start?Dn_Words?AENO?Cd_Start);
B(B_VARIN,,arrWordValues[0],13,2,15,4,);
B(B_VARIN,,iNumberOfWords,13,3,15,5,);
B(B_VAROUT,,arraWordValuesSwapped[0],28,2,30,4,);
B(B_CONTACT,,bEnable,4,1,6,3,);
L(1,2,4,2);
L(6,2,15,2);
L(1,0,1,5);
END_NETWORK_BODY
END_NET_WORK
END_BODY
if (bEnable) then
FP_SWAP_BYTES_BLOCK(s_Start := arrWordValues[0],
n_Words := iNumberOfWords,
d_Start => arraWordValuesSwapped[0]);
END_IF;