When using Modbus, if no read polling is provided (client FB use only to perform Modbus write), client FB keeps on opening TCP connection to the Modbus TCP server.
Root cause in the code: in modbusclientconnection.cpp, in CModbusClientConnection::tryPolling method, there is a check at the end :
if((nrErrors == m_nNrOfPolls)
in case m_nNrOfPolls and nrErrors are both equal to 0, the flag m_bConnected is set to false...
My suggestion would be the following:
if((nrErrors == m_nNrOfPolls) && (m_nNrOfPolls != 0)) {
modbus_close(m_pModbusConn); // in any case it is worth trying to close the socket
m_bConnected = false;
m_pModbusConnEvent = new CModbusConnectionEvent(1000); // changed to 1000 as set at startup
m_pModbusConnEvent->activate();
}
Thanks for findiing this issue. I applied your proposed solution. It is available here: http://git.eclipse.org/c/4diac/org.eclipse.4diac.forte.git/commit/?h=1.8.x&id=4ede9e4a7ef83cb900c2392dc392c66ef06c6915