Block that rearranges the bytes of a variable.
Ladder Representation

Block Structure
Variable type |
Name |
Data type |
Description |
VAR_INPUT |
EN |
BOOL |
Block enabling |
Value |
WORD UINT INT DWORD UDINT DINT |
Input variable to be rearranged |
|
Type |
BYTE |
Variable that defines the conversion type according to Table 2 |
|
VAR_OUTPUT |
ENO |
BOOL |
End of operation |
Result |
BYTE USINT SINT WORD UINT INT DWORD UDINT DINT REAL(*) |
Output value |
Table 1. Block variables.
Type |
WORD UINT INT |
ENO |
DWORD UDINT DINT |
ENO |
0 |
AB->AB* |
TRUE |
ABCD->ABCD |
TRUE |
1 |
AB->BA |
TRUE |
ABCD->DCBA |
TRUE |
2 |
- |
FALSE |
ABCD->CDAB |
TRUE |
3 |
- |
FALSE |
ABCD->BADC |
TRUE |
4 ... |
- |
FALSE |
- |
FALSE |
Table 2. Conversion type (*characters A, B, C and D represents BYTES).
Operation
When this block has a TRUE value in EN, it rearranges the bytes from Value variable, storing the result in Result.
Type defines how the bytes will be rearranged, as shown in Table 2.
Note that for 16-bit variables, only options 0 and 1 are valid.
For 32-bit variables the options 0, 1, 2, and 3 are valid.
When EN has FALSE value, Result remains unchanged.
The ENO value forwards to the next Ladder block the EN value after the operation is completed. Invalid TYPE options assigns FALSE to ENO, and Result value is not changed.
|
NOTA! Caution when using in Result a variable of REAL type, because the block does not perform type conversion, that is, it only reverses the bytes in memory. |
Block Flowchart

Example in Ladder

The example rearranges the position of value VALUE_IN according to the type set in TYPE_IN = 1 (AB->BA), storing the final result in RESULT. The block ends with success and ENO output is activated.
Example in ST
The example below displays the instructions for applying the example above in the ST language.
VAR VALUE_IN : INT := 16#2501; TYPE_IN : BYTE := 1; RES_OUT : INT; END_VAR
RES_OUT := FB_SWAP2( EN:=DI1, Value:=VALUE_IN, Type:=TYPE_IN, ENO=>DO1);
|
|---|