Exemplo n.º 1
1
  public static void reportSlaveIdTest(ModbusMaster master, int slaveId) {
    try {
      ReportSlaveIdRequest request = new ReportSlaveIdRequest(slaveId);
      ReportSlaveIdResponse response = (ReportSlaveIdResponse) master.send(request);

      if (response.isException())
        System.out.println("Exception response: message=" + response.getExceptionMessage());
      else System.out.println(Arrays.toString(response.getData()));
    } catch (ModbusTransportException e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 2
0
  public static void writeCoilsTest(ModbusMaster master, int slaveId, int start, boolean[] values) {
    try {
      WriteCoilsRequest request = new WriteCoilsRequest(slaveId, start, values);
      WriteCoilsResponse response = (WriteCoilsResponse) master.send(request);

      if (response.isException())
        System.out.println("Exception response: message=" + response.getExceptionMessage());
      else System.out.println("Success");
    } catch (ModbusTransportException e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 3
0
  public static void readDiscreteInputTest(ModbusMaster master, int slaveId, int start, int len) {
    try {
      ReadDiscreteInputsRequest request = new ReadDiscreteInputsRequest(slaveId, start, len);
      ReadDiscreteInputsResponse response = (ReadDiscreteInputsResponse) master.send(request);

      if (response.isException())
        System.out.println("Exception response: message=" + response.getExceptionMessage());
      else System.out.println(Arrays.toString(response.getBooleanData()));
    } catch (ModbusTransportException e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 4
0
  public static void writeMaskRegisterTest(
      ModbusMaster master, int slaveId, int offset, int and, int or) {
    try {
      WriteMaskRegisterRequest request = new WriteMaskRegisterRequest(slaveId, offset, and, or);
      WriteMaskRegisterResponse response = (WriteMaskRegisterResponse) master.send(request);

      if (response.isException())
        System.out.println("Exception response: message=" + response.getExceptionMessage());
      else System.out.println("Success");
    } catch (ModbusTransportException e) {
      e.printStackTrace();
    }
  }