Swap Register Bytes
easy
Reads a 16-bit register from a device that sends its high byte first.
What it teaches
A register is two bytes, and not every device stores them in the same order. A Siemens PLC or a Modbus device that sends the high byte first delivers 4660 (16#1234) as 13330 (16#3412). SWPB puts the bytes back: on an INT every order mode swaps the two bytes. It moves whole bytes, never decimal digits, so look at the value in hex to see what moved. Unlike Combine Two Registers, nothing is combined; one register is reordered.
Parameters
| Tag | Direction | Type | Default | Description |
|---|---|---|---|---|
| In_Raw | Input | INT | 13330 | Register as received, high byte first |
| Out_Value | Output | INT | 0 | The register's value in this controller's byte order |
Required behavior
- Every scan, Out_Value is In_Raw with its two bytes swapped: bits 8-15 of In_Raw become bits 0-7 of Out_Value, and bits 0-7 become bits 8-15.
- The device sends each register high byte first, so the number it means is the swapped one: 13330 (16#3412) means 4660 (16#1234).
- Swapping moves whole bytes, not decimal digits, and a result whose new top bit is set is negative: 12027 (16#2EFB) means -1234 (16#FB2E).
- With the default In_Raw of 13330, Out_Value is 4660.