IMDHMIControls LibraryShop main store

Troubleshooting

Why a CODESYS Modbus RTU query reads no data when Modbus Poll works

Industrial networks Published 8 min read By IMDHMI controls team

Short answer

A PC master that reads the registers proves the slave, its framing and its serial settings, so a CODESYS master that times out instead is failing on its own path. Trace the request across four hops: query, serial port, RS-485 cable, slave receiver. A timeout points at the middle two, an exception reply at the query parameters, and in the reported case a new RS-485 cable restored all ten registers.

On this page
  1. Read the failure signature before touching settings
  2. Test the RS-485 cable and its terminators
  3. Match the serial settings the working PC session used
  4. Check what the query encodes
  5. Rebuild the channel with the Modbus configurator
  6. Decide from the result
  7. Questions asked

When a PC master running Modbus Poll reads every register and your CODESYS 3.5 Modbus RTU master times out on the same slave, the slave, its register map and its framing are already proven good. The fault sits in something the two masters do not share: the serial port configuration, the unit ID, or the RS-485 cable. Trace the request across four hops — the query, the serial port, the cable, the slave's receiver. A timeout points at the middle two hops, an exception reply clears all of them and leaves only the query parameters, and in the case behind this article the failing hop was the cable: a new twisted-pair run restored the data with no program edits.

Read the failure signature before touching settings #

Read what the master reports before changing anything, because the signature splits the fault cleanly:

  • A timeout: the master sent a frame and received nothing that passed. The request died in the port settings, in the cable, or at the slave's receiver.
  • An exception reply: the slave heard the frame, validated it, and answered with an exception code instead of data. The cable, the port and the unit ID are all proven good, and the fault is in the query parameters.
  • Data that arrives but looks wrong or shifted: the link works end to end and the address convention or byte order is off.

Then follow the request itself hop by hop, because a failure at one hop makes every check above it meaningless:

  1. The query the program builds: bUnitId, bFunctionCode, uiReadAddress and uiReadQuantity in the typMbQuery structure.
  2. The controller's serial port: baud rate, parity, data bits, stop bits, and the terminals those settings actually drive.
  3. The RS-485 cable and its terminators: continuity, polarity, the twisted pair, the end-of-line resistors.
  4. The slave's receiver: framing, CRC and the unit ID match.

Two masters on one bus do not share hops 2 and 3 when the PC adapter connects at a different point through a different lead. That is exactly why a PC tool reads ten registers while the PLC master times out on the same slave: the two paths are different copper. Hop 2 closes with a settings comparison, and hop 3 closes with a resistance measurement you can put a number on.

Test the RS-485 cable and its terminators #

The cable is the cheapest hop to prove and the one that failed in the reported case, so measure it first. RS-485, standardized as TIA/EIA-485-A, transmits the signal as the voltage difference between the A and B conductors; a broken conductor, a loose terminal or a swapped pair leaves the slave deaf or corrupts the CRC on random frames. A PC adapter clipped in near the slave on a short lead can read perfectly while the run back to the controller is damaged.

Work through these checks with the bus powered down — that power-down is the one safety step here, and it also makes the resistance reading honest:

  • Check continuity of the A conductor and of the B conductor end to end.
  • Confirm A lands on A and B lands on B at both ends. Device labels vary between A/B and D+/D-, so follow each manual's terminal function rather than the letters; a swapped pair silencing a healthy slave is a pattern across vendors, and the CM1241 RS485 A/B polarity case documents one example.
  • Keep A and B on one twisted pair of the cable.
  • Reseat every screw or spring terminal and look for stray strands or insulation trapped under a clamp.

With the segment dead, measure resistance between A and B at the controller end. Fit a 120 Ω terminator across the pair at each physical end of the bus, the value that matches the twisted pair's differential-mode characteristic impedance, and the healthy reading follows from the two resistors sitting in parallel:

(120 × 120) / (120 + 120) = 60 Ω

Real runs read a little higher, because the wire resistance adds in series with the far terminator. For example, 500 m of 24 AWG cable adds about 42 Ω per conductor, so the far branch reads 204 Ω and the measurement works out to (120 × 204) / (120 + 204) ≈ 76 Ω. Decide from what the meter shows:

  • About 60 to 80 Ω: both terminators present, both conductors continuous. The cable passes.
  • About 120 Ω: one terminator doing all the work — the far terminator is missing or one conductor is broken along the run. Check the far end next.
  • Far above that, up to open: no terminators fitted, or both legs broken.
  • Near zero: A and B shorted together.
  • Below about 45 Ω on an otherwise healthy pair: an extra terminator is fitted mid-bus. Terminate only the two physical ends and remove any resistor in the middle.

In the case that prompted this article, the segment failed here. The replacement cable measured in the healthy band, the query ran unchanged, and the ten registers came back — the swap itself is the proof that hop 3 was the fault.

Match the serial settings the working PC session used #

A PC master that reads the slave proves the slave's framing, but only if you know what the PC sent. Open the connection setup in Modbus Poll, read the four values it used, and enter the same values in the CODESYS serial port configuration. A parity or stop-bit mismatch turns individual bytes into framing errors at the slave, the CRC never passes, and the slave stays silent, which the master reports as a timeout.

Setting Where to read it What a mismatch looks like
Baud rate the slave's serial settings and the PC session's connection setup timeout on every poll
Parity and stop bits the same two places; 8 data bits with even parity and 1 stop bit is the Modbus serial line specification's default, and with no parity the specification calls for 2 stop bits timeout, no frame ever passes CRC
Unit ID the slave's address setting and the PC session's slave address timeout with clean framing, because the slave ignores frames addressed to another unit
Serial port and terminals the controller's serial interface documentation no traffic on the line at all

Leave the master's response timeout with comfortable margin over the frame time; the worked arithmetic sits in the FAQ. When the framing matches, the cable measures healthy and the slave still never answers, the unit ID and the port assignment are the suspects left.

Check what the query encodes #

With the wire and the framing proven, read the request itself. The query from the reported case, as it was built:

utQuery : typMbQuery := (
    bUnitId := 1,                             // slave address
    bFunctionCode := 16#04,                   // read input registers
    IIdentifyObject := myBaseIdentification,  // only needed for FC43
    uiReadAddress := 2000,                    // start address
    uiReadQuantity := 10,                     // quantity of wanted registers
    uiWriteAddress := 0,                      // not needed for FC4
    uiWriteQuantity := 0,                     // not needed for FC4
    awWriteData := [124(0)]                   // not needed for FC4
);

Function code 16#04 reads input registers, so the query asks for the ten registers at protocol addresses 2000 through 2009 — the same request the PC tool sent, which is why the encoding is rarely the reason for a bare timeout. What differs between tools is the address convention. Protocol addresses count from 0, while many PC tools and register tables print 1-based references: input register reference 32001 is protocol address 2000 on the wire. A query that adds the extra one reads the neighbouring register — wrong values, not a timeout. A quantity that runs past the mapped block earns an exception reply, which again proves the wire. So for a bare timeout the encoding is usually innocent; the one-off offset becomes the first suspect once data flows and looks shifted, and the fix is to match uiReadAddress to the basis the slave's register table documents.

Rebuild the channel with the Modbus configurator #

If the cable, the framing and the address convention all check out and the master still reads nothing, rebuild the channel with the Modbus configurator in CODESYS 3.5 instead of the hand-built structure. The configurator creates the serial port, the master, the slave and the channel as one object tree, so the port framing and the per-channel unit ID, function code, offset and length cannot disagree the way two separately typed places can. Create the master on the serial line the bus uses, enter the four framing values, add the slave with unit ID 1, add a channel that reads input registers at offset 2000 with a length of 10, and map the results to variables.

Call the query cyclically; a one-shot call reads once and then sits stale. For the library and task side of a CODESYS Modbus serial master, the CODESYS 2.3 Modbus serial master library and task setup article covers the same master-slave-channel pattern. Then prove the whole chain: run the program and watch the mapped variables follow the physical inputs. If several slaves share the segment, the polling order and spacing decide how fresh each device's data is, and the article on polling many Modbus RTU slaves from one serial master covers that layout.

Decide from the result #

Map the outcome back to its hop and stop there:

  • Timeout, no reply: hops 2 to 4. Match the framing, confirm the unit ID, then prove the cable with the resistance test. This was the reported case, and the failing hop was 3.
  • Exception reply: hop 1. The slave is answering, so correct the function code, the address range or the quantity; the common codes are decoded in the FAQ.
  • Data that reads but looks shifted: the address convention. Align uiReadAddress with the basis the register table uses.
  • Data that reads once and then stalls: the task. Call the query cyclically or rebuild the channel with the configurator.

The decision in one line: when a PC master works and the PLC master gets nothing, the slave is innocent, so begin with the copper — cable first, framing second, encoding last. In the reported case that order found a damaged RS-485 run, and a new cable returned all ten registers without a single program change.

Questions asked

Why does a query to unit ID 0 never get an answer?

In the Modbus serial line specification, address 0 is the broadcast address. Slaves act on broadcast write commands but never transmit a reply, so a read addressed to 0 returns silence and the master times out by design. Reads need the device's configured address, which can be any value from 1 to 247; check the address setting on the slave itself when every other hop measures healthy.

What do the common Modbus exception codes mean?

An exception reply repeats the function code with its high bit set and adds one code byte. Code 01 means the slave does not implement that function. Code 02 means the requested address or quantity falls outside the mapped range. Code 03 means a value in the query is invalid, for example a read of more than 125 registers in one request. Any exception reply proves the cable, the port and the unit ID, because the frame made the round trip intact.

How long should the master's response timeout be?

Size it from the line time and add margin. A ten-register input read puts 8 bytes on the wire and expects 25 back; at 19200 bit/s with 11 bits per byte that is (8 + 25) × 11 / 19200 = 18.9 ms of line time, plus the slave's processing delay. Set 200 to 500 ms so a busy slave or a noisy frame still fits inside the window, and keep the value consistent across the segment's polls.

Why must A and B run on one twisted pair?

RS-485 receivers read the voltage difference between the two conductors, and a tightly twisted pair presents nearly the same impedance to both wires and couples interference onto them almost equally, so the difference stays clean. Split the two conductors across different pairs of a multi-pair cable and the balance is lost: the loop area grows, one wire picks up more noise than the other, and long segments start showing CRC errors. One pair for A and B, with the shield bonded at one point.

Keep reading

  • Troubleshooting

    Why a CJ2M Modbus RTU master gets no answer from an S7-1200

    Yes, a CJ2M can poll an S7-1200 over Modbus RTU. The simulators proved each PLC's serial settings, not the cable or the port mode between them: set the Omron port to the mode the MRTU_CPU_Master package requires, bring the send pair onto RDA and RDB for 2-wire operation, load the S7-1200 port at even parity, and confirm the frame on the wire with a known value.

    Industrial networks

  • Troubleshooting

    Why a CP 341 Modbus master returns status W#16#1E0D

    W#16#1E0D on a CP 341 Modbus master call means the serial transaction did not complete; on a link that once passed commissioning the fault sits on the Siemens side, in the cable path, or at the Schneider partner. Match the port variant from the order number, capture the line while real requests run, then use three laptop tests - passive monitor, slave simulator at the CP, master simulator at the Schneider PLC - to decide which side failed.

    Industrial networks

  • Troubleshooting

    CB1241 reads zero on Modbus RTU while the transmitter works

    A CB1241 that reads zero while a USB-to-RS-485 converter reads the same transmitter is failing on the PLC side, and TIA Portal hides the cause: MB_MASTER completes with an error and the next scan's retry clears STATUS. Latch STATUS into a memory word when ERROR goes true, then fix the parity code, the unit ID, the 40001-based register number and the RS-485 bus, and keep the converter off the bus.

    Industrial networks