Skip to content

feat: Add Slave ID support for Modbus TCP master plugin#79

Merged
thiagoralves merged 2 commits into
developmentfrom
feat/modbus-tcp-slave-id
Jan 19, 2026
Merged

feat: Add Slave ID support for Modbus TCP master plugin#79
thiagoralves merged 2 commits into
developmentfrom
feat/modbus-tcp-slave-id

Conversation

@thiagoralves
Copy link
Copy Markdown
Contributor

Summary

  • 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
  • Default value is 1 for backward compatibility with existing configurations

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, 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

  • Test with Modbus TCP device directly (slave_id = 1)
  • Test with Modbus TCP gateway forwarding to RS485 devices with different slave IDs
  • Verify backward compatibility with existing configurations without slave_id
  • Verify validation rejects invalid slave_id values (<0 or >255)

🤖 Generated with Claude Code

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>
@thiagoralves thiagoralves requested a review from Copilot January 19, 2026 17:18
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_id field to ModbusDeviceConfig with validation for values 0-255
  • Updated ModbusConnectionManager to 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 slave parameter

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>
@thiagoralves thiagoralves merged commit 94cd393 into development Jan 19, 2026
1 check passed
@thiagoralves thiagoralves deleted the feat/modbus-tcp-slave-id branch January 19, 2026 18:08
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.

2 participants