public ModbusResponse createResponse() {
    WriteSingleRegisterResponse response = null;
    Register reg = null;

    // 1. get process image
    ProcessImage procimg = ModbusCoupler.getReference().getProcessImage();
    // 2. get register
    try {
      reg = procimg.getRegister(m_Reference);
      // 3. set Register
      reg.setValue(m_Register.toBytes());
    } catch (IllegalAddressException iaex) {
      return createExceptionResponse(Modbus.ILLEGAL_ADDRESS_EXCEPTION);
    }
    response = (WriteSingleRegisterResponse) getResponse();

    return response;
  }
Beispiel #2
0
 @Override
 public void init(ProtocolParams params) {
   ModbusCoupler.getReference().setUnitID(128);
   SerialParameters SerialParams = new SerialParameters();
   if (params instanceof ModbusMasterParams) {
     ModbusMasterParams mbParams = (ModbusMasterParams) params;
     SerialParams.setPortName(mbParams.getPortName());
     SerialParams.setBaudRate(mbParams.getBaudRate());
     SerialParams.setDatabits(mbParams.getDataBits());
     SerialParams.setParity(mbParams.getParity());
     SerialParams.setStopbits(mbParams.getStopbits());
     SerialParams.setEncoding(mbParams.getEncoding());
     SerialParams.setEcho(mbParams.getEcho());
     this.timePause = mbParams.getTimePause();
     con = new SerialConnection(SerialParams);
     logger.debug(this.name + " initialize.");
   } else {
     logger.error("Объект параметров не является объектом класса ModbusMasterParams");
   }
 }