/* ************************************************************** */ /* * Module HP34970 * This module contains I/O functions for the HP34970 multimeter. * * Zachary Wolf * 2/19/03 */ /* ************************************************************** */ /* INCLUDES */ #include "repository.h" #include "c:\MMCVI\Lib\delay.h" #include "delay.h" #include #include #include #include #include "hp34970_sw.h" /* ************************************************************** */ /* PRIVATE FUNCTIONS */ int hp34970_open_dev(int gpib_board_addr, int gpib_dev_addr); void hp34970_close_dev(int dev_ID); int hp34970_out(int dev_ID, char* buf); int hp34970_in(int dev_ID, char* buf); int hp34970_in_buf(int dev_ID, char* buf); int hp34970_serial_poll(int dev_ID, int* spoll); int hp34970_check_dev_open(int dev_ID); void hp34970_message(char* msg); void hp34970_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[HP34970_MAX_NUM_DEV + 1]; static int dev_descr[HP34970_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[HP34970_MAX_NUM_CHAR]; static char msg[HP34970_MAX_NUM_CHAR]; static char module_name[] = {"hp34970"}; /* ************************************************************** */ /* PUBLIC FUNCTIONS */ /* ************************************************************** */ /* * hp34970_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 * 2/19/03 */ void hp34970_init(int gpib_board_addr, int gpib_dev_addr, int* ID) { /* Declare variables */ int dev_ID; int err; /* Message */ hp34970_message(""); hp34970_message("Initializing the HP34970..."); /* Check input parameters */ if (gpib_board_addr < 0 || gpib_board_addr > 10) { Fmt(msg, "%s 30) { Fmt(msg, "%s HP34970_MAX_NUM_DEV) { Fmt(msg, "%s HP34970_MAX_NUM_DEV) { Fmt(msg, "%s HP34970_MAX_NUM_CHAN) { Fmt(msg, "%s= 400) { Fmt(msg, "%s HP34970_MAX_NUM_DEV) { Fmt(msg, "%s 400) { Fmt(msg, "%s HP34970_MAX_NUM_DEV) { Fmt(msg, "%s HP34970_MAX_NUM_CHAN) { Fmt(msg, "%s= 400) { Fmt(msg, "%s HP34970_MAX_NUM_DEV) { Fmt(msg, "%s 400) { Fmt(msg, "%s HP34970_MAX_NUM_DEV) { Fmt(msg, "%s HP34970_MAX_NUM_CHAN) { Fmt(msg, "%s= 400) { Fmt(msg, "%s HP34970_MAX_NUM_DEV) { Fmt(msg, "%s 400) { Fmt(msg, "%s HP34970_MAX_NUM_DEV) { Fmt(msg, "%s HP34970_MAX_NUM_CHAN) { Fmt(msg, "%s= 400) { Fmt(msg, "%s%i", &rtd_type); /* set RTD type */ Fmt(cmd, "%s%f", &rtd_res); /* set nominal resistance */ Fmt(cmd, "%s%i", &therm); /* set thermistor type */ Fmt(cmd, "%s%f %s[t44],%i,%s[t-]", &meas_val_as_meas[i], unit_as_meas[i], &chan_as_meas[i], buf); if (err != 4) { hp34970_error("Problem getting HP34970 measurements"); } strcpy(in_buf, buf); } if (strcmp(in_buf, "end") != 0) hp34970_error("Problem getting HP34970 measurements"); /* Order the measurements according to the input channel array */ for (i = 0; i < num_chan; i++) { n = 0; for (j = 0; j < num_chan; j++) { if (chan[i] == chan_as_meas[j]) { meas_val[i] = meas_val_as_meas[j]; strcpy(unit[i], unit_as_meas[j]); n++; } } if (n != 1) hp34970_error("Problem getting HP34970 measurements."); } /* Check the units */ for (i = 0; i < num_chan; i++) { if (meas[i] == 'v') {if (strcmp(unit[i], "VDC") != 0) hp34970_error("Problem getting HP34970 measurements");} else if (meas[i] == 'r') {if (strcmp(unit[i], "OHM") != 0) hp34970_error("Problem getting HP34970 measurements");} else if (meas[i] == '4') {if (strcmp(unit[i], "OHM") != 0) hp34970_error("Problem getting HP34970 measurements");} else hp34970_error("Problem getting HP34970 measurements"); } /* Check for errors */ err = hp34970_get_errors(dev_ID); if (err != 0) { hp34970_error("The HP34970 has an error"); for (i = 0; i < num_chan; i++) meas_val[i] = 0.; return; } /* Done */ return; } /* ************************************************************** */ /* * hp34970_exit * This function leaves the HP34970 in a desired state and * closes the device. * * Input: * dev_ID, device identifier * * Zachary Wolf * 2/19/03 */ void hp34970_exit(int dev_ID) { /* Declare variables */ int dev_open; // Exit if testing without hardware #ifdef DUMMY_DEVICES return; #endif // Check input parameters if (dev_ID < 1 || dev_ID > HP34970_MAX_NUM_DEV) { Fmt(msg, "%s 10) { Fmt(msg, "%s 30) { Fmt(msg, "%s%s[t-]", buf); /* Done */ return 0; } /* ************************************************************** */ /* * hp34970_in_buf * This function reads a buffer of data from the device. * * Input: * dev_ID, device identifier * * Output: * buf, null terminated string, the contents from the device * err, 0 if ok, -1 otherwise * * Zachary Wolf * 2/19/03 */ int hp34970_in_buf(int dev_ID, char* buf) { /* Declare variables */ int err; char in_buf[HP34970_MAX_IN_BUF]; delay(0.05); /* Read the message */ err = ibrd(dev_descr[dev_ID], in_buf, HP34970_MAX_IN_BUF); /* Check for errors */ if (err & 0x8000) { Fmt(msg, "%s%s[t-]", buf); /* Done */ return 0; } /* ************************************************************** */ /* * hp34970_serial_poll * This function performs a serial poll of the device. * * Input: * dev_ID, device identifier * * Output: * spoll, contents of the serial poll register * err, 0 if ok, -1 otherwise * * Zachary Wolf * 2/19/03 */ int hp34970_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; } /* ************************************************************** */ /* * hp34970_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 * 2/19/03 */ int hp34970_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 */ } } /* ************************************************************** */ /* * hp34970_get_errors * This function obtains errors from the error queue. * The operator is alerted if there is an error. * * Input: * dev_ID, device identifier * * Output: * err, 0 if no errors, -1 otherwise * * Zachary Wolf * 2/19/03 */ int hp34970_get_errors(int dev_ID) { /* Declare variables */ int err; int more_err; /* Initialize, start of error queue read */ err = 0; get_another: more_err = 0; /* Get the HP34970 error status */ hp34970_out(dev_ID, "SYSTEM:ERROR?"); hp34970_in(dev_ID, msg); /* Alert the operator if there is an error */ if (strcmp(msg, "+0,\"No error\"") != 0) { printf("\nThe HP34970 has an error.\n"); printf("%s", msg); err = -1; more_err = 1; } /* Check to see if there are more errors */ if (more_err != 0) goto get_another; /* Done */ return err; } /* ************************************************************** */ /* * hp34970_message * This function handles messages about the hp34970. * * Input: * message, string to display in standard I/O * * Zachary Wolf * 2/19/03 */ void hp34970_message(char* message) { /* Print the message */ printf("%s\n", message); /* Done */ return; } /* ************************************************************** */ /* * hp34970_error * This function handles error messages for the HP34970. * * Input: * message, string to display in standard I/O * * Zachary Wolf * 2/19/03 */ void hp34970_error(char* message) { /* Declare variables */ char buf[80]; /* Notify the operator of the error */ printf("\nHP34970 ERROR: %s\n", message); Beep(); Delay(.5); Beep(); /* Terminate the program if the operator desires */ printf("Press ENTER to continue.\nPress any key then ENTER to terminate program.\n"); fgets(buf, 80, stdin); if (buf[0] == '\n') return; else exit(0); } /* ************************************************************** */ /* * hp34970_switch_on_off * This function switches ON the HP34970 20 channel Actuator board installed into 200 slot * for specified channels. * * Input: * dev_ID - Device ID * ch_num - number of channel to be switched ON * flag = 1 to switch the channel ON, else flag = 0 * Yurii Levashov * 09/30/2004 */ void hp34970_switch_on_off(int dev_ID, int ch_num, int flag) { /* Declare variables */ int slot_number; int dev_ON = 0, err; char buf[80]; char sc_list[HP34970_MAX_NUM_CHAR]; slot_number = HP34970_SWITCH_SLOT; ch_num += slot_number; /* Check input parameters */ if (dev_ID < 1 || dev_ID > HP34970_MAX_NUM_DEV) { Fmt(msg, "%s 400) { Fmt(msg, "%s%d", &dev_ON); // Reed status of a channel switch(dev_ON) { case 0: // If the channel is open if (flag == 0) // And needs to be switched ON { sprintf(buf, "(@%i)", ch_num); // Make a string for the channel Fmt(cmd, "%s%d", &dev_ON); if(dev_ON != 1) hp34970_error(" Problem open the channels"); return; } /* ************************************************************** */ /* * hp34970_get_chan_res * This function gets the resistance applied to the specified channel. * * Input: * dev_ID, device identifier * chan, channel number (0 to HP34970_MAX_NUM_CHAN - 1) * * Output: * res, applied resistance (ohm) * * Zachary Wolf * 2/19/03 */ void hp34970_get_chan_temp(int dev_ID, int chan, double* temp) { /* Declare variables */ int num_chan = 1; char meas = 't'; /* Check input parameters */ if (dev_ID < 1 || dev_ID > HP34970_MAX_NUM_DEV) { Fmt(msg, "%s 400) { Fmt(msg, "%s HP34970_MAX_NUM_DEV) { Fmt(msg, "%s= 400) { Fmt(msg, "%s HP34970_MAX_NUM_DEV) { Fmt(msg, "%s