Comparison
Polling many Modbus RTU slaves with one queued function block
Short answer
On an M241 the built-in Modbus IO Scanner is documented to 64 slave devices across serial lines SL1 and SL2, so 33 identical RTU slaves belong in the scanner rather than a hand-written queue. Keep the queued function block for controllers without a scanner or counts above 64, sequenced on busy, done and error flags.
On this page
- Can the built-in IO Scanner handle 33 Modbus RTU slaves?
- Does one RS-485 segment carry 33 slaves over 500 meters?
- How long does one full poll of 33 slaves take at 9600 baud?
- Is the IO Scanner or a queued function block the better architecture?
- How should the queued function block sequence its requests?
- How do HMI writes jump the read queue safely?
- How do you keep per-device fault diagnosis with one block?
- When do 33 separate function block instances still win?
- Questions asked
Thirty-three identical Modbus RTU slaves fit inside the M241's built-in Modbus IO Scanner, which the vendor documents at 64 slave devices maximum across serial lines SL1 and SL2, so the scanner should run this project and the queued function block stays in reserve as the fallback. Build the queue when a controller ships without a scanner, when the slave count outgrows the documented capacity, or when the application must own request priority. The physics does not change with the architecture: one transaction on the wire at a time, RS-485 unit loads capping a repeater-free segment at 32 devices, and a pass time you can compute from frame length and baud rate before writing any code. The sections below compare the three architectures and put numbers on your 33-device, 500-meter, 9600 bps, 8-E-1 network.
Can the built-in IO Scanner handle 33 Modbus RTU slaves? #
Yes — the vendor documents a maximum of 64 Modbus slave devices for the added Modbus IO Scanner on the M241, counted across serial lines SL1 and SL2, so 33 identical slaves sit at about half the documented capacity and the scanner should run them.
That figure belongs to the M241 as the vendor's scanner-capacity FAQ states it; it is not a family-wide constant, so confirm it against the documentation for your exact CPU and software version before the design freezes. In EcoStruxure Machine Expert the scanner is a configuration object rather than code: you list each slave with its address, the registers to read and the refresh condition, and the runtime schedules the transactions outside your scan cycle. Every channel reports its own health, so a slave that stops answering is already named for you. What you own is the mapping, the refresh intervals and the wiring — the scanner will not repair a marginal bus.
Decision: configure all 33 devices in the IO Scanner and treat the queued function block as the documented fallback, not the plan of record.
Does one RS-485 segment carry 33 slaves over 500 meters? #
Not on one segment — classic RS-485 loading allows 32 devices per segment and total bus length tops out near 1200 meters, so a 500-meter run passes the distance check but its 33 devices need at least one repeater to split into two segments inside the limit.
The figure is the unit load the RS-485 standard assumes for its drivers, and it belongs to each segment, not to the whole network: a repeater regenerates the signal and resets the device count on the far side. Many modern slaves present a fractional unit load, which raises the per-segment count, and the device datasheet is what decides that number. Splitting 33 devices into segments of 17 and 16 leaves both segments far below the classic limit even with full-load devices. Terminate and bias each segment at its ends, keep stubs short, and set repeater direction and power per the repeater's own documentation. Length is a separate check: Modbus RS-485 practice caps the summed length of all segments at about 1200 meters, and 500 meters sits well inside. Set slave addresses 1 through 33 uniquely and prove one known-good device before scanning the whole line.
Decision: the repeater in your plan is required, not optional — with one repeater splitting 17 and 16 devices, every segment is inside the 32-device limit and the 500 meters has margin.
How long does one full poll of 33 slaves take at 9600 baud? #
About 1.2 seconds per complete pass with all 33 slaves healthy at 9600 bps, and one dead slave with a one-second timeout stretches every pass by that full second.
The number falls straight out of the frame sizes, and it is worth computing before the architecture is chosen, because it is the update rate your process has to accept. Worked example, reading 6 holding registers per device:
- Request frame: 1 address byte + 1 function byte + 2 start-address bytes + 2 quantity bytes + 2 CRC bytes = 8 bytes. Response: 1 + 1 + 1 byte-count byte + 12 data bytes + 2 CRC bytes = 17 bytes. Each transaction is 25 bytes.
- 8-E-1 framing sends 11 bits per byte, so one transaction is 25 × 11 = 275 bits.
- Wire time: 275 bits ÷ 9600 bps = 28.6 ms.
- Silence and turnaround: the Modbus inter-frame gap is 3.5 character times, 3.5 × 11 = 38.5 bits ÷ 9600 bps = 4.0 ms, plus about 2 ms of slave response latency — roughly 35 ms per device.
- Full pass: 33 × 35 ms = 1155 ms, call it 1.2 seconds per refresh of every device.
What moves it: each extra 10 ms of average slave latency adds 330 ms per pass, and each extra register per device adds 2 bytes = 22 bits = 2.3 ms, or 76 ms per pass across 33 devices. At 19200 bps the wire time halves to 14.3 ms per transaction and a healthy pass drops to roughly 0.6 seconds. Errors dominate everything: one slave that stops answering under a 1-second timeout makes every pass about 2.2 seconds, and two retries before skip makes it about 4.2 seconds, so the retry policy is a cycle-time decision as much as a reliability one. No scheduler beats the wire — Why Modbus RTU drive polling on one serial port is slow works the same one-port arithmetic in detail.
Decision: design on 1.2 seconds per full refresh; if the process needs faster, move the line to 19200 bps, trim the register count, or split devices across SL1 and SL2 so each line carries half the transactions.
Is the IO Scanner or a queued function block the better architecture? #
The IO Scanner wins here: the M241's documented 64-device capacity covers all 33 slaves, scheduling runs outside your scan cycle, and every channel carries its own fault status — keep the queued function block for controllers without a scanner or counts above it.
| Architecture | Use when | What it gives you | What you own |
|---|---|---|---|
| Built-in IO Scanner | Slave count inside the documented scanner capacity (64 Modbus slaves on the M241 across SL1 and SL2) | Request scheduling outside user code, per-channel fault status, no hand-written sequencing | Channel mapping, refresh intervals, wiring health |
| One queued function block | No scanner on the controller, or count and scheduling needs exceed it | One code path for all devices, application-controlled write priority | Busy/done/error sequencing, retries, per-device freshness, diagnostics |
| One instance per device | A handful of devices or genuinely different logic per device | Immediate per-device visibility in the code | A copy of the block and its variables per device, every fix applied to each |
The queue's real cost is not variables — 33 devices at 6 words each is 198 words of arrays, trivial on any modern controller — it is diagnostics. The scanner hands you per-channel health; a hand-rolled queue tells you only what you instrumented. The comparison that matters is commissioning and maintenance time: with the scanner you commission mappings, with the queue you commission a state machine plus whatever diagnostic surface you remembered to build.
Decision: scanner first at 33 devices on an M241; the queue only against the fallback rows of the table.
How should the queued function block sequence its requests? #
Gate every request on the communication block's busy, done and error flags — issue the next read only while the block is idle, store data on done, record and skip on error — and never on a fixed timer, because timers drift out of step with the wire.
The queue itself is five rules:
- Keep one index over the devices, 0 through 32, with the slave address each index selects, and check the index against the range before any request is built; an out-of-range index selects the wrong slave or data slot.
- Fire the read for the active index only when the block reports idle; while it reports busy, wait.
- On done, move the six words into that device's array slot, stamp the slot with a freshness marker, then increment the index.
- On error, increment that device's error count, apply the skip policy, keep the error code observable, then increment the index.
- Wrap at 33 back to 0.
Separate communication state from process data: the arrays of values are what the control logic reads, and the freshness markers are what decide whether those values may be trusted — a skipped read must never look like a fresh one. The same flag-gated scheduler, sized for one serial master and many slaves, is walked through step by step in How to poll many Modbus RTU slaves from one serial master.
Decision: flags, never timers — busy gates the issue, done moves data, error counts and skips.
How do HMI writes jump the read queue safely? #
Capture the target slave address and the command together the moment the operator presses the button, let the active read finish, send the write to the captured address once the block goes idle, and report success only on the write's done flag — never because the request was issued.
Pause new reads while a write is pending rather than aborting the active transaction: one RTU port carries exactly one transaction, and a second request issued into an active one is what corrupts control on a serial line — Why a Modbus RTU read and write on one port drops VFD control shows that failure with drives. Capturing address and command together matters because an operator can change the selection between pressing the button and the write firing; the pending write must still reach the device selected when it was requested. Serve the write ahead of the queue's next read and resume polling on the write's done flag — the ordering pattern is the one described in Speeding Up Modbus RTU Writes Behind Polled Reads. Before the queue issues an open, close or stop, check that device's freshness: if the last good read from the target is older than two passes, refuse the command at the PLC rather than act on stale status. On a write error, apply the documented policy — three failed attempts, then cancel, raise a fault to the HMI and leave the device untouched.
Decision: capture address and command as a pair, gate on idle, send one write, resume on done, and interlock the command on freshness.
How do you keep per-device fault diagnosis with one block? #
Rebuild in arrays what 33 separate instances used to give you for free: one error count, one error code and one last-good-pass marker per device, so a slave that stops answering is named by index in seconds instead of found by watching the queue stall.
The last-good-pass marker costs almost nothing — one increment per completed pass, one store per successful read — and it turns the hunt for a stale device into a compare. Keep a commissioning mode that polls exactly one selected device, so a technician can exercise a single slave while the rest of the line stays quiet; prove the wiring against one known-good device before scanning all 33. When a slave goes quiet, check the physical layer before the logic: Why a Modbus RTU frame gap before the CRC silences the slave documents a framing fault that looks exactly like a dead device.
Decision: three status arrays, one single-device commissioning mode, and the physical layer checked first when a device goes quiet.
When do 33 separate function block instances still win? #
Only below roughly eight identical devices, or when each device needs genuinely different logic — at 33 copies, six-plus variables per instance and every fix applied 33 times cost more than any array saves.
Below that size, one instance per device buys immediate per-device visibility and trivial startup troubleshooting, and nobody has to understand an index to follow the code. The middle path is an array of the block's own type called with the device index, so there is one code body and per-device state at every element — but one RTU port still carries one transaction at a time, so the array calls must share the same idle gate, which converges right back on the queue's discipline. The three decisions in one place:
- The documented scanner capacity covers the slave count — 33 fits — so configure the IO Scanner and skip the custom code.
- The count exceeds capacity or the controller has no scanner — one queued function block, gated on idle, busy, done and error, writes captured as address-and-command pairs, per-device freshness kept.
- A handful of devices, or different logic per device — one instance each, updated together.
Questions asked
How many slave addresses does Modbus RTU define?
The Modbus serial line specification numbers slave addresses from 1 to 247, with address 0 reserved for broadcasts. That address range is separate from the electrical limit: a segment without repeaters is typically good for 32 classic unit-load devices, and fractional-load devices raise the count. The address space decides what you can configure; the segment loading decides what the wire can carry.
What happens if two masters try to share one Modbus RTU bus?
Collisions, because an RTU serial line is single-master: one device drives requests at a time. If a second client such as a data logger needs the same slaves, give it its own serial line from another port on the controller, or put a gateway with a single RTU master side on the bus and let the second client reach the slaves through the gateway's network side.
Which parity and stop-bit settings match a 9600 bps RTU network?
The Modbus serial line specification makes EVEN parity the RTU default, which is what 9600 bps, EVEN, 1 stop bit implements. The same specification asks for two stop bits when a device runs with no parity at all. Every master and slave on the line must carry identical serial settings, because the receiver finds the frame boundary by counting those bits.
Are retry counts and skip-after-error rules part of the Modbus standard?
No. The standard defines the request-response transaction, the silent intervals between frames and the CRC check; it does not say how many times a master retries a slave that never answers or when the poller moves on. Three attempts, then skip and log, is an application policy — write it down once, keep it in one place in the code, and expose the counter to the HMI.