Troubleshooting
Why Modbus TCP discrete inputs read bad only on subscribe
Short answer
When discrete-input tags read good one at a time and go bad on subscribe, the driver is batching your separated addresses into one FC02 read that crosses addresses the device does not define, so the device rejects the whole transaction. Uncheck Span Gaps in the Modbus device connection so each range is read separately; if quality stays bad, capture the traffic and check the data area and address base.

On this page
- Why do discrete inputs read bad only when you subscribe?
- What does the subscription change on the wire?
- What does Span Gaps do in the Modbus device connection?
- How do you prove the gap is the cause with a capture?
- How do you turn gap spanning off?
- What if disabling Span Gaps changes nothing?
- When should you reorganize the device map instead?
- Questions asked
Discrete-input tags that read good one at a time and go bad the moment you subscribe are being killed by the read request, not by the wire: the driver batches your separated addresses into one wider FC02 read, and when that read crosses an address the device has not defined, the device rejects the whole transaction. Holding-register tags on the same device survive because their addresses sit inside one defined block. The change that fixed one reported install is to uncheck Span Gaps in the Modbus device connection so each address range is read separately; the worked example below shows the arithmetic, and a short capture proves which case you are in.
Why do discrete inputs read bad only when you subscribe? #
A single read asks for one address and succeeds; a subscription lets the driver batch your tags into one wider read, and when that wider read crosses addresses the device does not define, the device rejects the whole transaction and every tag inside it goes bad at once.
The single read and the subscription exercise different request patterns against the same device. A good one-off read proves the tag's address, its data area, the connection and the device's answer to that one request; it proves nothing about the request the polling scheduler assembles once several tags are active. When holding registers stay good and discrete inputs fail, the network path and the connection are healthy, and the difference lives in how requests for that one data area are shaped. Good outside subscription, bad inside it, one data area affected: that signature points at the combined request before it points at scan timing.
What does the subscription change on the wire? #
The device never sees your subscription: the OPC server turns it into recurring Modbus read transactions, so the request the device receives can carry a different starting address and quantity than the single read that worked, and the device judges that whole request or none of it.
Between the subscribing client and the device sit the server's polling scheduler and the driver's request optimizer. They group active tags, merge near-adjacent addresses and refresh the driver's cache on a cycle, so the device answers Modbus reads, not subscriptions. Modbus has no partial answer: an exception applies to the entire request, never to individual tags inside it. For what one merged request does and does not promise, the article on synchronous PLC reads and grouped request guarantees is the reference. The consequence here is simple: one undefined address in the middle of a merged read punishes every tag on both sides of it, including tags that read good alone.
What does Span Gaps do in the Modbus device connection? #
Span Gaps is the documented option in the Modbus device connection that lets the driver span address gaps when optimizing requests, turning two reads at separated addresses into one read of the interval, which cuts request count but forces the device to answer for addresses it may not own.
The option lives in the device connection settings of servers that optimize Modbus traffic; the name Span Gaps is the documented one in Ignition's Modbus connection, and other servers expose the same behavior under their own request-optimization settings. With the option checked, the driver fills the space between non-adjacent addresses to reduce the number of requests. Devices react to a request covering undefined addresses in two ways: most answer with exception code 02, illegal data address, and some never answer at all, so the read times out. Either way the driver marks every tag in that transaction bad, which is why tags on both sides of a hole fail together while a single read of one defined address succeeds.
How do you prove the gap is the cause with a capture? #
Capture one working single read and one failing subscription with Wireshark on the driver host and compare them request by request: the spanned request shows a starting address of 2 with quantity 7 where two quantity-1 reads belong, and the device answers with exception code 02 or stays silent.
Worked example: say your two discrete inputs sit at wire addresses 3 and 9, the 1-based numbers the device documentation prints. Read alone, each tag produces its own FC02 request — starting address 2 with quantity 1 covers wire address 3, and starting address 8 with quantity 1 covers wire address 9 — and both come back good because each address is defined. With spanning on, the driver covers the interval between them: 9 - 3 + 1 = 7, so it sends one FC02 request with starting address 2 and quantity 7, reaching wire addresses 3 through 9. That request includes the five undefined addresses from wire 4 through 8, so a device with nothing defined there rejects the whole transaction or goes quiet, and both good tags go bad together.
To see this on your own system:
- In the OPC Quick Client, read one failing tag without subscribing and save that exchange from the capture.
- Subscribe to the same tags and save the exchanges the polling produces.
- Match each request to its response and compare destination address, unit identifier, function code, starting address and quantity.
- Read the result against these outcomes:
- One wide FC02 request answered with the illegal-data-address exception, or no answer at all: gap spanning is the cause; take the fix below.
- Narrow requests that still fail: the data area, the address base or the quantity is wrong, not the spanning.
- No request at all for the subscription: the failure sits upstream of the device, in subscription activation or the polling group.
- A normal response that still arrives with bad quality: the exchange is healthy; check driver diagnostics and tag mapping next.
How do you turn gap spanning off? #
Open the Modbus device connection settings in your OPC server, uncheck Span Gaps, apply the change, and rerun the same subscription: each separated address goes out as its own quantity-1 read again, the change that fixed one reported install with exactly this symptom.
- Record the current state of the gap-spanning option in the Modbus device connection settings.
- Uncheck it and apply the edit the way your server applies device connection changes, including any reconnect it asks for.
- Change nothing else in the same pass — no scan rates, no timeouts — so the before-and-after comparison stays clean.
- Rerun the subscription and confirm every tag that was bad now reads good.
- Capture once more and confirm the wide request is replaced by one narrow read per separated range.
- Leave the option off for that device and note the decision next to its address map so nobody re-enables it later for speed.
What if disabling Span Gaps changes nothing? #
Gap spanning explains only requests that fail because they cross undefined addresses; if the quality stays bad after unchecking it, the capture will show a request with a wrong data area, an address base shifted by one, a quantity the device cannot serve, or no request at all.
One reported install stayed faulty after the change, and that result is the signal to go back to the capture rather than to guess. Work the branches in order:
- Wrong data area: a tag is mapped to holding registers when you believe it reads discrete inputs, or the reverse. A valid holding-register address proves nothing about the FC02 map, and the no-data version of this symptom has its own walkthrough in fixing Modbus TCP FC02 discrete inputs that return no data.
- Address base off by one: the number your driver prints and the number that goes on the wire differ by one, so a request aimed one address low lands on a hole; the article on why Modbus discrete inputs are off by one at the PLC covers that offset.
- Quantity too large: the merged request asks for more inputs in one read than the device serves from that area, and the device refuses it even when every address inside is defined.
- No change on the wire: the edit never reached the running connection, or the failing tags belong to a different device connection than the one you edited.
When should you reorganize the device map instead? #
Move the tags you need into contiguous blocks in the device so one spanning read covers only defined addresses, and keep Span Gaps off whenever any connected device rejects undefined addresses — the split reads cost more transactions but every request then stays inside the map the device actually owns.
If you program the device yourself, the map is yours to fix. Gather the discrete inputs the SCADA needs into one contiguous range; spanning reads then stop crossing holes, and you can re-enable the optimization for its lower request count. Verify the revised map and every affected tag before the screen goes back into service. The cost arithmetic follows the count of separated ranges, not of tags: two tags at wire addresses 3 and 9 mean two requests where one existed before, and a map with ten separated ranges means ten. One safety note: while quality is bad, the operator's indication is unknown, not off — restart nothing and trust nothing fed by these inputs until quality reads good again.
Decision, case by case:
- Capture shows one wide FC02 read crossing a hole, and the device answers with the illegal-data-address exception or times out: uncheck Span Gaps in that Modbus device connection and leave it off.
- Capture shows narrow requests still failing: fix the data area, the address base or the quantity; spanning was never the cause.
- Capture shows no request: repair the subscription or the device connection the tags live in.
- You control the device map: make the needed ranges contiguous, verify each tag, then choose the setting on performance.
Questions asked
Does unchecking Span Gaps hurt Modbus TCP scan performance?
It can raise the request count: every separated address range becomes its own transaction, so two tags at distant addresses go from one read to two. On Modbus TCP over a local network the extra frames are usually negligible at normal scan rates. On a serial link behind a gateway, or with hundreds of separated ranges, watch the poll cycle time after the change and confirm the device keeps up.
What does Modbus exception code 02 mean?
Exception code 02 is illegal data address: the device is saying that the starting address and quantity of the request together reach addresses it does not define, so it refuses the whole transaction rather than returning partial data. In this failure that is the driver-spanned read crossing the hole in the discrete-input map. Partial responses are not a Modbus option; one undefined address invalidates the entire request.
Why do holding registers read good while discrete inputs fail on the same device?
Each Modbus data area has its own address map, and your device's holding-register block may be contiguous while its discrete inputs sit in separated ranges with holes between them. A good holding-register read proves the network and the connection, nothing about the FC02 map. Check where each data area begins and ends in the device documentation before you trust one area's success as evidence for another.
How many discrete inputs can one Modbus read request cover?
The Modbus specification allows up to 2000 discrete inputs in a single FC02 request, so the protocol ceiling is not what stops these reads. The practical limit is the device's defined map and the largest quantity the device accepts without an exception. With gap spanning disabled you trade the wide request for several narrow ones, each of which must still stay inside addresses the device defines.
