We have upgraded the community system as part of the upgrade a password reset is required for all users before login in.

i am getting pymodbus 502 connection refused.



  • @Lazar-Demin
    can you please help me i am getting pymodbus port 502 connection refused?. what could be the issue?.

    from pymodbus.client.sync import ModbusTcpClient
    import time
    import logging
    logging.basicConfig()
    log = logging.getLogger()
    log.setLevel(logging.DEBUG)
    host = '192.168.0.200'
    port = 502

    client = ModbusTcpClient(host,502)
    client.connect()
    while True:
    rr = client.read_holding_registers(0x0001,2,unit=2)
    print(rr)
    #assert(rr.function_code < 0x80) # test that we are not an error
    #print rr.registers
    time.sleep(5)

    error:
    root@Omega-6834:~# python modbus_ip.py
    ERROR:pymodbus.client.sync:Connection to (192.168.0.200, 502) failed: timed out
    ERROR:pymodbus.client.sync:Connection to (192.168.0.200, 502) failed: timed out
    Traceback (most recent call last):
    File "modbus_ip.py", line 13, in <module>
    rr = client.read_holding_registers(0x0001,2,unit=2)
    File "/usr/lib/python2.7/site-packages/pymodbus/client/common.py", line 114, in read_holding_registers
    return self.execute(request)
    File "/usr/lib/python2.7/site-packages/pymodbus/client/sync.py", line 107, in execute
    raise ConnectionException("Failed to connect[%s]" % (self.str()))
    pymodbus.exceptions.ConnectionException: Modbus Error: [Connection] Failed to connect[ModbusTcpClient(192.168.0.200:502)]
    Note: i am able to pinging 192.168.0.200 this IPaddress.



  • @Nagarjuna-Reddy This suggests that port 502 is not open on IP 192.168.0.200. Is the service running on that device on that IP and port? Is there a firewall in place?

    A good test is to try to telnet to that IP and port, but. You'll need to provide more specifics of your setup if you need more help but check the above.



  • @crispyoz sir it was working previously, while working time suddenly I got this issue. but here i am able to ping the device IP. using telnet port forbidden error happening. I was done onion restart after also port was not opened. after done Modbus device restart port was opened. Is there any way to kill that 502 port issue from terminal side?



  • @Nagarjuna-Reddy I suspect the issue is that when you connect to the Modbus host then disconnect, the port on the host is not closed and the device can only accept a single connection. So you need to make sure that you close the port on the client side each time you or subsequent connections will fail.

    I'm making some assumptions here because I don't have details of the host device, but the logic is sound.



Looks like your connection to Community was lost, please wait while we try to reconnect.