Go to the first, previous, next, last section, table of contents.


Opening And Closing ahi.device For High-level Access

Four primary steps are required to open ahi.device:

Each OpenDevice() must eventually be matched by a call to CloseDevice(). When the last close is performed, the device will deallocate all resources.

All I/O requests must be completed before CloseDevice(). Abort any pending requests with AbortIO().

Example:

struct MsgPort    *AHImp      = NULL;
struct AHIRequest *AHIio      = NULL;
BYTE               AHIDevice  = -1;
UBYTE              unit       = AHI_DEFAULT_UNIT;

/* Check if user wants another unit here... */

if(AHImp = CreateMsgPort())
{
  if(AHIio = (struct AHIRequest *)
      CreateIORequest(AHImp, sizeof(struct AHIRequest)))
  {
    AHIio->ahir_Version = 4;
    if(!(AHIDevice = OpenDevice(AHINAME, unit, 
        (struct IORequest *) AHIio, NULL)))
    {

      /* Send commands to the device here... */

      if(! CheckIO((struct IORequest *) AHIio))
      {
        AbortIO((struct IORequest *) AHIio);
      }

      WaitIO((struct IORequest *) AHIio);

      CloseDevice((struct IORequest *) AHIio);
      AHIDevice = -1;
    }
    DeleteIORequest((struct IORequest *) AHIio);
    AHIio = NULL;
  }
  DeleteMsgPort(AHImp);
  AHImp = NULL;
}


Go to the first, previous, next, last section, table of contents.