#include "toolbox.h" /* ************************************************************** */ /* * Module HP34970 * This module contains I/O functions for the HP34970 multimeter. * * Zachary Wolf * 2/19/03 */ /* ************************************************************** */ /* INCLUDES */ #include "repository.h" #include DELAY #include #include #include #include #include "hp34970.h" //#include "param.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); int hp34970_get_errors(int dev_ID); void hp34970_message(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; static char module_name[] = {"hp34970"}; /* ************************************************************** */ /* 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]; /* ************************************************************** */ /* 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_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 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%f %s[t44],%i,%s[t-]", &meas_val_as_meas[i], unit_as_meas[i], &chan_as_meas[i], buf); if (err != 4) { stop_error_msg(module_name, "Problem getting HP34970 measurements"); } strcpy(in_buf, buf); } if (strcmp(in_buf, "end") != 0) stop_error_msg(module_name, "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) stop_error_msg(module_name, "Problem getting HP34970 measurements."); } /* Check the units */ for (i = 0; i < num_chan; i++) { if (meas[i] == 'v') {if (strcmp(unit[i], "VDC") != 0) stop_error_msg(module_name, "Problem getting HP34970 measurements");} else if (meas[i] == 'r') {if (strcmp(unit[i], "OHM") != 0) stop_error_msg(module_name, "Problem getting HP34970 measurements");} else if (meas[i] == '4') {if (strcmp(unit[i], "OHM") != 0) stop_error_msg(module_name, "Problem getting HP34970 measurements");} else if (meas[i] == 't') {if (strcmp(unit[i], "C") != 0) stop_error_msg(module_name, "Problem getting HP34970 measurements");} else if (meas[i] == 'f') {if (strcmp(unit[i], "HZ") != 0) stop_error_msg(module_name, "Problem getting HP34970 measurements");} else if (meas[i] == 'p') {if (strcmp(unit[i], "SEC") != 0) stop_error_msg(module_name, "Problem getting HP34970 measurements");} else stop_error_msg(module_name, "Problem getting HP34970 measurements"); } /* Check for errors */ err = hp34970_get_errors(dev_ID); if (err != 0) { stop_error_msg(module_name, "The HP34970 has an error"); for (i = 0; i < num_chan; i++) meas_val[i] = 0.; return; } /* Done */ return; } void hp34970_scan_chan_timed_min_max_ave(int dev_ID, int num_chan, int chan[], char meas[], double meas_val[], double min[], double mean[], double max[], double trig_time, int trig_count) { /* Declare variables */ int dev_open; int err; int i, j, n, k; char scan_list[HP34970_MAX_NUM_CHAR]; char chan_list[HP34970_MAX_NUM_CHAR]; char in_buf[HP34970_MAX_IN_BUF]; char buf[HP34970_MAX_IN_BUF]; int chan_as_meas[HP34970_MAX_NUM_CHAN]; double meas_val_as_meas[HP34970_MAX_NUM_CHAN]; char unit_as_meas[HP34970_MAX_NUM_CHAN][HP34970_MAX_NUM_CHAR]; char unit[HP34970_MAX_NUM_CHAN][HP34970_MAX_NUM_CHAR]; int trig_num = trig_count; /* Check input parameters */ if (num_chan < 1 || num_chan > HP34970_MAX_NUM_CHAN) { Fmt(msg, "%s= 400) { Fmt(msg, "%s%f %s[t44],%i[w3],%s[t-]", &meas_val_as_meas[i], unit_as_meas[i], &chan_as_meas[i], buf); if (err != 4) { stop_error_msg(module_name, "Problem getting HP34970 measurements"); } strcpy(in_buf, buf); } if (strcmp(in_buf, "end") != 0) stop_error_msg(module_name, "Problem getting HP34970 measurements"); /* Order the measurements according to the input channel array */ j = 0; for(i = 0; i < num_chan*trig_num; i++) { if((i+2)%2 == 0) { meas_val[j] = meas_val_as_meas[i]; strcpy(unit[j], unit_as_meas[i]); j++; } } for(i = 0;i < num_chan*trig_num; i++) { if((i+1)%2 == 0) { meas_val[j] = meas_val_as_meas[i]; strcpy(unit[j], unit_as_meas[i]); j++; } } /*Get min mean and max*/ Fmt(cmd, "CALCULATE:AVERAGE:MINIMUM? %s",scan_list); hp34970_out(dev_ID, cmd); hp34970_in_buf(dev_ID, buf); Scan(buf, "%s>%f,%f", &min[0], &min[1]); Fmt(cmd, "CALCULATE:AVERAGE:AVERAGE? %s",scan_list); hp34970_out(dev_ID, cmd); hp34970_in_buf(dev_ID, buf); Scan(buf, "%s>%f,%f", &mean[0], &mean[1]); Fmt(cmd, "CALCULATE:AVERAGE:MAXIMUM? %s",scan_list); hp34970_out(dev_ID, cmd); hp34970_in_buf(dev_ID, buf); Scan(buf, "%s>%f,%f", &max[0], &max[1]); /* Check the units */ for (i = 0; i < num_chan; i++) { if (meas[i] == 'v') {if (strcmp(unit[i], "VDC") != 0) stop_error_msg(module_name, "Problem getting HP34970 measurements");} else if (meas[i] == 'r') {if (strcmp(unit[i], "OHM") != 0) stop_error_msg(module_name, "Problem getting HP34970 measurements");} else if (meas[i] == '4') {if (strcmp(unit[i], "OHM") != 0) stop_error_msg(module_name, "Problem getting HP34970 measurements");} else if (meas[i] == 't') {if (strcmp(unit[i], "C") != 0) stop_error_msg(module_name, "Problem getting HP34970 measurements");} else if (meas[i] == 'f') {if (strcmp(unit[i], "HZ") != 0) stop_error_msg(module_name, "Problem getting HP34970 measurements");} else if (meas[i] == 'p') {if (strcmp(unit[i], "SEC") != 0) stop_error_msg(module_name, "Problem getting HP34970 measurements");} else stop_error_msg(module_name, "Problem getting HP34970 measurements"); } /* Check for errors */ err = hp34970_get_errors(dev_ID); if (err != 0) { stop_error_msg(module_name, "The HP34970 has an error"); for (i = 0; i < num_chan; i++) meas_val[i] = 0.; return; } /* Done */ return; } /* ************************************************************** */ /* * hp34970_monitor_chan * This function monitors the specified measurement on the specified channel. * * Input: * dev_ID, device identifier * chan, channel number * meas, measurement ('v' = voltage, 'r' = resistance, '4' = 4-wire resistance, 't' = temperature, 'f' = frequency, 'p' = period) * * Zachary Wolf * 6/6/05 */ void hp34970_monitor_chan(int dev_ID, int chan, char meas) { /* Declare variables */ int dev_open; char scan_list[HP34970_MAX_NUM_CHAR]; char chan_list[HP34970_MAX_NUM_CHAR]; int err; /* Check input parameters */ if (chan < 101 || chan >= HP34970_MAX_NUM_CHAN) { Fmt(msg, "%s HP34970_MAX_NUM_DEV) { 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]; /* 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_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; }