Using a mixture of standard and custom response/request classes in a synchronous serial client #2789
-
|
@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. 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.
Replies: 2 comments 4 replies
-
|
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.
-
|
Yes make a custom class with 0x03 and in decode/encode methods call the standard one if it is a standard request/response |
Beta Was this translation helpful? Give feedback.
Passing another parameter will not help you with the responses.
You cannot unregister a custom class, it does not make sense, but of course you can stop the special handling in your code.
For pointers have a look at our examples.