home *** CD-ROM | disk | FTP | other *** search
/ HTBasic 9.3 / HTBasic 9.3.iso / SICL / data1.cab / sicl32 / c / samples / misc / locking.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-03-02  |  1.4 KB  |  57 lines

  1. /* locking.c
  2.    This example shows how device locking can be
  3.    used to gain exclusive access to a device*/
  4.  
  5. #include <sicl.h>
  6. #include <stdio.h>
  7.  
  8. main()
  9. {
  10.    INST dvm;
  11.  
  12.    char strres[20];
  13.    unsigned long actual;
  14.  
  15.    #if defined(__BORLANDC__) && !defined(__WIN32__)
  16.       _InitEasyWin();   // required for Borland EasyWin programs 
  17.    #endif
  18.    
  19.    /* Log message and terminate on error */
  20.    ionerror (I_ERROR_EXIT);
  21.  
  22.    /* Open the multimeter session */
  23.    dvm = iopen ("hpib7,16");
  24.    itimeout (dvm, 10000);
  25.  
  26.    /* Lock the multimeter device to prevent access from
  27.        other applications*/
  28.    ilock(dvm);
  29.  
  30.    /* Take a measurement  */
  31.    iwrite (dvm, "MEAS:VOLT:DC?\n", 14, 1, NULL);
  32.  
  33.    /* Read the results */
  34.    iread (dvm, strres, 20, NULL, &actual);
  35.  
  36.    /* Release the multimeter device for use by others */
  37.    iunlock(dvm);
  38.  
  39.    /* NULL terminate result string and print the results */
  40.    /* This technique assumes the last byte sent was a line-feed */
  41.    if (actual) {
  42.      strres[actual - 1] = (char) 0;
  43.      printf("Result is %s\n", strres);
  44.    }
  45.  
  46.    /* Close the multimeter session */
  47.    iclose(dvm);
  48.  
  49.    // For WIN16 programs, call _siclcleanup before exiting to release
  50.    // resources allocated by SICL for this application.  This call
  51.    // is a no-op for WIN32 programs.
  52.    _siclcleanup();
  53.  
  54.    return 0;
  55. }
  56.  
  57.