if (!m_Terminal.isActive()) {
try {
m_Terminal.activate();
m_IO = m_Terminal.getModbusTransport();
} catch (Exception ex) {
throw new ModbusIOException("Activation failed.");
}
}
//3. Retry transaction m_Retries times, in case of
//I/O Exception problems.
m_RetryCounter = 0;
while (m_RetryCounter <= m_Retries) {
try {
//toggle the id
m_Request.setTransactionID(c_TransactionID.increment());
//3. write request, and read response,
// while holding the lock on the IO object
synchronized (m_IO) {
//write request message
m_IO.writeMessage(m_Request);
//read response message
m_Response = m_IO.readResponse();
break;
}
} catch (ModbusIOException ex) {
m_RetryCounter++;
continue;
}
}
//4. deal with "application level" exceptions
if (m_Response instanceof ExceptionResponse) {
throw new ModbusSlaveException(
((ExceptionResponse) m_Response).getExceptionCode()
);
}
if (isCheckingValidity()) {
checkValidity();
}
} catch (InterruptedException ex) {
throw new ModbusIOException("Thread acquiring lock was interrupted.");
} finally {
m_TransactionLock.release();
}
}//execute