Skip to content
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

Modbus ID change - Wrong return slave address #101

Open
somakelemen opened this issue May 5, 2023 · 3 comments · May be fixed by #130
Open

Modbus ID change - Wrong return slave address #101

somakelemen opened this issue May 5, 2023 · 3 comments · May be fixed by #130
Labels
Usage Usage questions

Comments

@somakelemen
Copy link

Hi,

I have a small script which change the slave default Modbus ID to another one (from 1 to 23 or any other unused ID) via write_register().
My issue is when it's done I got the following "error" which is right but basically this was the goal.

minimalmodbus.InvalidResponseError: Wrong return slave address: 23 instead of 1. The response is: '\x17\x06@\x03\x00\x17.ò'

I am using,
Python 3.9.2
minimalmodbus 2.0.1

Are there any option to override the expected slave address?

@pyhys pyhys added the Usage Usage questions label Jul 4, 2023
@pyhys
Copy link
Owner

pyhys commented Jul 4, 2023

Maybe you can just silence the error for that particular write:

try:
    instrument.write_register(24, NEW_TEMPERATURE, 1) 
except minimalmodbus.InvalidResponseError:
    pass

@penguintamer
Copy link

Another time disabling return slave address checking would be useful: accessing single connected devices by their "universal" address such as 0xF7 or 0xFF.

Unfortunately, silencing errors with a try block has the unfortunate side effect of making the value returned from the Instrument unusable except by trying to parse the string that comes back in the error. So a simple pattern like using the universal address to query the register that contains the device's real address won't work.

@Janl1
Copy link

Janl1 commented Apr 1, 2024

In my case I wanted to change the slave address of an Epever XTRA3210N Solar Charge Controller.

With some reverse engineering of the official Epever software I found out that you cannot change the slave address to a normal register value, but you can use the function code 69 to change it.

I used the following line of code to change the address. It will probably return an error message because it cannot parse the result, but the change went through in my case.

instrument._perform_command(69, instrument._num_to_onebyte_string(newId)) (minimalmodbus v2.0.1)

Please keep in mind that the function code might be different depending on the device and that playing around with undocumented function codes can break the communication with the device.

@penguintamer penguintamer linked a pull request Apr 4, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Usage Usage questions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants