Jump to content

Ofer

Members
  • Posts

    5
  • Joined

  • Last visited

Posts posted by Ofer

  1. some help from friends and this forum - here is the last version of the controller side

    first added the close every 3 minutes - did not do the trick but helped a bit so i keep it there

    init the card socket and port and set tcp keep, link lost and connection gave a stable read even when power or cable momentarily removed

     

    conecting modbus stable version.jpg

  2. Im just a nube so it took me a while to figure it out.

    on the unitronix side assign a slave to one of the ports like this

    image.png.c7d12414fa5fbcb709ca47e5a826a9d0.png

    on the python side read data with something like this

    import modbus_tk
    import modbus_tk.defines as cst
    import modbus_tk.modbus as modbus
    import modbus_tk.modbus_tcp as modbus_tcp
    import logging
    
    logger = modbus_tk.utils.create_logger("console", level=logging.DEBUG)
    
    master = modbus_tcp.TcpMaster(host='172.21.2.183', port=20257, timeout_in_sec=5.0)
    master.open
    actual_bits = master.execute(slave=1, function_code=cst.READ_COILS, starting_address=1, quantity_of_x=2)
    print("actual_bits =", actual_bits)
    
    master.close

    remember the slave number!

    Hope this helps someone

     

×
×
  • Create New...