Troubleshooting
Why a Modbus write to CLICK PLC DS1 needs address 0
Short answer
A Modbus RTU write to CLICK PLC DS1 must carry register address 0x0000, not the bytes of the printed reference. The leading 4 is the holding-register table prefix, the remaining one-based number loses one on the wire, so register 1 travels as 0x0000; correct the address bytes, then recalculate the CRC over the six message bytes.
On this page
- Which register address reaches CLICK DS1 on the wire?
- Why does splitting the reference into two bytes pick a register the CLICK does not have?
- Do 40001 and 400001 select different registers?
- What bytes should the corrected write carry?
- How do you prove the PLC actually took the write?
- What must match before you blame the address again?
- What is the decision, and what stays out of the code?
- Questions asked
The write fails because the frame carries a printed reference where the PLC expects a wire address. To set DS1 on a CLICK PLC at station 2 over Modbus RTU from your PC, send function 06 with the two register-address bytes at zero and a CRC computed over those six message bytes. Both reference spellings you have been juggling name the same register: the leading 4 picks the holding-register table, the number after it is one-based, and the wire field is that number minus one, so register 1 travels as 0x0000. Below is the conversion, the corrected frame byte by byte, the check that proves the PLC accepted the write, and the settings to rule out if it still stays silent.
Which register address reaches CLICK DS1 on the wire? #
Send the two address bytes as 00 00: CLICK DS1 is holding register 1, so the printed reference 40001 or 400001 reduces to the one-based number 1 once the table digit 4 is dropped, and the RTU wire address is that number minus one, which is 0.
Modbus references have two layers. The application layer spells a holding register as a table digit plus a one-based number, which is the 4xxxxx notation printed in PLC documentation. The protocol layer carries only a 16-bit, zero-based offset, and the function code already tells the slave which table you mean, so the table digit is never transmitted. The Modbus application protocol specification fixes that address field at two bytes for the read and write functions alike, zero-based.
The CLICK follows the convention. Its documentation lists the DS registers under the holding-register table in six-digit form, so DS1 prints as 400001; a five-digit document would print the same register as 40001. When the CLICK itself is the master, its MODBUS RTU send instruction accepts CLICK addressing with an Address Picker that does the conversion for you. When your PC is the master, nothing converts the reference except your code.
Why does splitting the reference into two bytes pick a register the CLICK does not have? #
Dividing the reference by 256 puts 156 and 65 into the address bytes, so the frame asks for wire address 0x9C41, which sits far outside the CLICK's DS map, and the PLC answers with a Modbus exception instead of writing DS1.
Your existing code derives the address bytes from the reference itself. 40001 / 256 evaluates to 156.25, CByte rounds that to 156, and 40001 Mod 256 leaves 65. Recombined, 156 × 256 + 65 = 40001, so the address bytes on the wire are 9C 41, and the slave is asked for offset 40001, a position no CLICK DS register occupies.
Two tempting fixes do nothing. Swapping in the six-digit spelling changes the digit you feed the arithmetic but not the principle: a table digit is typography, not address data, so divide-and-modulo manufactures a bad offset from either spelling. Recomputing the CRC over unchanged bytes changes nothing either, because the check authenticates the bytes in transit, and a valid check over wrong bytes still selects a register the PLC does not have. Correct the address first; the check follows.
A request for an offset the server cannot map comes back as exception 02, illegal data address — the same decode covered in Modbus exception 02 when a read crosses a register map gap.
Do 40001 and 400001 select different registers? #
No — both spellings name the first holding register, so both convert to wire address 0 on this PLC; the digit count is a documentation convention, and the six-digit form exists for devices whose register tables run past five digits, not for a wider wire field.
| What you are looking at | Written as | What it becomes on the wire |
|---|---|---|
| Six-digit reference | 400001 | Address 0x0000 |
| Five-digit reference | 40001 | The same address |
| One-based register number | 1 | 1 - 1 = 0 |
| CLICK memory name | DS1 | The register that address 0x0000 writes |
The two-byte wire field counts 0 through 65535 within one table, so its width has nothing to do with how many digits a reference prints. The CLICK keeps one register map across its ports, and reading a CLICK PLC float over Modbus TCP in an HMI walks the same DS-to-offset conversion from the Ethernet side. Your CPU model's memory map decides which offsets beyond DS1 exist; anything outside it is exception territory, not spare memory.
What bytes should the corrected write carry? #
The corrected request is eight bytes: slave 02, function 06, address bytes 00 00, value bytes 00 00, then check bytes 89 F9 with the low byte first, which makes the complete frame 02 06 00 00 00 00 89 F9.
| Array slot | Byte | Purpose |
|---|---|---|
| frame(0) | 02 | Slave (station) address |
| frame(1) | 06 | Write single holding register |
| frame(2) | 00 | DS1 address, high byte |
| frame(3) | 00 | DS1 address, low byte |
| frame(4) | 00 | Value, high byte |
| frame(5) | 00 | Value, low byte |
| frame(6) | 89 | Check byte, low, transmitted first |
| frame(7) | F9 | Check byte, high |
Worked example — station 2, DS1, value 0:
- Convert the register: DS1 is the first holding register, the one-based number after the table digit is 1, and 1 - 1 = 0, so the address bytes are 00 00.
- Assemble the six message bytes: slave 02, function 06, address 00 00, value 00 00.
- Compute the RTU check over exactly those six bytes — start from 0xFFFF, process each byte lowest bit first through the polynomial 0xA001 — and the computation returns 0xF989; RTU transmits the low byte of the check first, so the final two bytes are 89 F9.
- Send all eight bytes and read the response.
frame(0) = 2 ' slave (station) address
frame(1) = 6 ' function 06, write single holding register
frame(2) = 0 ' DS1 address, high byte
frame(3) = 0 ' DS1 address, low byte
frame(4) = 0 ' value, high byte
frame(5) = 0 ' value, low byte
' check over frame(0) through frame(5) computes to &HF989
frame(6) = &H89 ' check low byte, transmitted first
frame(7) = &HF9 ' check high byte
SerialPort1.Write(frame, 0, frame.Length)
Recalculate the check after every byte you change; a value carried over from the old frame validates old bytes, not new ones. Check the bounds inside CRC(frame) too: the name alone does not reveal whether the routine processes the six message bytes or the whole allocated array, and a check that walks trailing zeros is a check over a different message. For a value other than zero the layout holds unchanged, and the value also goes high byte first: 1234 decimal travels as 04 D2 in the value slots.
How do you prove the PLC actually took the write? #
A passing serial Write call only proves your program handed bytes to the port; proof of acceptance is the response, which for function 06 echoes the station address, the function code, the DS1 address field and the written value, each followed by its own check bytes.
| What comes back | What it means | Next move |
|---|---|---|
| Silence | Framing, station number, wiring or check bytes | Capture the line; re-derive the check over the six message bytes |
| Exception 02 | The offset is outside the map | Re-derive the offset for the register you meant |
| Echo arrives, DS1 still reads its old value | Program logic owns the register | Cross-reference DS1 for moves and initializations |
| DS1 zeroes out, then changes again | Another writer follows yours | Trace that writer before trusting the test |
Zero is weak evidence if DS1 already held zero. Where the process allows it, write a recognizable value instead — 1234 is 04 D2 on the wire — read it back with function 03 from the same offset, then restore the required value. Put the machine in a state where a changed DS1 cannot move anything first: if running logic reads DS1, your write ends up driving outputs through that logic, the channel examined in can a Modbus write change PLC outputs.
What must match before you blame the address again? #
If the corrected frame still fails, the address math is no longer the suspect: confirm the CLICK serial port runs Modbus RTU slave at your station number, match baud, parity, data bits and stop bits at both ends, and keep other masters off the same cable.
- Slave role and station number: the port protocol and station address are set in the PLC's serial configuration, and a request sent to station 0 is a broadcast no slave answers — the trap described in why Modbus RTU sends to slave address 0 instead of your device.
- Serial format: identical baud, parity, data bits and stop bits at both ends, with any converter's wiring checked against its own documentation.
- One master: stop other polling applications on the cable while you test, because RTU defines no arbitration between masters.
- Check-byte scope: the routine processes exactly the six message bytes, and runs again after every edited byte.
- Register ownership: cross-reference DS1 in the program for any rung that moves, copies or computes into it.
- One capture before automation: log the transmitted and received bytes of the first corrected exchange by hand, before polling loops or automatic retries go live.
What is the decision, and what stays out of the code? #
For your PC master the decision is final: transmit function 06 with the address field at zero and the value you want, compute the check over those six message bytes and nothing else, and never let a printed reference reach the address arithmetic.
The permanent repair is one conversion routine in your application: it takes the CLICK register, strips the table digit, subtracts one from the one-based number and returns the two wire bytes. Document for every field whether it expects a printed reference or a zero-based offset, because libraries differ — some accept printed-reference entries and convert internally, others want the raw offset, and doing the subtraction on top of the tool's own conversion sends offset 65535 instead, which no CLICK map fills.
Keep the corrected frame as a regression test: if a later edit changes any of the six message bytes, the stored check bytes no longer match, and the test fails loudly instead of writing to the wrong register. The same arithmetic applies when the master is a controller building frames itself — sending hex prefix bytes through a Studio 5000 MSG instruction is the same strip-the-prefix-then-subtract-one work on a different canvas. When the CLICK is the master, leave the conversion to its instruction setup, which takes CLICK addresses directly.
Questions asked
Why did communication work when the CLICK was the master?
Master-side traffic proves the CLICK can drive the port, not that it accepts requests. Your PC test exercises the other role, the slave side. The port's protocol setting and station number must match what the PC sends before any frame, corrected or not, earns a response.
My software has a zero-based addressing switch, which way do I set it?
Let exactly one side do the arithmetic. With the switch on, enter the wire offset 0 for DS1; with it off, enter the printed holding-register reference and let the software subtract the offset. Doing the subtraction yourself on top of the tool's own conversion sends offset 65535 instead, an entry of 0 minus one wraps in the 16-bit field, and that offset is almost certainly unmapped.
How do I write several DS registers in one request?
Use function 16, write multiple registers. The address rule is unchanged: DS1 is offset 0, DS2 is offset 1, and so on across the documented range. The byte-count and register-count fields must match the data you send, and a successful response echoes the first offset and the quantity rather than the data.
Does the same address rule apply to a CLICK over Modbus TCP?
Yes. The register address field means the same thing on both transports: DS1 is offset 0 whether the request arrives on the serial port or as Modbus TCP. The framing differs, since TCP wraps the same function code and address in an MBAP header and carries no check bytes, because Ethernet verification covers the frame instead.