-
Notifications
You must be signed in to change notification settings - Fork 25
Feature 107: Support multiple units on one connection #108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Modernizes the Modbus terminology by using "unit ID" throughout the codebase. This addresses issue sunspec#105 by: - Renaming parameters and variables to unit_id - Updating method signatures while maintaining backward compatibility - Revising documentation and comments to reflect current industry standards - Ensuring consistent terminology across the entire Modbus implementation This change improves code readability and aligns with current Modbus specification terminology while maintaining full backward compatibility.
Updates test cases to align with the modernized unit ID terminology. Ensures all tests properly exercise the updated API while maintaining complete test coverage include backward compatibility tests.
Implements the ability to communicate with multiple Modbus devices sharing the same TCP/RTU connection but with different unit IDs. This addresses issue sunspec#107 by: - Adding SunSpecModbusClientUnit class to represent a specific unit ID - Creating SunSpecModbusClientUnitCollection for managing units - Adding scan_units method to discover models on specific unit IDs - Implementing read_unit and write_unit methods for unit-specific operations - Ensuring proper delegation of Modbus commands to the parent device This change enables users to interact with multiple logical devices on a single physical connection while maintaining the same API interface.
Adds comprehensive test cases for the new multiple unit ID functionality. Verifies proper behavior of unit scanning, reading, and writing across different unit IDs on the same connection.
Updates documentation to explain the new multiple unit ID functionality. Includes usage examples, API references, and best practices for working with multiple logical devices on a single connection.
There has been a lot of discussion about the use of, and need for, the unit ID with TCP devices. I didn't realize that SolarEdge was using a gateway in this way. What's the biggest benefit of this functionality over this approach:
I suppose in the future case where we may have encrypted connections to equipment, this may reduce the number of TLS handshakes to the gateway? |
SolarEdge only supports a single TCP connection and session, see p. 13 of https://knowledge-center.solaredge.com/sites/kc/files/sunspec-implementation-technical-note.pdf Creating multiple devices would work if you only ever used one connection at a time. i.e. if you used the automatic connect/disconnect. But it doesn't work if you want to use connect(), then do a bunch of operations across multiple connections. Having child devices of the main connection (i.e. multiple units across one connection) avoids this issue. The unit ID is just a parameter sent in messages, so this works fine. There is also a mention in the documentation of a connection idle time of 2 mins, which originally I thought meant you had to wait 2 mins before you could make the second connection, because I was having a lot of trouble using HA-sunspec to connect twice to the same IP address (the whole driver for this). Although I'm not sure now if that is the issue, as the connection to unit 2 just seems flakey (even if it is the only one). But I've already done the work, so thought I might as well submit the PR. |
Overview
This PR implements support for communicating with multiple Modbus devices sharing a single connection but with different unit IDs. This is particularly useful for gateway devices that expose multiple logical devices through a single TCP connection (such as some SolarEdge configurations).
Features
Units
collectionscan_units([unit_ids])
method to discover models on multiple unitsread_unit()
andwrite_unit()
methods for direct register accessExample Usage
Implementation Details
SunSpecModbusClientUnit
class that acts as a proxy for a specific unit IDSunSpecModbusClientUnitCollection
to manage and provide access to unitsCloses
Closes #107