Conversation
A register can name its own unit with the new `unit` option. Registers on every unit share one connection, so a single instance reaches every device behind a gateway or a controller that exposes several units. The Carlo Gavazzi BH8-CTRLX, for example, gives the controller and each extension module its own Modbus ID. Registers without `unit` use the connection's device_address as before. Each unit gets its own input and holding tables. poll() reads and flushes writes per unit, and every read and write passes its unit as device_id.
asmundg
force-pushed
the
upstream-per-register-units
branch
from
September 25, 2026 09:45
6276217 to
7b77e5e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds an optional
unitfield to each register, so a single modbus4mqtt instance can read and write registers on more than one Modbus unit over one connection. This helps with gateways, and with controllers that expose separate buses as separate units. For example, the Carlo Gavazzi BH8-CTRLX smart-house controller gives the controller and each extension module its own Modbus ID (CTRLX manual, section 3.4.2.3, PDF).Registers without
unitkeep using the connection'sdevice_address, so existing configs behave as before.Changes
modbus_interfacekeeps separate input and holding tables for each unit.poll()reads and flushes writes one unit at a time, and each read and write passes its unit asdevice_id.add_monitor_register,get_valueandset_valuetake an optionalunitargument, andmodbus4mqtt.pypasses the register'sunitthrough.Testing
test_registers_poll_and_write_on_their_own_unit: polls the same address on two units and checks each unit's value, then checks that a write goes to the right unit.tests/test_modbus_server.pyalso occur onmasterwithout this change.This PR is independent of #71. The two touch adjacent lines in
modbus4mqtt.pyand the README option table, so whichever merges second needs a small rebase.🤖 Generated with Claude Code