/* ************************************************************** */ /* * Module DAC488HR * This module contains I/O functions for the IOtech DAC488HR. * * Zachary Wolf * 12/20/99 */ /* ************************************************************** */ /* INCLUDES */ #include #include #include #include #include "dac488hr.h" /* ************************************************************** */ /* PRIVATE FUNCTIONS */ int dac488hr_open_dev(int gpib_board_addr, int gpib_dev_addr); void dac488hr_close_dev(int dev_ID); int dac488hr_out(int dev_ID, char* buf); int dac488hr_in(int dev_ID, char* buf); int dac488hr_check_dev_open(int dev_ID); int dac488hr_get_errors(int dev_ID); void dac488hr_message(char* msg); void dac488hr_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[DAC488HR_MAX_NUM_DEV + 1]; static int dev_descr[DAC488HR_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 * range_settings, port range settings saved for quick access */ static char cmd[DAC488HR_MAX_CMD + 1]; static char msg[DAC488HR_MAX_CMD + 1]; static int range_settings[DAC488HR_NUM_PORTS + 1]; /* ************************************************************** */ /* PUBLIC FUNCTIONS */ /* ************************************************************** */ /* * dac488hr_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 connected 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 * 12/20/99 */ void dac488hr_init(int gpib_board_addr, int gpib_dev_addr, int* ID) { /* Declare variables */ int dev_ID; int err; int i; /* Message */ dac488hr_message(""); dac488hr_message("Initializing the DAC488HR..."); /* Check input parameters */ if (gpib_board_addr < 0 || gpib_board_addr > 10) { Fmt(msg, "%s 30) { Fmt(msg, "%s DAC488HR_MAX_NUM_DEV) { Fmt(msg, "%s DAC488HR_MAX_NUM_DEV) { Fmt(msg, "%s DAC488HR_NUM_PORTS) { Fmt(msg, "%s 8) { Fmt(msg, "%s DAC488HR_MAX_NUM_DEV) { Fmt(msg, "%s DAC488HR_NUM_PORTS) { Fmt(msg, "%s high_volt_range[range_settings[port]]) { Fmt(msg, "%s DAC488HR_MAX_NUM_DEV) { Fmt(msg, "%s 255) { Fmt(msg, "%s DAC488HR_MAX_NUM_DEV) { Fmt(msg, "%s DAC488HR_NUM_PORTS) { Fmt(msg, "%sV%f", voltage); if (err != 1) { dac488hr_error("Problem getting DAC voltage"); } /* Done */ return; } /* ************************************************************** */ /* * dac488hr_get_digital_output * This function gets the digital output configuration. * * Input: * dev_ID, device identifier * * Output: * config, integer (0 to 255) giving the states of the 8 lines * * Zachary Wolf * 12/20/99 */ void dac488hr_get_digital_output(int dev_ID, int* config) { /* Declare variables */ int dev_open; int err; /* Check input parameters */ if (dev_ID < 1 || dev_ID > DAC488HR_MAX_NUM_DEV) { Fmt(msg, "%sD%i", config); if (err != 1) { dac488hr_error("Problem getting digital output configuration"); } /* Done */ return; } /* ************************************************************** */ /* * dac488hr_exit * This function configures the DAC488HR for program exit and * closes the device. * * Input: * dev_ID, device identifier * * Zachary Wolf * 12/20/99 */ void dac488hr_exit(int dev_ID) { /* Declare variables */ int dev_open; int err; int port; /* Check input parameters */ if (dev_ID < 1 || dev_ID > DAC488HR_MAX_NUM_DEV) { Fmt(msg, "%s 10) { Fmt(msg, "%s 30) { Fmt(msg, "%s%s[t-]", buf); /* Done */ return 0; } /* ************************************************************** */ /* * dac488hr_check_dev_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 * 12/20/99 */ int dac488hr_check_dev_open(int dev_ID) { /* See if the device descriptor has a positive value */ if (dev_descr[dev_ID] > 0) { return 1; /* Open */ } else { return 0; /* Not open */ } } /* ************************************************************** */ /* * dac488hr_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 * 12/20/99 */ int dac488hr_get_errors(int dev_ID) { /* Declare variables */ int status; int err; /* Get the DAC error status */ dac488hr_out(dev_ID, "E? X"); dac488hr_in(dev_ID, cmd); /* Extract the status value */ err = Scan(cmd, "%s>E%i", &status); if (err != 1) { dac488hr_error("Problem getting error status"); return -1; } /* Alert the operator if there is an error */ if (status != 0) { Fmt(msg, "%s