en-us_guide:hmi_connection:studio2:modbus_addresses

MPINO STUDIO2 · Finding and Testing Modbus Addresses

HMI Connection · Connecting an HMI with Modbus RTU

An HMI or a PC reads and writes MPINO STUDIO2 memory through Modbus RTU addresses. This page works out the function code and address for a D register, one bit of a D register, a counter, a timer, and an R value, then tests an address from a PC before the HMI is involved. The complete address table is in Phase 7 · Modbus RTU Slave and LS Electric Cnet Slave Addresses.

The page applies to MPINO STUDIO2 V2.1.1 and later, with a channel set to Modbus RTU Slave under Run → Communication. You write no Modbus code in a STUDIO2 project: STUDIO2 builds the slave from those settings. The examples use an MPINO-⁠8A8R-⁠S, whose RS-485 port is Serial1, with station 1, 9600 bps, and 8N1.

1. Look up the address

The numbers are 0-based addresses in the request.

To do this Function code Address
Read D10 03 Read Holding Registers, quantity 1 2010
Write D10 06 Write Single Register, or 16 (0x10) Write Multiple Registers 2010
Read or write bit 0 of D10 (D10.0) 01 Read Coils, 05 Write Single Coil 2160
Read or write M0 01, 05 1000
Read the current value of counter C12 03 3012
Read the done contact of counter C12 01 3012
Read the elapsed count of timer T0 03 4000
Read the done contact of timer T0 01 4000
Read R0 (32-bit real number) 03, quantity 2 5000 (lower 16 bits) and 5001 (upper 16 bits)

The same rules give any other address:

Memory Holding register Coil
Dn 2000 + n Bit b of Dn: 2000 + 16 × n + b
Mn 1000 + w holds M bits 16 × w to 16 × w + 15 (1000 = M0 to M15) 1000 + n
Cn 3000 + n, current value 3000 + n, done contact
Tn 4000 + n, elapsed count 4000 + n, done contact
Rn 5000 + 2 × n (lower 16 bits), then the next address (upper 16 bits) -

For C and T, the holding register and the coil at the same address are different values: the register is the current count, and the coil is the done contact. A timer's count is in timer units (10 ms by default for T timers), not milliseconds. On the MPINO-⁠8A8R-⁠S, C0 to C11 are mapped to board functions (analog inputs, temperature inputs, and PWM outputs) in Settings → Ladder Pin Map Settings, so the counter examples start at C12.

These offsets apply to STUDIO2 projects only. A sketch written in Arduino IDE with the board package's Modbus built-in commands uses its own map: M is accessed as coils and D as holding registers, starting at the addresses set with ImodbusRTUAdr(). With ImodbusRTUAdr(0, 0), D[0] is holding register 0 and M[0] is coil 0.

2. See how a register and its bits line up

Holding register 2010 and coils 2160 to 2175 are the same memory. Write 1 to coil 2160 and D10 becomes 1. Write 300 to holding register 2010 and coils 2162, 2163, 2165, and 2168 read ON.

D10 = 300 shown as 16 coils: bits 2, 3, 5, and 8 are ON at coils 2162, 2163, 2165, and 2168

A single-coil write (function 05) changes only that bit of the D word. Writing a P or M holding register changes all 16 bits at once.

3. Enter the number your HMI driver expects

D10 is 2010 as a 0-based address, 2011 in a driver that counts from 1, and 42011 in five-digit 4xxxx notation. All three point at the same register. Check the address format explains how to tell which form your driver takes.

If you are not sure, write a distinctive number such as 1234 to D10 from the HMI and read it back from a PC as in section 5. If the value lands in D9 or D11, switch conventions.

4. Make the memory area large enough

The numbers under Settings → Memory Area Settings (Ctrl+Shift+M) are counts, not addresses. To use D10, D11, and D13, the D area needs at least 14 words (D0 to D13).

  • Reading an address beyond the memory size returns 0.
  • Writing to such an address returns exception 02 (Illegal Data Address), so a write that changed nothing shows up as an error.
  • If any address in a multi-address write cannot be written, nothing is written.

5. Test the address from a PC

A USB to RS-485 adapter and a command-line Modbus master such as mbpoll take the HMI out of the test. If these commands work, the controller side is done, and any remaining problem is in the HMI project.

Read D10 (holding register, address 2010):

mbpoll -m rtu -a 1 -b 9600 -P none -0 -t 4 -r 2010 -c 1 COM5

Write 300 to D10:

mbpoll -m rtu -a 1 -b 9600 -P none -0 -t 4 -r 2010 COM5 300

Read M0 to M7 (coils 1000 to 1007):

mbpoll -m rtu -a 1 -b 9600 -P none -0 -t 0 -r 1000 -c 8 COM5

Replace COM5 with your adapter's port. -0 makes mbpoll use 0-based addresses. -P none matters because mbpoll uses even parity by default.

On a bus analyzer, the frames look like this. 07 DA is 2010 in hexadecimal.

Read D10       request   01 03 07 DA 00 01 A4 85
               response  01 03 02 01 2C B8 09      (D10 = 0x012C = 300)
Write D10=300  request   01 06 07 DA 01 2C A9 08
               response  echoes the request

6. Match the HMI data format

  • D memory is a signed 16-bit WORD (−32,768 to 32,767). Choose a signed format in the HMI unless the value is used unsigned on purpose, such as a timer preset.
  • An R value is a 32-bit floating-point number in two registers, lower 16 bits first. Set the HMI's 32-bit word order to match.
  • Number display settings, byte swap, and switch and lamp targets are covered in Set up number displays and input.

7. Symptoms and where to look

Symptom Check first
A write is refused with exception 02 The address is beyond the memory size. Enlarge the area in section 4.
A register always reads 0 The address may be beyond the memory size. Reads there return 0 instead of an error.
A long block write gets no response A request longer than 63 bytes can overflow the 64-byte receive buffer, for example a function 16 write of 28 or more words. Split the request or enlarge the Serial RX Buffer.
An R value is meaningless The HMI's 32-bit word order. R sends the lower 16 bits first.

No response at all, values one register away, and values that disappear are covered in Where to look for each symptom. RS-485 polarity and termination are in RS-485 wiring.

en-us_guide/hmi_connection/studio2/modbus_addresses.txt · Last modified: by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki