/* ************************************************************** */ /* * Module HP3458 * This module contains I/O functions for the HP3458 multimeter. * * Zachary Wolf * 8/3/98 */ /* ************************************************************** */ /* INCLUDES */ #include #include #include #include #include "hp3458.h" /* ************************************************************** */ /* PRIVATE FUNCTIONS */ int hp3458_open_dev(int gpib_board_addr, int gpib_dev_addr); void hp3458_close_dev(int dev_ID); int hp3458_out(int dev_ID, char* buf); int hp3458_in(int dev_ID, char* buf); int hp3458_serial_poll(int dev_ID, int* spoll); int hp3458_check_dev_open(int dev_ID); int hp3458_get_errors(int dev_ID); void hp3458_message(char* msg); void hp3458_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[HP3458_MAX_NUM_DEV + 1]; static int dev_descr[HP3458_MAX_NUM_DEV + 1]; static int dev_count; /* ************************************************************** */ /* PRIVATE GLOBAL VARIABLES */ /* * cmd, buffer for GPIB I/O strings * msg, buffer for messages to Standard I/O */ static char cmd[HP3458_MAX_CMD + 1]; static char msg[HP3458_MAX_CMD + 1]; /* ************************************************************** */ /* PUBLIC FUNCTIONS */ /* ************************************************************** */ /* * hp3458_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 * 11/11/99 */ void hp3458_init(int gpib_board_addr, int gpib_dev_addr, int* ID) { /* Declare variables */ int dev_ID; int err; /* Message */ hp3458_message(""); hp3458_message("Initializing the HP3458..."); /* Check input parameters */ if (gpib_board_addr < 0 || gpib_board_addr > 10) { Fmt(msg, "%s 30) { Fmt(msg, "%s HP3458_MAX_NUM_DEV) { Fmt(msg, "%s%f", voltage); if (err != 1) { hp3458_error("Problem getting HP3458 voltage"); } /* Done */ return; } /* ************************************************************** */ /* * hp3458_get_frequency * This function gets the frequency of the voltage applied to the * HP3458. * * Input: * dev_ID, device identifier * * Output: * frequency, frequency of applied voltage (Hz) * * Zachary Wolf * 11/11/99 */ void hp3458_get_frequency(int dev_ID, double* frequency) { /* Declare variables */ int dev_open; int err; /* Check input parameters */ if (dev_ID < 1 || dev_ID > HP3458_MAX_NUM_DEV) { Fmt(msg, "%s%f", frequency); if (err != 1) { hp3458_error("Problem getting HP3458 frequency"); } /* Done */ return; } /* ************************************************************** */ /* * hp3458_get_resistance * This function measures the resistance of the device attached * to the HP3458. * * Input: * dev_ID, device identifier * * Output: * resistance, resistance of the attached device (ohms) * * Zachary Wolf * 11/12/99 */ void hp3458_get_resistance(int dev_ID, double* resistance) { /* Declare variables */ int dev_open; int err; /* Check input parameters */ if (dev_ID < 1 || dev_ID > HP3458_MAX_NUM_DEV) { Fmt(msg, "%s%f", resistance); if (err != 1) { hp3458_error("Problem getting HP3458 resistance"); } /* Put the DVM back in a high impedance state */ hp3458_out(dev_ID, "PRESET"); /* Done */ return; } /* ************************************************************** */ /* * hp3458_get_temperature * This function measures the temperature of an HP thermistor * attached to the HP3458. * * Input: * dev_ID, device identifier * * Output: * temperature, temperature of the attached thermistor (deg C) * * Zachary Wolf * 11/12/99 */ void hp3458_get_temperature(int dev_ID, double* temperature) { /* Declare variables */ int dev_open; int err; /* Check input parameters */ if (dev_ID < 1 || dev_ID > HP3458_MAX_NUM_DEV) { Fmt(msg, "%s%f", temperature); if (err != 1) { hp3458_error("Problem getting HP3458 temperature"); } /* Put the DVM back in a high impedance state */ hp3458_out(dev_ID, "PRESET"); /* Done */ return; } /* ************************************************************** */ /* * hp3458_setup_timed_voltage_samples * This function sets up to sample the voltage on the HP3458. * The voltage range, measurement integration time, number of samples, * and the time between samples are specified. * * Input: * dev_ID, device identifier * v_range, voltage range for the HP3458 * num_plc, number of power line cycles to measure the voltage over * num_samples, the number of samples to take * delta_t, the time between samples (sec) * * Zachary Wolf * 11/12/99 */ void hp3458_setup_timed_voltage_samples(int dev_ID, double v_range, double num_plc, int num_samples, double delta_t) { /* Declare variables */ int dev_open; int err; /* Check input parameters */ if (dev_ID < 1 || dev_ID > HP3458_MAX_NUM_DEV) { Fmt(msg, "%s 30000) { Fmt(msg, "%s 10) { Fmt(msg, "%s HP3458_MAX_NUM_DEV) { Fmt(msg, "%s HP3458_MAX_NUM_DEV) { Fmt(msg, "%s 30000) { Fmt(msg, "%s%f", &voltages[i]); if (err != 1) { hp3458_error("Problem getting HP3458 voltage"); } } /* Done */ return; } /* ************************************************************** */ /* * hp3458_digitize * This function samples the voltage applied to the HP3458. * The number of samples and the time between samples are * specified. * Some parameters are defined locally such as the voltage range. * These should be changed to meet the needs of the job being performed. * * Input: * dev_ID, device identifier * num_samples, the number of samples to take * delta_t, the time between samples (sec) * * Output: * voltages[0 to num_samp - 1], voltage samples (V) * * Zachary Wolf * 11/16/99 */ void hp3458_digitize(int dev_ID, int num_samples, double delta_t, double voltages[]) { /* Parameters */ const double max_input = 10.; /* Determines voltage range */ /* Declare variables */ int dev_open; int err; int spoll; int i; /* Check input parameters */ if (dev_ID < 1 || dev_ID > HP3458_MAX_NUM_DEV) { Fmt(msg, "%s 30000) { Fmt(msg, "%s 1.) { Fmt(msg, "%s%f", &voltages[i]); if (err != 1) { hp3458_error("Problem getting HP3458 voltage"); } } /* Done */ return; } /* ************************************************************** */ /* * hp3458_exit * This function leaves the HP3458 in a desired state and * closes the device. * * Input: * dev_ID, device identifier * * Zachary Wolf * 7/27/98 */ void hp3458_exit(int dev_ID) { /* Declare variables */ int dev_open; int err; /* Check input parameters */ if (dev_ID < 1 || dev_ID > HP3458_MAX_NUM_DEV) { Fmt(msg, "%s 10) { Fmt(msg, "%s 30) { Fmt(msg, "%s%s[t-]", buf); /* Done */ return 0; } /* ************************************************************** */ /* * hp3458_serial_poll * This function performs a serial poll of the device. * A value of 16 indicates the HP3458 is ready for a command. * A value of 32 indicates an error. * * Input: * dev_ID, device identifier * * Output: * spoll, contents of the serial poll register * err, 0 if ok, -1 otherwise * * Zachary Wolf * 8/26/98 */ int hp3458_serial_poll(int dev_ID, int* spoll) { /* Declare variables */ int err; char spoll_char; /* Perform the serial poll */ err = ibrsp(dev_descr[dev_ID], &spoll_char); /* Check for errors */ if (err & 0x8000) { Fmt(msg, "%s%i", spoll); /* Done */ return 0; } /* ************************************************************** */ /* * hp3458_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 * 7/27/98 */ int hp3458_check_dev_open(int dev_ID) { /* See if the board descriptor has a positive value */ if (dev_descr[dev_ID] > 0) { return 1; /* Open */ } else { return 0; /* Not open */ } } /* ************************************************************** */ /* * hp3458_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 hp3458_get_errors(int dev_ID) { /* Declare variables */ int status; /* Get the HP3458 error status */ hp3458_out(dev_ID, "ERR?"); hp3458_in(dev_ID, cmd); /* Extract the status value */ Scan(cmd, "%s>%i", &status); /* Alert the operator if there is an error */ if (status != 0) { Fmt(msg, "%s