deathwish88 / modbus-tk

Automatically exported from code.google.com/p/modbus-tk
Other
0 stars 0 forks source link

Suggested enhancement for modbus write callback... #15

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Would be nice if the app developer could supply a callback that is invoked as a 
result of a modbus write.

Please see attached modbus_tk/modbus.py patch (against r120).

Example use:

from modbus_tk.modbus import ModbusBlockWrite

class MBCoilWrite(ModbusBlockWrite):
  """Callback from modbus_tk library for coil writes"""

  def __init__(self, em, name, id_list):
    ModbusBlockWrite.__init__(self)
    self.em = em
    self.name = name
    self.id_list = id_list
    logger.debug("MBCoilWrite.__init__(%s, %s)" % (self.name, self.id_list))

  def __call__(self, offset, value):
    """Write method"""
    logger.debug("%s.__call__(%u, %u)" % (self.name, offset, value))
    assert(0 <= offset and offset < len(self.id_list))
    self.em.coil_write.send_cmd(self.id_list[offset], value)

Thanks,
Bob

Original issue reported on code.google.com by robert.b...@gmail.com on 11 Oct 2010 at 11:04

Attachments:

GoogleCodeExporter commented 8 years ago
Hi Bob,
Thanks for this suggestion. I think it is a good idea.
The callback mechanism in modbus_tk are implemented with hooks (see hooks.py)
I 'll add a new hook when writing into a block.
Does it meet your need?
Best Regards
luc

Original comment by luc.jean@gmail.com on 12 Oct 2010 at 5:59

GoogleCodeExporter commented 8 years ago

Original comment by luc.jean@gmail.com on 12 Oct 2010 at 5:59

GoogleCodeExporter commented 8 years ago
I've created a new hook that make possible I think to implement your wish. 

Please get the new version from mercurial.

Please look at hooks.py and test/unittest_modbus.py. The testHookOnSetBlockData 
should help.

Waiting for your feedback 

Best regards

Original comment by luc.jean@gmail.com on 12 Oct 2010 at 4:15