예제 #1
0
 /** PV is connected. Get meta info, or subscribe right away. */
 private void handleConnected(final Channel channel) {
   try {
     if (channel.getConnectionState() != Channel.CONNECTED) {
       return;
     }
   } catch (Exception ex) {
     logger.warn("Exception handling connection state change for " + this.name, ex);
     return;
   }
   if (state == PVConnectionState.Connected) return;
   state = PVConnectionState.Connected;
   hostName = channel_ref.getChannel().getHostName();
   totalMetaInfo.setHostName(hostName);
   for (final PVListener listener : listeners) {
     listener.pvConnected(this);
   }
   // If we're "running", we need to get the meta data and
   // then subscribe.
   // Otherwise, we're done.
   if (!running) {
     connected = true;
     // meta = null;
     synchronized (this) {
       this.notifyAll();
     }
     return;
   }
   // else: running, get meta data, then subscribe
   try {
     DBRType type = channel.getFieldType();
     if (!(plain || type.isSTRING())) {
       state = PVConnectionState.GettingMetadata;
       if (type.isDOUBLE() || type.isFLOAT()) type = DBRType.CTRL_DOUBLE;
       else if (type.isENUM()) type = DBRType.LABELS_ENUM;
       else if (type.isINT()) type = DBRType.CTRL_INT;
       else type = DBRType.CTRL_SHORT;
       channel.get(type, 1, meta_get_listener);
       return;
     }
   } catch (final Exception ex) {
     logger.error("exception when handleConnect " + name, ex);
     return;
   }
   // Meta info is not requested, not available for this type,
   // or there was an error in the get call.
   // So reset it, then just move on to the subscription.
   // meta = null;
   subscribe();
 }
 public JCAConnectionPayload(
     JCAChannelHandler channleHandler, Channel channel, JCAConnectionPayload previousPayload) {
   this.jcaDataSource = channleHandler.getJcaDataSource();
   this.channel = channel;
   this.connected =
       channel != null && channel.getConnectionState() == Channel.ConnectionState.CONNECTED;
   this.longString = channleHandler.isLongString();
   if (channel.getFieldType().getClass() == null && previousPayload != null) {
     // JNI sets the type to unknown on disconnect. We need
     // to remember the type before the disconnection
     this.fieldType = previousPayload.fieldType;
   } else {
     this.fieldType = channel.getFieldType();
   }
 }
 /**
  * @return range values
  * @throws DeviceException
  */
 public String getRangeValue() throws DeviceException {
   try {
     short test = controller.cagetEnum(chRangeRBV);
     return positions.get(test);
   } catch (Throwable th) {
     throw new DeviceException("failed to get position from " + chRangeRBV.getName(), th);
   }
 }
예제 #4
0
  @Override
  public int match(ValueCache<?> cache, JCAConnectionPayload connPayload) {
    Channel channel = connPayload.getChannel();

    // If the generated type can't be put in the cache, no match
    if (!cache.getType().isAssignableFrom(typeClass)) return 0;

    // If the type of the channel does not match, no match
    if (!dbrTypeMatch(epicsValueType, connPayload.getFieldType())) return 0;

    // If processes array, but count is 1, no match
    if (array != null && array && channel.getElementCount() == 1) return 0;

    // If processes scalar, but the count is not 1, no match
    if (array != null && !array && channel.getElementCount() != 1) return 0;

    // Everything matches
    return 1;
  }
  @Override
  public void rawAsynchronousMoveTo(Object position) throws DeviceException {
    // find in the positionNames array the index of the string
    if (positions.contains(position.toString())) {
      int target = positions.indexOf(position.toString());
      try {
        controller.caput(chRange, target, channelManager);
        Thread.sleep(1000);
      } catch (Throwable th) {
        throw new DeviceException(
            chRange.getName() + " failed to moveTo " + position.toString(), th);
      }

      return;
    }
    // if get here then wrong position name supplied
    throw new DeviceException("Position called: " + position.toString() + " not found.");
  }
예제 #6
0
 /** Subscribe for value updates. */
 private void subscribe() {
   synchronized (this) {
     // Prevent multiple subscriptions.
     if (subscription != null) {
       return;
     }
     // Late callback, channel already closed?
     final RefCountedChannel ch_ref = channel_ref;
     if (ch_ref == null) {
       return;
     }
     final Channel channel = ch_ref.getChannel();
     // final Logger logger = Activator.getLogger();
     try {
       if (channel.getConnectionState() != Channel.CONNECTED) {
         return;
       }
       //
       // the RefCountedChannel should maintain a single
       // subscription to the underlying CAJ/JCA channel.
       // So even with N PVs for the same channel, it's
       // only one subscription on the network instead of
       // N subscriptions.
       final DBRType type = DBR_Helper.getTimeType(plain, channel.getFieldType());
       state = PVConnectionState.Subscribing;
       totalMetaInfo.setStartTime(System.currentTimeMillis());
       // isnotTimestampDBR
       if (this.name.endsWith(".RTYP")) {
         subscription = channel.addMonitor(MonitorMask.ARCHIVE.getMask(), this);
       } else {
         subscription =
             channel.addMonitor(
                 type, channel.getElementCount(), MonitorMask.ARCHIVE.getMask(), this);
       }
     } catch (final Exception ex) {
       logger.error("exception when subscribing pv " + name, ex);
     }
   }
 }
 /**
  * True if the channel is not null, connected, and can be written to.
  *
  * @return true if the channel is ready for write
  */
 public boolean isWriteConnected() {
   return isChannelConnected() && channel.getWriteAccess();
 }
예제 #8
0
  /** @param channelName */
  public void execute(String channelName) {

    try {

      // initialize context
      initialize();

      // Create the Channel to connect to the PV.
      Channel channel = context.createChannel(channelName);

      // Send the request and wait 5.0 seconds for the channel to connect to the PV.
      context.pendIO(5.0);

      // If we're here, then everything went fine.
      // Display basic information about the channel.
      channel.printInfo();

      /** ***************************************************************** */
      /** *************************** sync get **************************** */
      /** ***************************************************************** */
      System.out.println("\n------------------------------------------------\n");
      System.out.println("Sync get:");

      // get request w/o callbacks will wait until flush/pendIO is called
      // (channel default 'type' and 'count' is used)
      DBR dbr = channel.get();
      context.pendIO(3.0);
      dbr.printInfo();

      System.out.println();

      dbr = channel.get(DBRType.STRING, 1);
      context.pendIO(3.0);
      String[] value = ((STRING) dbr).getStringValue();
      System.out.println("Read string value: " + value[0]);

      /** ***************************************************************** */
      /** ************************** async get **************************** */
      /** ***************************************************************** */
      System.out.println("\n------------------------------------------------\n");
      System.out.println("Async get:");

      // get request w/ callbacks are always issued immediately
      // not related to pendIO at all, but require pend_event (to be flushed also)
      GetListenerImpl listener = new GetListenerImpl();
      channel.get(listener);
      synchronized (listener) {
        // flush & get event back
        context.flushIO();
        // wait for response...
        listener.wait(3000);
      }

      if (listener.getStatus() == CAStatus.NORMAL) listener.getValue().printInfo();
      else System.err.println("Get error: " + listener.getStatus());

      /** ***************************************************************** */
      /** *************************** Monitors **************************** */
      /** ***************************************************************** */
      System.out.println("\n------------------------------------------------\n");
      System.out.println("Monitors:");
      System.out.println();

      // Create a monitor
      Monitor monitor = channel.addMonitor(Monitor.VALUE, new MonitorListenerImpl());
      context.flushIO();

      // Sleep for 10 seconds (monitors will be printed out).
      Thread.sleep(10000);

      // Clear the monitor
      monitor.clear();

      System.out.println("\n------------------------------------------------");

      /** ***************************************************************** */
      /** ***************************************************************** */
      /** ***************************************************************** */

      // Disconnect the channel.
      channel.destroy();

      // Flush all pending requests...
      context.flushIO();

      System.out.println("Done.");

    } catch (Throwable th) {
      th.printStackTrace();
    } finally {
      // always finalize
      destroy();
    }
  }