Starting from revision 24 the line 186 of the file ModbusTCPTransaction.java changed from while(retryCounter<=m_Retries) to while(retryCounter<m_Retries). This introduced a bug, because the condition if(retryCounter==m_Retries) into the catch() block will be always false.
. . .
} catch (ModbusIOException ex) {
if (retryCounter == m_Retries) {
throw new ModbusIOException("Executing transaction failed (tried " + m_Retries + " times)");
} else {
retryCounter++;
continue;
}
}
. . .
This produce a wrong behavior in case of connection fault because the execute() method will return without exception and the ModbusTCPTransaction.getResponse() will return the m_response obtained during previus call to the method execute().
To simulate the bug do the following:
1. Connect to a modbus server
2. Use ModbusTCPTransaction.execute() in loop for reading a register from the server
3. Quit the modbus server and keep looping with the ModbusTCPTransaction.execute()
4. BUG: the ModbusTCPTransaction.execute() returns without throwing exceptions, and the ModbusTCPTransaction.getResponse() reports a response even if the connection is not active anymore
Many thanks in advance for your attention.
Regards,
Angelo
I'm fairly confident this bug is not present in j2mod.
The issue is that Modbus/TCP has a different error recovery path than Modbus/RTU, because Modbus/TCP is based on a connection-oriented transport.