public ModbusRequest buildDiagnostics ( DiagnosticsSubFunctionCode subFunctionCode , int serverAddress , int data ) throws ModbusNumberException { DiagnosticsRequest request = new DiagnosticsRequest ( ) ; request . setServerAddress ( serverAddress ) ; request . setSubFunctionCode ( subFunctionCode ) ; request . setSubFunctionData ( data ) ; return request ; }
The function uses a sub - function code field in the query to define the type of test to be performed . The server echoes both the function code and sub - function code in a normal response . Some of the diagnostics cause data to be returned from the remote device in the data field of a normal response .