home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_13_12 / taylor / gpibio.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1995-08-17  |  1.8 KB  |  90 lines

  1. // gpibio.cpp
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5. #include <iostream.h>
  6. #include "gpibio.h"
  7.  
  8. // GPIB BOARD CLASS
  9. gpibdvr *gpibio::dvr[] = {NULL,NULL};
  10. int gpibio::rep_cnt[] = {0,0};    // Initialize repetition count per board
  11.  
  12. // Constructor
  13. gpibdvr::gpibdvr(int b)
  14. {
  15.     char name[6];
  16.  
  17.     // build board name
  18.     strcpy(name,"gpib");
  19.     if(b==1)
  20.        strcat(name,"1");
  21.     else
  22.        strcat(name,"0");
  23.  
  24.     // Find GPIB interface board
  25.     bhandle = ::ibfind(name);
  26.     if(bhandle < 0)
  27.     {
  28.        cerr << "Can't Find GPIB Board" << endl;
  29.        exit(1);
  30.     }
  31.  
  32.     // Configure The board
  33.     ::ibconfig(bhandle,IbcAUTOPOLL,0);
  34.  
  35.     // Disable the EOI assertion at the end of write I/O
  36.     ::ibeot(bhandle,0);
  37.  
  38.     // Terminate read when EOS is detected, set EOI on EOS
  39.     ::ibeos(bhandle,0xC0A);
  40.  
  41.     // Set read/write/wait time out to 30 seconds
  42.     ::ibtmo(bhandle,T30s);
  43. }
  44.  
  45. // Open Specific device  -- Returns -1 on error
  46. int gpibdvr::open_device(int d)
  47. {
  48.     char name[8];
  49.  
  50.     // Build device name
  51.     sprintf(name,"dev%d",d);
  52.  
  53.     // Find the device
  54.     int device = ::ibfind(name);
  55.     if(ibsta & ERR)
  56.     {
  57.        cerr << "Can't Find device" << endl;
  58.        exit(1);
  59.     }
  60.     return (device);
  61. }
  62.  
  63. // Constructor for initializing the GPIB board
  64. gpibio::gpibio(int b)
  65. {
  66.     radix = 10;              // setup format radix
  67.     board = (b==1) ? 1 : 0;  // restrict index
  68.     if(rep_cnt[board]++ == 0)
  69.     {
  70.        dvr[board] = new gpibdvr;
  71.        if(dvr[board] == NULL)
  72.        {
  73.           cerr << "Can't allocate driver class." << endl;
  74.           exit(1);
  75.        }
  76.     }
  77. }
  78.  
  79. // Destructor
  80. gpibio::~gpibio()
  81. {
  82.     if(--rep_cnt[board] == 0)
  83.     {
  84.        delete dvr[board];    // Release class memory
  85.        dvr[board] = NULL;
  86.     }
  87. }
  88.  
  89.  
  90.