'Unable to establish connection with Pymodbus TCPserver

I am setting up a new TCP Server connected to client through an Ethernet TCP/IP modbus and is supposed to push certain values to a given modbus register (hr = 6022), every few seconds. I do not see any exceptions/errors raised by the script but no data is received by the client. With a StartTCPserver command, I expected to see any network traffic (atleast the handshake) but I do not see any traffic on Wireshark. What could be the next possible diagnostic?

I have tried running similar script locally (without an external ethernet connection); One acting as a client and another as a server and did see the values update on the client register.

from pymodbus.server.sync import StartTcpServer
from pymodbus.device import ModbusDeviceIdentification
from pymodbus.datastore import ModbusSequentialDataBlock
from pymodbus.datastore import ModbusSlaveContext, ModbusServerContext
import time
import logging
FORMAT = ('%(asctime)-15s %(threadName)-15s'
          ' %(levelname)-8s %(module)-15s:%(lineno)-8s %(message)s')
logging.basicConfig(format=FORMAT)
log = logging.getLogger()
log.setLevel(logging.DEBUG)


def run_server():
    store = ModbusSlaveContext(
        ir=ModbusSequentialDataBlock(6022, [152, 276]), 
        zero_mode=True
    )
    context = ModbusServerContext(slaves=store, single=True)
    StartTcpServer(context, address=("192.168.10.2", 502))


if __name__ == "__main__":
    run_server()


Solution 1:[1]

The lines after run_server() are never reached. Code connecting to the server can be placed in a different script;

from pymodbus.client.sync import ModbusTcpClient as ModbusClient     

cli = ModbusClient('192.168.10.2', port=502)                       
assert cli.connect()                                                 
res = cli.read_input_registers(6022, count=1, unit=1)                
print(res.registers[0]) 

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Bosz