Skip to content

Custom Response Class registration lost due to ModbusFramer being inialized multiple times #1146

@wlcrs

Description

@wlcrs

Versions

  • Python: 3.10.2
  • OS: Ubuntu 20.04
  • Pymodbus: 3.0.0
  • Modbus Hardware (if used):

Pymodbus Specific

  • Client: tcp async

Description

I'm trying to upgrade to 3.0.0, but run into trouble with registering my custom response class.

I do this like this:

client = AsyncModbusTcpClient(host,   port,     framer=ModbusSocketFramer)
client.register(PrivateHuaweiModbusResponse)   

This correctly adds the response to the client.framer.decoder.__lookup table

However, upon callling client.connect(), I see that in AsyncModbusTcpClient._create_protocol, it does not pass client.framer to the ModbusClientProtocol, but instead the self.params.framer:

       protocol = ModbusClientProtocol(framer=self.params.framer, **self.params.kwargs)

In the protocol-object, the framer is initialized again, without the custom response class this time.

I'm very confused about how both AsyncModbusTcpClient and ModbusClientProtocol have ModbusBaseClient as a parent class. Would it not be more appropriate to remove ModbusBaseClient as a parent class from ModbusClientProtocol and pass the client-object creating the ModbusClientProtocol to it instead?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions