private void listen() {
try {
m_Listening = true;
m_SerialCon.open();
//System.out.println("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();
}
if (Modbus.debug)
System.out.println("Request:" + request.getHexMessage());
if (Modbus.debug)
System.out.println("Response:" + response.getHexMessage());
transport.writeMessage(response);
count();
} catch (ModbusIOException ex) {
ex.printStackTrace();
continue;