private void getRequest ( int function , BytesOutputStream out ) throws IOException { int byteCount ; byte inpBuf [ ] = new byte [ 256 ] ; try { if ( ( function & 0x80 ) == 0 ) { switch ( function ) { case Modbus . READ_EXCEPTION_STATUS : case Modbus . READ_COMM_EVENT_COUNTER : case Modbus . READ_COMM_EVENT_LOG : case Modbus . REPORT_SLAVE_ID : readRequestData ( 0 , out ) ; break ; case Modbus . READ_FIFO_QUEUE : readRequestData ( 2 , out ) ; break ; case Modbus . READ_MEI : readRequestData ( 3 , out ) ; break ; case Modbus . READ_COILS : case Modbus . READ_INPUT_DISCRETES : case Modbus . READ_MULTIPLE_REGISTERS : case Modbus . READ_INPUT_REGISTERS : case Modbus . WRITE_COIL : case Modbus . WRITE_SINGLE_REGISTER : readRequestData ( 4 , out ) ; break ; case Modbus . MASK_WRITE_REGISTER : readRequestData ( 6 , out ) ; break ; case Modbus . READ_FILE_RECORD : case Modbus . WRITE_FILE_RECORD : byteCount = readByte ( ) ; out . write ( byteCount ) ; readRequestData ( byteCount , out ) ; break ; case Modbus . WRITE_MULTIPLE_COILS : case Modbus . WRITE_MULTIPLE_REGISTERS : readBytes ( inpBuf , 4 ) ; out . write ( inpBuf , 0 , 4 ) ; byteCount = readByte ( ) ; out . write ( byteCount ) ; readRequestData ( byteCount , out ) ; break ; case Modbus . READ_WRITE_MULTIPLE : readRequestData ( 8 , out ) ; byteCount = readByte ( ) ; out . write ( byteCount ) ; readRequestData ( byteCount , out ) ; break ; default : throw new IOException ( String . format ( "getResponse unrecognised function code [%s]" , function ) ) ; } } } catch ( IOException e ) { throw new IOException ( "getResponse serial port exception" ) ; } }
getRequest - Read a request after the unit and function code