feat: Add Slave ID support for Modbus TCP master plugin#79
Merged
Conversation
Add Slave ID (Unit ID) support to the Modbus master plugin to enable communication through Modbus TCP gateways that forward messages to RS485 serial networks. The Slave ID is passed to all pymodbus read/write operations via the 'slave' parameter. Changes: - Add slave_id field to ModbusDeviceConfig with validation (0-255) - Parse slave_id from JSON configuration (default 1) - Store slave_id in ModbusConnectionManager - Pass slave parameter to all Modbus operations (FC 1-6, 15, 16) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds Slave ID (Unit ID) support to the Modbus TCP master plugin, enabling communication through Modbus TCP gateways that forward messages to RS485 serial networks. The implementation maintains backward compatibility by defaulting to slave_id=1.
Changes:
- Added
slave_idfield toModbusDeviceConfigwith validation for values 0-255 - Updated
ModbusConnectionManagerto store and use the slave_id parameter - Modified all Modbus read/write operations (FC 1, 2, 3, 4, 5, 6, 15, 16) to pass the
slaveparameter
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| modbus_master_config_model.py | Added slave_id field with default value 1, validation logic, and updated repr method |
| modbus_master_plugin.py | Updated ModbusConnectionManager initialization and all Modbus read/write operations to include slave parameter |
| modbus_master_connection.py | Added slave_id parameter to init method with default value 1 |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
pymodbus 3.10+ renamed the 'slave' parameter to 'device_id' for all client read/write methods. Update all Modbus operations to use the correct parameter name. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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.
Summary
slaveparameterChanges
slave_idfield toModbusDeviceConfigwith validation (0-255)slave_idfrom JSON configuration (default 1)slave_idinModbusConnectionManagerslaveparameter to all Modbus operations (FC 1, 2, 3, 4, 5, 6, 15, 16)JSON Configuration Format
{ "name": "device_name", "protocol": "MODBUS", "config": { "type": "SLAVE", "host": "192.168.1.100", "port": 502, "timeout_ms": 1000, "slave_id": 5, "io_points": [...] } }Test plan
slave_id🤖 Generated with Claude Code