public void readData(DataInput din) throws IOException {
    setByteCount(din.readUnsignedByte());

    InputRegister[] registers = new InputRegister[getWordCount()];
    ProcessImageFactory pimf = ModbusCoupler.getReference().getProcessImageFactory();
    for (int k = 0; k < getWordCount(); k++) {
      registers[k] = pimf.createInputRegister(din.readByte(), din.readByte());
    }
    m_Registers = registers;
    // update data length
    setDataLength(getByteCount() + 1);
  } // readData
  public void readData(DataInput din) throws IOException {

    m_Reference = din.readShort();
    // read lengths
    int wc = din.readUnsignedShort();
    int bc = din.readUnsignedByte();

    // read values
    if (m_NonWordDataHandler == null) {
      m_Registers = new Register[wc];
      ProcessImageFactory pimf = ModbusCoupler.getReference().getProcessImageFactory();
      for (int i = 0; i < wc; i++) {
        m_Registers[i] = pimf.createRegister(din.readByte(), din.readByte());
      }
    } else {
      m_NonWordDataHandler.readData(din, m_Reference, wc);
    }
  } // readData
  public ModbusResponse createResponse() {
    WriteMultipleRegistersResponse response = null;

    if (m_NonWordDataHandler == null) {
      Register[] regs = null;
      // 1. get process image
      ProcessImage procimg = ModbusCoupler.getReference().getProcessImage();
      // 2. get registers
      try {
        // TODO: realize a setRegisterRange()?
        regs = procimg.getRegisterRange(this.getReference(), this.getWordCount());
        // 3. set Register values
        for (int i = 0; i < regs.length; i++) {
          regs[i].setValue(this.getRegister(i).toBytes());
        }
      } catch (IllegalAddressException iaex) {
        return createExceptionResponse(Modbus.ILLEGAL_ADDRESS_EXCEPTION);
      }
      response = new WriteMultipleRegistersResponse(this.getReference(), regs.length);
    } else {
      int result = m_NonWordDataHandler.commitUpdate();
      if (result > 0) {
        return createExceptionResponse(result);
      }
      response =
          new WriteMultipleRegistersResponse(
              this.getReference(), m_NonWordDataHandler.getWordCount());
    }
    // transfer header data
    if (!isHeadless()) {
      response.setTransactionID(this.getTransactionID());
      response.setProtocolID(this.getProtocolID());
    } else {
      response.setHeadless();
    }
    response.setUnitID(this.getUnitID());
    response.setFunctionCode(this.getFunctionCode());
    return response;
  } // createResponse
  public ModbusResponse createResponse() {
    ReadInputRegistersResponse response = null;
    InputRegister[] inpregs = null;

    // 1. get process image
    ProcessImage procimg = ModbusCoupler.getReference().getProcessImage();
    // 2. get input registers range
    try {
      inpregs = procimg.getInputRegisterRange(this.getReference(), this.getWordCount());
    } catch (IllegalAddressException iaex) {
      return createExceptionResponse(Modbus.ILLEGAL_ADDRESS_EXCEPTION);
    }
    response = new ReadInputRegistersResponse(inpregs);
    // transfer header data
    if (!isHeadless()) {
      response.setTransactionID(this.getTransactionID());
      response.setProtocolID(this.getProtocolID());
    } else {
      response.setHeadless();
    }
    response.setUnitID(this.getUnitID());
    response.setFunctionCode(this.getFunctionCode());
    return response;
  } // createResponse