Appendix 4 - Exclusive Communications Access

Q:  How do I gain exclusive access to the field-bus, in order to perform something special in my driver?

A:  Override the grantAccess method in your driver's communicator.

The grantAccess method is called each time that a request is pulled off of the communicator's queue but before any processing occurs on the request. If the grantAcess method returns false for the request, then the request is placed back onto the tail of the communicator's queue, asynchronously, after a short period of time. You may define the grantAccess method to return true only for certain requests, depending on some internal state or scenario that you are maintaining or that you detect in your driver.

Please note that by default, the grantAccess method simply returns true. That allows all requests to proceed normally. To gain exclusive access to your field-bus, you may define any restrictions in your overrided version of this method.

Example

The following example allows only certain types of requests to be processed (transmitted onto the field-bus) when certain conditions are in effect. If those certain conditions are not in effect, then this example allows all requests to be processed (transmitted onto the field-bus).



  /**
   * This method is called for each request that is dequeued.
   *
   * Overridden in Sample driver to provide exclusive access to the
   * communicator when doing terminal mode sessions and backups and/or
   * restores of the controllers.
   *
   * If returning true then the request will be processed
   * immediately (transmitted and scheduled for response checking). If
   * the developer returns false then the request will be placed back
   * in the back of the communicator queue.
   *
   * @param ddfRequest this is a request that was just pulled off of the
   * communicator queue. However, this request has not yet been processed.
   * This request will be processed immediately if this method returns
   * true. This request will be processed later if this method returns
   * false.
   *
   * @return true, unless the backup, restore, or terminal mode is active, and
   * the request is a Reload, ReloadLine, or Keystroke command.
   */
  protected boolean grantAccess(BIDdfRequest ddfRequest)
  {
    BSampleNetwork network = (BSampleNetwork)getParent();
    // In terminal mode, the end-user has visited a Vt100 terminal display from
    // within Workbench AX. He or she may type at the keyboard and the corresponding
    // keys are passed through to the field-device. While in this mode, routine
    // driver pinging, polling, etc. needs to temporarily stop.
    if(network.isTerminalModeActive())
      return ddfRequest instanceof BSampleKeystrokeRequest;

    // If the driver is backing-up the field-device, then routing pinging, polling,
    // etc. needs to temporarily stop so as not to confuse the field-device while
    // the back-up is occuring. The backup procedure uses BSampleKeystrokeRequest
    // to communicate to the field-device. Therefore, if the field-device is being
    // backed-up, then this only allows BSampleKeystrokeRequest requests to be
    // processed.
    if(network.getBackupModeActive()) // Backup procedure uses BSampleKeystrokeRequest
      return ddfRequest instanceof BSampleKeystrokeRequest; // To peform the backup

    // If the driver is reloading the field-device then only those request types that
    // are used during the reload process will be allowed to proceed. Any others will
    // be denied access to the field-bus.
    if(network.isReloadModeActive())
    {
      return (ddfRequest instanceof BSampleReloadNetRequest) ||
             (ddfRequest instanceof BSampleReloadLineRequest)    ||
             (ddfRequest instanceof BSampleKeystrokeRequest);
    }

    // If none of the above scenarios are in effect, then any request type may
    // be granted access to the field-bus at this exact moment in time.
    return true;
  }