How-to
How to Split Modbus Register Bytes in Operator Terminal Expert
Short answer
Create a variable of type USINT with array size 2 on each register: Operator Terminal Expert assigns the register's low and high byte addresses to the two elements. Rebuild a 16-bit field split across two registers as low byte + 256 × high byte into a UINT, and write it back by replacing only that field's bytes while preserving the neighbor in the shared register.
On this page
- How do I split a Modbus register into bytes without a PLC?
- Which array element is the high byte and which is the low byte?
- Does %MW1000 in the unit's map mean address 1000 in the driver?
- How do I rebuild a 16-bit value that spans two registers?
- How do I write one field without overwriting its neighbor?
- How do I reconstruct a 32-bit DWORD field?
- When should this conversion stay in a controller instead of the panel?
- Questions asked
Skip the PLC this time: the panel can do the byte packing itself. In Operator Terminal Expert, create one variable of type USINT with array size 2 for each register; the software assigns the register's low and high byte addresses to the two elements, so every byte in the control unit's map becomes an addressable variable. Fields that cross register boundaries are rebuilt with low byte + 256 × high byte, and writes go back as full registers that preserve the neighboring byte. The walk-through below uses the map %MW1000 to %MW1004, with 8-bit, 16-bit and 32-bit fields mixed together, which is the layout that breaks one-variable-per-register mapping.
How do I split a Modbus register into bytes without a PLC? #
Create a variable of type USINT with array size 2 and point it at the register: Operator Terminal Expert assigns the register's low and high byte addresses to the two elements, which turns every byte in the unit's map into an individually addressable variable. USINT is an 8-bit unsigned type holding 0 to 255, exactly the width of every packed field in this map. Set it up like this:
- In the variable configuration, create a variable of type USINT and set its array size to 2.
- Assign the array to the register through the Modbus RTU driver, the same way a whole-register variable targets it.
- Check the addresses the configuration shows for both elements: one lands on the register's low byte, the other on its high byte.
- Repeat per register; five arrays cover %MW1000 through %MW1004.
The software's variable documentation gives the VECTOR keyword for reaching array element values from logic. This exposes whole bytes, not single bits; when a map needs one bit out of a word, accessing one bit of a word in Operator Terminal Expert is the separate technique.
Which array element is the high byte and which is the low byte? #
Prove it with one register whose known value has two different bytes, then write the association down: the element order is set by the driver mapping, not by a convention you can assume, and two equal bytes can never reveal a reversal. Put both elements and the raw register value on one test screen, with a hexadecimal base where the display offers it, so the two bytes stay visible:
- Make the register hold a known value whose bytes differ; %MW1001 with Var3 = 3 and a Var4 low byte of 232 reads 256 × 3 + 232 = 1000, which is 0x03E8.
- The element showing 232 (E8) is that register's low byte and the element showing 3 (03) is the high byte; record the pairing.
- Repeat once on an adjacent register to confirm the array advanced a whole register, not a single byte.
On this map, leave any driver-level byte-swap option off: each field's low byte already sits in a register low-byte position and its high byte in a high-byte position, and a global swap reverses both bytes of every register on the connection, misaligning the rebuild. A swap is the right tool only for a device that is consistently byte-reversed, and it never moves a field across a register boundary.
Does %MW1000 in the unit's map mean address 1000 in the driver? #
Not until you confirm it: %MW1000 is the control unit's documentation label, and the driver may expect 1000, 999, or a holding-register base like 400001, so a wrong convention shifts every field by a whole register and no expression can repair that. Bring the raw register up before any expression work; a wrong device address, serial setting, register area or offset breaks every downstream value, and byte arithmetic cannot mask it. Decoding a Modbus holding register address such as 4500001 covers the conventions drivers use, so confirm which one yours follows, then:
- Display one whole register from the mapped area in hexadecimal.
- Compare it with a value known from the unit's documentation or an independent diagnostic.
- Adjust the address base until the raw value lands, and confirm it updates live without communication errors.
Byte-level work means nothing until that gate passes.
How do I rebuild a 16-bit value that spans two registers? #
Add the low byte to 256 times the high byte into a UINT variable: a low byte of 232 and a high byte of 3 reconstruct 232 + 256 × 3 = 1000, and any unsigned result from 0 to 65535 needs all 16 bits. The map resolves as follows:
| Field | Where it comes from |
|---|---|
| Var1, Var2 | the two elements of the %MW1000 array |
| Var3 | high-byte element of %MW1001 |
| Var4 | low byte of %MW1001 + 256 × high byte of %MW1002 |
| Var5 | low byte of %MW1002 + 256 × high byte of %MW1003 |
| Var6 | low-byte element of %MW1003 |
| Var7, Var8 | the two elements of the %MW1004 array |
Worked example, read side: the %MW1001 low-byte element reads 232 and the %MW1002 high-byte element reads 3, so:
Var4 = 232 + 256 × 3 = 232 + 768 = 1000
Give each rebuilt field a UINT destination covering 0 to 65535, and run the multiply and add in integer arithmetic at least 16 bits wide. Put the formula in the expression or scripting facilities of your installed version; the formulas above define the mapping, they are not literal software syntax. Verify against a known unit value above 255, such as 1000, because a test value with a zero high byte passes even when the reconstruction is wired wrong.
How do I write one field without overwriting its neighbor? #
Read the register, replace only the byte your field owns, and write the full register back: on %MW1002 a write to one field must carry the other field's current byte, or the write silently restores a stale value over it. %MW1002 holds the high byte of Var4 and the low byte of Var5, two fields in one register. Whether writing one array element transfers a single byte or the whole register depends on the driver, so prove the behavior once with a controlled test; composing the full register works either way. Writing an operator entry of 1000 on Var4:
- Split the entry: low byte = 1000 modulo 256 = 232, and high byte = 1000 ÷ 256 = 3 as the integer quotient; check it with 256 × 3 + 232 = 1000.
- Read the bytes to preserve: Var3 from the %MW1001 high element, and the current Var5 low byte from the %MW1002 low element, which reads 120 in this example.
- Compose the registers: %MW1001 = 256 × 3 + 232 = 1000, and %MW1002 = 256 × 3 + 120 = 768 + 120 = 888.
- Write both registers back to back, then read back; %MW1002 must return 888 with the Var5 low element still at 120.
Do the first write tests on registers whose bytes cannot command motion or a process output, or with the machine in a state where a wrong byte is harmless.
The race is real: if the unit changes that Var5 low byte to 200 between the read in step 2 and the write in step 3, the write restores 120, the panel's stale copy, and the unit's newer value is gone. Keep the read immediately before the write, and remember that Var4 itself is split across two registers, so the unit can observe a half-updated field between the two writes.
How do I reconstruct a 32-bit DWORD field? #
Weight its four bytes by 1, 256, 65536 and 16777216 from least to most significant into a UDINT, then verify the word order against a known value, because Modbus fixes the 16-bit register size, not the order of bytes inside a device's 32-bit fields. The map above does not locate the DWORD bytes, so take the four byte positions and their significance from the unit's own documentation before configuring anything. With the least significant byte first:
value = b0 × 1 + b1 × 256 + b2 × 65536 + b3 × 16777216
Bytes 232, 3, 1 and 0 give 232 + 768 + 65536 + 0 = 66536, into a UDINT destination covering 0 to 4294967295. Word order inside multi-register values is a device decision rather than a Modbus rule, and it is the first thing to question when a rebuilt 32-bit value is wildly wrong; displaying a PLC real value over Modbus on an HMI covers how word order changes what the panel receives.
When should this conversion stay in a controller instead of the panel? #
Keep it on the panel when the panel is the only master and the fields genuinely cross byte boundaries; move it back to a controller when another writer shares those registers, because the panel's read-modify-write has no lock protecting the shared bytes. Decide by who writes the registers and how the fields sit:
- Read-only screens: the array plus the expression is the whole job, so commit to it on the panel.
- Operator writes with the panel as the only master: the read-modify-write above holds, because nothing else can interleave on those registers.
- A second master, or unit firmware that rewrites the shared registers between the panel's read and write: move the packing into a controller or gate writes through a trigger the device owns, because the panel holds no lock on those bytes.
- A controller already in the line: keep the conversion there, where one program scan writes both registers coherently.
- Fields aligned to whole registers: skip packing entirely and map one UINT per register.
For the %MW1000 map, that decision lands as reads on the panel from five USINT arrays, writes on the panel while it stays the only master, and a controller the day a second writer appears.
Questions asked
Can the converters do this instead of an array variable?
No. A converter rescales one value into another range; it cannot pull one byte out of a register or join bytes from two different registers. The two-element USINT array is what gives each byte its own address, and the expression or script editor is where the 256-weighted arithmetic on those elements belongs.
How do I display a signed 16-bit field rebuilt from bytes?
Rebuild the unsigned value first, 0 to 65535, then apply the device's documented sign convention: for a signed field, subtract 65536 from any result of 32768 or more. A rebuilt 65500 then reads -36, and 40000 reads -25536. Keep the arithmetic in integer types wide enough to hold 65535 before the subtraction.
Do I create one array for all the registers or one per register?
One two-element array per register, five for %MW1000 through %MW1004. That keeps each element pair tied to the register you verified against its raw value, and it stops a byte from being attributed to the neighboring field when you later extend the map.
What if the control unit changes the shared byte while the panel is between its read and its write?
The panel writes back the byte it read, and the unit's newer value is lost. Mitigate by polling the shared registers as one contiguous block so both come from the same scan, and where the device offers a command trigger byte, write the data bytes first and the trigger last. If updates still outrun the panel, move the packing into a controller.