code: public boolean maskWriteRegister(int unitId, int ref, int andMask, int orMask) throws ModbusException {
          checkTransaction();
          if (maskWriteRegisterRequest == null) {
              maskWriteRegisterRequest = new MaskWriteRegisterRequest();
          }
          maskWriteRegisterRequest.setUnitID(unitId);
          maskWriteRegisterRequest.setReference(ref);
          maskWriteRegisterRequest.setAndMask(andMask);
          maskWriteRegisterRequest.setOrMask(orMask);
          transaction.setRequest(maskWriteRegisterRequest);
          transaction.execute();
  
          MaskWriteRegisterResponse response = (MaskWriteRegisterResponse) getAndCheckResponse();
          return response.getReference() == maskWriteRegisterRequest.getReference() &&
                 response.getAndMask() == maskWriteRegisterRequest.getAndMask() &&
                 response.getOrMask() == maskWriteRegisterRequest.getOrMask();
      }
docs: Mask write a single register to the slave.
  
  @param unitId    the slave unit id.
  @param ref       the offset of the register to start writing to.
  @param andMask   AND mask.
  @param orMask    OR mask.
  
  @return true if success, i.e. response data equals to request data, false otherwise.
  
  @throws ModbusException if an I/O error, a slave exception or
  a transaction error occurs.