Word (endianness) & Byte-Swapping
Word-Swappiong (endianness) & Byte-swapping in Modbus
Introduction
Across various brand and utilization of the Modbus protocol, endianness and byte-swapping has been introduced. To better support the variations across Modbus, SIA Connect allows you to configure the reading of Modbus registers. A register has the size of a single word, 2 bytes.
Quick overview
Below tables gives you a brief overview of the swapping of words and bytes. Values encapsulated into [ ] symbolizes a register.
Word swapping
Big endian | Little endian (word swap) | Example |
---|---|---|
[ a b ] [ c d ] | [ c d ] [ a b ] | [ 0x12 0x34 ] [ 0x56 0x78 ] → [ 0x56 0x78 ] [ 0x12 0x34 ] |
Byte swapping
Non-swapped | Byte Swapped | Example |
---|---|---|
[ a b ] | [ b c ] | [ 0x12 0x34 ] → [ 0x34 0x12 ] |
Byte and Word swapping
Non-swapped | Byte and Word swapped | Example |
---|---|---|
[ a b ] [ c d ] | [ d c ] [ b a ] | [ 0x12 0x34 ] [ 0x56 0x78 ] → [ 0x78 0x56 ] [ 0x34 0x12 ] |
Word-Swapping (Endianness)
Endianness is applied when reading values that span across more than one register - eg. INT32, FLOAT, DWORD, etc.
You can choose between big endian and little endian.
Big endian | Little endian | ||||||||
---|---|---|---|---|---|---|---|---|---|
Example when reading 0x12345678 from 2 registers
|
Example when reading 0x1234 from 2 registers
|
Byte-Swapping
Byte-swapping is applied for each individual register being read. You can choose between First Byte High and First Byte Low
First byte high | First byte low | ||||||||
---|---|---|---|---|---|---|---|---|---|
Example when reading 0x1234 from 1 register
|
Example when reading 0x1234 from 1 register
|
Word & Byte swapping
Combining both word & byte swapping yield the below data formatting:
No swapping | First byte low | ||||||||
---|---|---|---|---|---|---|---|---|---|
Example when reading 0x12345678 from 2 registers
|
Example when reading 0x12345678 from 2 registers
|