/* ************************************************************** */ /* * Module K7011 * This module contains I/O functions for the Keithley 7011 * multiplexer card in the model 7001 chassis. * * Zachary Wolf * 8/23/98 */ /* ************************************************************** */ /* INCLUDES */ #include #include #include #include #include "k7011.h" /* ************************************************************** */ /* PRIVATE FUNCTIONS */ int k7011_open_dev(int gpib_board_addr, int gpib_dev_addr); void k7011_close_dev(int dev_ID); int k7011_out(int dev_ID, char* buf); int k7011_in(int dev_ID, char* buf); int k7011_check_device_open(int dev_ID); int k7011_get_errors(int dev_ID); void k7011_message(char* msg); void k7011_error(char* msg); /* ************************************************************** */ /* PRIVATE DEVICE TABLE */ /* * This table allows several devices of the same type to be * used in the system. * dev_addr, contains the GPIB addresses of opened devices * dev_descr, contains the device descriptors of opened devices * dev_count, contains the number of devices open of this type */ static int dev_addr[K7011_MAX_NUM_DEV + 1]; static int dev_descr[K7011_MAX_NUM_DEV + 1]; static int dev_count; /* ************************************************************** */ /* PRIVATE GLOBAL VARIABLES */ /* * cmd, buffer for GPIB I/O strings * msg, buffer for message strings to Standard I/O */ static char cmd[K7011_MAX_CMD + 1]; static char msg[K7011_MAX_CMD + 1]; /* ************************************************************** */ /* PUBLIC FUNCTIONS */ /* ************************************************************** */ /* * k7011_init * This function opens the device, queries for ID, and * initializes the device to a known state. * * Input: * gpib_board_addr, address of the GPIB board the device is conected to (0, 1, ...) * gpib_dev_addr, GPIB address of the device (1 to 30, 0 is reserved) * * Output: * dev_ID, identifier for future references to the device * * Zachary Wolf * 8/23/98 */ void k7011_init(int gpib_board_addr, int gpib_dev_addr, int* ID) { /* Declare variables */ int dev_ID; int err; /* Message */ k7011_message(""); k7011_message("Initializing the K7011..."); /* Check input parameters */ if (gpib_board_addr < 0 || gpib_board_addr > 10) { Fmt(msg, "%s 30) { Fmt(msg, "%s K7011_MAX_NUM_DEV) { Fmt(msg, "%s K7011_MAX_NUM_DEV) { Fmt(msg, "%s 2) { Fmt(msg, "%s 40) { Fmt(msg, "%s K7011_MAX_NUM_DEV) { Fmt(msg, "%s 10) { Fmt(msg, "%s 30) { Fmt(msg, "%s%s[t-]", buf); /* Done */ return 0; } /* ************************************************************** */ /* * k7011_check_device_open * This function checks to see if the specified device is open. * If the device has been opened, a 1 is returned, 0 otherwise. * * Input: * dev_ID, device identifier * * Output: * status, 1 if device is open, 0 otherwise * * Zachary Wolf * 7/27/98 */ int k7011_check_device_open(int dev_ID) { /* See if the board descriptor has a positive value */ if (dev_descr[dev_ID] > 0) { return 1; } else { return 0; } } /* ************************************************************** */ /* * k7011_get_errors * This function obtains device errors. * The operator is alerted if there is an error. * * Input: * dev_ID, device identifier * * Output: * err, 0 if no errors, -1 otherwise * * Zachary Wolf * 8/3/98 */ int k7011_get_errors(int dev_ID) { /* Declare variables */ int status; int err; /* Get the error status */ k7011_out(dev_ID, "*ESR?"); k7011_in(dev_ID, cmd); /* Extract the status value */ err = Scan(cmd, "%s>%i", &status); if (err != 1) { k7011_error("Problem getting error status"); return -1; } /* Alert the operator if there is an error */ if (status != 0) { Fmt(msg, "%s