protected static ModbusResponse readRequest(int functionCode,int register,int count){
  ModbusUDPTransaction trans;
  UDPMasterConnection connection=null;
  try {
    connection=new UDPMasterConnection(InetAddress.getByName(TestUtils.getFirstIp4Address()));
    connection.setPort(PORT);
    connection.connect();
    connection.setTimeout(500);
    ModbusRequest req=null;
switch (functionCode) {
case Modbus.READ_COILS:
      req=new ReadCoilsRequest(register,count);
    break;
case Modbus.READ_INPUT_DISCRETES:
  req=new ReadInputDiscretesRequest(register,count);
break;
case Modbus.READ_INPUT_REGISTERS:
req=new ReadInputRegistersRequest(register,count);
break;
case Modbus.READ_HOLDING_REGISTERS:
req=new ReadMultipleRegistersRequest(register,count);
break;
default :
fail(String.format("Request type %d is not supported by the test harness",functionCode));
}
req.setUnitID(UNIT_ID);
trans=new ModbusUDPTransaction(connection);
trans.setRequest(req);
trans.execute();
return trans.getResponse();
}
 catch (Exception e) {
logger.debug(e.getMessage());
}
 finally {
if (connection != null) {
connection.close();
}
}
return null;
}

protected static ModbusResponse readRequest ( int functionCode , int register , int count ) { ModbusUDPTransaction trans ; UDPMasterConnection connection = null ; try { connection = new UDPMasterConnection ( InetAddress . getByName ( TestUtils . getFirstIp4Address ( ) ) ) ; connection . setPort ( PORT ) ; connection . connect ( ) ; connection . setTimeout ( 500 ) ; ModbusRequest req = null ; switch ( functionCode ) { case Modbus . READ_COILS : req = new ReadCoilsRequest ( register , count ) ; break ; case Modbus . READ_INPUT_DISCRETES : req = new ReadInputDiscretesRequest ( register , count ) ; break ; case Modbus . READ_INPUT_REGISTERS : req = new ReadInputRegistersRequest ( register , count ) ; break ; case Modbus . READ_HOLDING_REGISTERS : req = new ReadMultipleRegistersRequest ( register , count ) ; break ; default : fail ( String . format ( "Request type %d is not supported by the test harness" , functionCode ) ) ; } req . setUnitID ( UNIT_ID ) ; trans = new ModbusUDPTransaction ( connection ) ; trans . setRequest ( req ) ; trans . execute ( ) ; return trans . getResponse ( ) ; } catch ( Exception e ) { logger . debug ( e . getMessage ( ) ) ; } finally { if ( connection != null ) { connection . close ( ) ; } } return null ; }
executes a read transaction using the function code , register and count
