MangoAutomation/modbus4j

Network reconnection does not yield data

continuefly opened this issue · 1 comments

When the network is disconnected, data cannot be re connected and data can not be obtained after reconnection ,so i find one bug , change TcpMaster class is ok !

here !

try {
LOG.debug("Modbus4J: Keep-alive connection may have been reset. Attempting to re-open.");
openConnection();
ipResponse = (IpMessageResponse) conn.send(ipRequest);
if (ipResponse == null)
return null;
if(LOG.isDebugEnabled()){
StringBuilder sb = new StringBuilder();
for (byte b : Arrays.copyOfRange(ipResponse.getMessageData(),0,ipResponse.getMessageData().length)) {
sb.append(String.format("%02X ", b));
}
LOG.debug("Response: " + sb.toString());
}
return ipResponse.getModbusResponse();
}
catch (Exception e2) {
// ====================add one line code is ok ===================
closeConnection();
LOG.debug("Exception: " + e2.getMessage() + " " + e2.getLocalizedMessage());
throw new ModbusTransportException(e2, request.getSlaveId());
}

Thanks for finding that!