1 #include <stdio.h>
    2 #include <unicap.h>
    3 
    4 #define MAX_DEVICES 64
    5 
    6 unicap_handle_t
    7 open_device ()
    8 {
    9   int dev_count;
   10   int status = STATUS_SUCCESS;
   11   unicap_device_t devices[MAX_DEVICES];
   12   unicap_handle_t handle;
   13   int d = -1;
   14 
   15   for (dev_count = 0; SUCCESS (status) && (dev_count < MAX_DEVICES);
   16        dev_count++)
   17     {
   18       status = unicap_enumerate_devices (NULL, &devices[dev_count], dev_count); // (1)
   19       if (SUCCESS (status))
   20         printf ("%d: %s\n", dev_count, devices[dev_count].identifier);
   21       else
   22         break;
   23     }
   24 
   25   if (dev_count == 0)
   26     return NULL;                // no device selected
   27 
   28   while ((d < 0) || (d >= dev_count))
   29     {
   30       printf ("Open Device: ");
   31       scanf ("%d", &d);
   32     }
   33 
   34   unicap_open (&handle, &devices[d]);   // (2)
   35 
   36   return handle;
   37 }
   38 
   39 
   40 int
   41 main (int argc, char **argv)
   42 {
   43   unicap_handle_t handle;
   44   handle = open_device ();
   45   if (!handle)
   46     return -1;
   47 
   48   unicap_close (handle);        // (3)
   49   return 0;
   50 }