create a ModbusClient instance
try {
    const string hostname = “hostname”;
    const int portnumber = 502;
    ModbusSocketParameters connectionParams = new ModbusSocketParameters(hostname, portnumber, ModbusType.TCP);
    IModbusClient client = ModbusClientFactory.GetInstance().Create(connectionParams);
} catch (ModbusException e) {
//handle exception
}
 Make synchronous call
var slaveId = 0xFF;//identity of the device is -1 in the case of Modbus TCP/UDP
var address = 100; //address is the address of register in Modbus device 
var quantity = 12; //quantity is the number of registers to be accessed in Modbus device
var convertToHex = true; //true is to say whether the value of address to be converted as hex value or not
//synchronous call
Response response = client.Submit(new ReadCoils(slaveId, address, quantity, convertToHex)).Get();
if (response is ModbusSuccessResponse success)
{
   byte[] data = success.GetData(); 
    // raw bytes received from the Modbus device as a success response 
    //use the utility methods to convert the raw bytes into meaningful data 
    // if the raw bytes to be converted as floats 
   float[] floatValues = ModbusUtil.ToFloatValue(data, false, true); //raw bytes, byteSwap, wordSwap 
    // or if the raw bytes to be converted as integers 
   int[] intValues = ModbusUtil.ToIntValue(data, false, true);
}
else if (response is ModbusErrorResponse error) 
{
    byte errorcode = error.GetErrorCode();
    String errMessage = error.GetErrorMessage();
}
create a ModbusClient instance
try {
    String hostname = “hostname”;
    int portnumber = 502;
    ModbusSocketParameters connectionParams = new ModbusSocketParameters(hostname, portnumber, ModbusType.TCP);
    ModbusClient client = ModbusClientFactory.getInstance().create(connectionParams);
} catch (ModbusException e) {
//handle exception
}
 Make synchronous call
int slaveId = 0xFF;//identity of the device is -1 in the case of Modbus TCP/UDP
int address = 100; //address is the address of register in Modbus device 
int quantity = 12; //quantity is the number of registers to be accessed in Modbus device
boolean convertToHex = true; //true is to say whether the value of address to be converted as hex value or not
//synchronous call
Response response = client.submit(new ReadCoils(slaveId, address, quantity, convertToHex)).get();  
if (response instanceof ModbusSuccessResponse)
{
   byte[] data = success.getData(); 
   // raw bytes received from the Modbus device as a success response 
   //use the utility methods to convert the raw bytes into meaningful data 
   // if the raw bytes to be converted as floats 
  float[] floatValues = ModbusUtil.toFloatValue(data, false, true); //raw bytes, byteSwap, wordSwap 
   // or if the raw bytes to be converted as integers 
  int[] intValues = ModbusUtil.toIntValue(data, false, true);
}
else if (response instanceof ModbusErrorResponse) 
{
   byte errorcode = error.getErrorCode();
   String errMessage = error.getErrorMessage();
}