use of net.wimpi.modbus.io.ModbusTransport in project openhab1-addons by openhab.
the class ModbusSerialListener method listen.
/**
* Listen to incoming messages.
*/
private void listen() {
try {
m_Listening = true;
m_SerialCon.open();
logger.trace("Opened Serial connection.");
ModbusTransport transport = m_SerialCon.getModbusTransport();
do {
if (m_Listening) {
try {
// 1. read the request
ModbusRequest request = transport.readRequest();
ModbusResponse response = null;
// test if Process image exists
if (ModbusCoupler.getReference().getProcessImage() == null) {
response = request.createExceptionResponse(Modbus.ILLEGAL_FUNCTION_EXCEPTION);
} else {
response = request.createResponse();
}
logger.debug("Request:{}", request.getHexMessage());
logger.debug("Response:{}", response.getHexMessage());
transport.writeMessage(response);
count();
} catch (ModbusIOException ex) {
ex.printStackTrace();
continue;
}
}
// ensure nice multithreading behaviour on specific platforms
} while (true);
} catch (Exception e) {
// FIXME: this is a major failure, how do we handle this
e.printStackTrace();
}
}
Aggregations