예제 #1
0
  // ChannelPutRequester
  @Override
  public void channelPutConnect(
      final Status status, final ChannelPut channelPut, final Structure structure) {
    if (!status.isSuccess()) {
      error = new Exception("Failed to connect 'put' for " + pv.getName() + ": " + status);
      updates.countDown();
      return;
    }

    try {
      final PVStructure write_structure =
          PVDataFactory.getPVDataCreate().createPVStructure(structure);
      final BitSet bit_set = new BitSet(write_structure.getNumberFields());

      // Locate the value field at deepest level in structure
      PVField field = null;
      PVStructure search = write_structure;
      while (search != null) {
        final PVField[] fields = search.getPVFields();
        if (fields.length != 1)
          throw new Exception(
              "Can only write to simple struct.element.value path, got " + structure);
        if (fields[0].getFieldName().equals("value")) {
          field = fields[0];
          break;
        } else if (fields[0] instanceof PVStructure) search = (PVStructure) fields[0];
        else search = null;
      }
      if (field == null) throw new Exception("Cannot locate 'value' to write in " + structure);

      // Enumerated? Write to value.index
      if (field instanceof PVStructure && "enum_t".equals(field.getField().getID()))
        field = ((PVStructure) field).getSubField("index");

      // Indicate what's changed & change it
      bit_set.set(field.getFieldOffset());
      PVStructureHelper.setField(field, new_value);

      // Perform write
      channelPut.put(write_structure, bit_set);
    } catch (Exception ex) {
      logger.log(Level.WARNING, "Failed to write " + pv.getName() + " = " + new_value, ex);
      error = new Exception("Failed to write " + pv.getName() + " = " + new_value, ex);
      updates.countDown();
    }
  }
예제 #2
0
  /* (non-Javadoc)
   * @see org.epics.pvaccess.client.ChannelPutRequester#channelPutConnect(org.epics.pvdata.pv.Status, org.epics.pvaccess.client.ChannelPut, org.epics.pvdata.pv.PVStructure, org.epics.pvdata.misc.BitSet)
   */
  @Override
  public void channelPutConnect(
      Status status, ChannelPut channelPut, PVStructure pvStructure, BitSet bitSet) {
    reportStatus("Failed to create ChannelPut instance", status);

    if (status.isSuccess()) {
      this.channelPut = channelPut;

      if (isChannelEnumType) {
        // handle inconsistent behavior
        this.channelPutValueField = pvStructure.getSubField("value");
        if (this.channelPutValueField instanceof PVStructure)
          this.channelPutValueField = ((PVStructure) pvStructure).getSubField("index");
      } else {
        this.channelPutValueField = pvStructure.getSubField("value");
      }

      // set BitSet
      bitSet.clear(); // re-connect case
      if (this.channelPutValueField != null) bitSet.set(channelPutValueField.getFieldOffset());
    }

    doNextWrite();
  }