Skip to content

fix(transport): retry a read whose answer has the wrong length - #674

Merged
groupsky merged 1 commit into
mainfrom
fix/transport-short-answer-retry
Oct 20, 2026
Merged

groupsky merged 1 commit into
mainfrom
fix/transport-short-answer-retry

Conversation

@groupsky

Copy link
Copy Markdown
Owner

Summary

A read whose answer has the wrong number of data bytes is now a failed request, so withRetry sends it again in the same poll, like after a timeout or a CRC error. Before, the short buffer went to the driver, the decoder threw, and the whole poll failed (an OR-WE-514 sent 1 data byte for a 2-register read, 4 times in 23 hours).

Changes

  • New internal checkLength (packages/transport/src/answer-length.ts): register reads expect count × 2 bytes, coil and discrete-input reads expect ceil(count / 8) bytes.
  • Used inside the retried function of all four reads in both createModbusTransport (CLI, profiler) and SlaveTransport (the MQTT bridge, through TransportManager).
  • Error: Wrong answer length: expected 4 data bytes, got 1. withRequestContext appends the port, slave, function, address and count, e.g. (… 9600 8N1, slave 2, FC03 read holding registers, address 0 (0x0000), count 2).
  • modbus-serial 8.0.25 already checks the whole frame length, so a good answer always matches; only a byte-count byte that disagrees with the frame is rejected.

Checklist

  • Tests added/updated for new functionality: for both transports and all four reads, "short once, then good → good after one retry" and "always wrong → rejects with the message"
  • Documentation updated (if applicable): not needed

Closes #673

A meter sent 1 data byte for a 2-register read. It was not treated as a
failed request, so it was not retried and the driver decoder threw.
Now every register, coil and discrete input read checks the byte count
inside the retried function, in createModbusTransport and in
SlaveTransport (the path the MQTT bridge uses).

Closes #673
@pkg-pr-new

pkg-pr-new Bot commented Oct 20, 2026

Copy link
Copy Markdown

Open in StackBlitz

@ya-modbus/cli

npm i https://pkg.pr.new/@ya-modbus/cli@674

@ya-modbus/device-profiler

npm i https://pkg.pr.new/@ya-modbus/device-profiler@674

@ya-modbus/driver-dds024mr

npm i https://pkg.pr.new/@ya-modbus/driver-dds024mr@674

@ya-modbus/driver-dds519mr

npm i https://pkg.pr.new/@ya-modbus/driver-dds519mr@674

@ya-modbus/driver-ex9em

npm i https://pkg.pr.new/@ya-modbus/driver-ex9em@674

@ya-modbus/driver-loader

npm i https://pkg.pr.new/@ya-modbus/driver-loader@674

@ya-modbus/driver-or-we-514

npm i https://pkg.pr.new/@ya-modbus/driver-or-we-514@674

@ya-modbus/driver-or-we-516

npm i https://pkg.pr.new/@ya-modbus/driver-or-we-516@674

@ya-modbus/driver-sdk

npm i https://pkg.pr.new/@ya-modbus/driver-sdk@674

@ya-modbus/driver-sdm630

npm i https://pkg.pr.new/@ya-modbus/driver-sdm630@674

@ya-modbus/driver-types

npm i https://pkg.pr.new/@ya-modbus/driver-types@674

@ya-modbus/driver-xymd1

npm i https://pkg.pr.new/@ya-modbus/driver-xymd1@674

@ya-modbus/emulator

npm i https://pkg.pr.new/@ya-modbus/emulator@674

@ya-modbus/mqtt-bridge

npm i https://pkg.pr.new/@ya-modbus/mqtt-bridge@674

@ya-modbus/transport

npm i https://pkg.pr.new/@ya-modbus/transport@674

ya-modbus

npm i https://pkg.pr.new/ya-modbus@674

ya-modbus-bridge

npm i https://pkg.pr.new/ya-modbus-bridge@674

ya-modbus-emulator

npm i https://pkg.pr.new/ya-modbus-emulator@674

ya-modbus-profile

npm i https://pkg.pr.new/ya-modbus-profile@674

commit: 0399c95

@groupsky
groupsky merged commit 01f71bf into main Oct 20, 2026
13 checks passed
@groupsky
groupsky deleted the fix/transport-short-answer-retry branch October 20, 2026 16:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

transport: a short answer (fewer data bytes than asked) is not retried; the whole poll fails in the driver

1 participant