MangoAutomation / modbus4j

A high-performance and ease-of-use implementation of the Modbus protocol written in Java. Supports ASCII, RTU, TCP, and UDP transports as slave or master, automatic request partitioning and response data type parsing.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Network reconnection does not yield data

continuefly opened this issue · 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!