pyModbusTCP icon indicating copy to clipboard operation
pyModbusTCP copied to clipboard

on_coils_change and on_holding_registers_change methods don't have callbacks

Open EzequielMarcelo opened this issue 10 months ago • 1 comments

  • The idea would be to trigger external functions when triggering these events to avoid the user having to enter the library to access the methods.
def OnCoilsChange(address, from_value, to_value, srv_info):
        """
        :param address: address of coil
        :type address: int
        :param from_value: coil original value
        :type from_value: bool
        :param to_value: coil next value
        :type to_value: bool
        :param srv_info: some server info
        :type srv_info: ModbusServerInfo
        """
        pass

def OnHoldingRegistersChange(address, from_value, to_value, srv_info):
        """
        :param address: address of register
        :type address: int
        :param from_value: register original value
        :type from_value: int
        :param to_value: register next value
        :type to_value: int
        :param srv_info: some server info
        :type srv_info: ModbusServerInfo
        """
        pass


server = ModbusServer(modbusServerAddr, modbusServerPort, no_block=True)
server.on_coils_change= OnCoilsChange
server.on_holding_registers_change = OnHoldingRegistersChange

EzequielMarcelo avatar Mar 24 '25 12:03 EzequielMarcelo

Hi,

You can achieve this by implementing a custom DataBank class, as shown in the provided example:

https://github.com/sourceperl/pyModbusTCP/blob/47675dcb865c81fbfbcdea9eb75581a6f3c31b70/examples/server_change_log.py

sourceperl avatar Apr 01 '25 06:04 sourceperl