Using a mixture of standard and custom response/request classes in a synchronous serial client #2789
Unanswered
pfsysadmin
asked this question in
Help
Replies: 1 comment 1 reply
-
You can have multiple custom requests, but if the function code is the same as a standard one, you overwrite the standard ! Same goes for responses, if you define an existing function code, the standard function is no longer available. To send a custom request you need to use client.execute |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
@janiversen , thank you for the pymodbus package.
I'm new to Modbus (and python) so it's taking me some time to learn them.
I have a requirement to interface with a particular measuring instrument via Modbus over an RS-485 connection.
I have determined by monitoring the serial traffic that the instrument uses a mixture of standard and custom Modbus function code requests and responses. In order to cope with this I thought I would create custom response and request classes based on the standard pymodbus ModbusResponse and ModbusRequest classes and registering the custom response class using the .register() function.
I was wondering it is possible to use both standard and custom function responses/requests in the same program?
From my investigations so far, the custom one works but when I then call the standard Modbus read_holding_registers(), I see from the debug logs it is using the custom response class (Factory Response[GetConfigCustomModbusResponse': 3]) instead of Factory Response[ReadHoldingRegistersResponse': 3].
If I don't do the .register(GetConfigCustomModbusResponse), the standard _read_holding_registers function works for the particular function code 0x3 request.
I have probably not done the sub class creation from the base class properly or made some other mistake(s). Sub class code follows.
class GetConfigCustomModbusResponse(ModbusResponse):
function_code = 3
_rtu_frame_size = 15
_rtu_byte_count_pos = 3
followed by the various encode decode, etc def's.
There is only one .register(GetConfigCustomMopdbusResponse) call.
I look forward to comments, etc,
Regards
Paul
Beta Was this translation helpful? Give feedback.
All reactions