/* ************************************************************** */ /* * Module TDS3012B * This module contains I/O functions for the Tektronix TDS3012B * oscilloscope. * * Zachary Wolf * 1/16/02 */ /* ************************************************************** */ /* INCLUDES */ #include #include #include #include #include "tds3012b.h" /* ************************************************************** */ /* PRIVATE FUNCTIONS */ int tds3012b_open_dev(int gpib_board_addr, int gpib_dev_addr); void tds3012b_close_dev(int dev_ID); int tds3012b_out(int dev_ID, char* buf); int tds3012b_in(int dev_ID, char* buf); int tds3012b_in_waveform(int dev_ID, char* buf); int tds3012b_check_device_open(int dev_ID); int tds3012b_get_errors(int dev_ID); void tds3012b_message(char* msg); void tds3012b_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[TDS3012B_MAX_NUM_DEV + 1]; static int dev_descr[TDS3012B_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[TDS3012B_MAX_CMD + 1]; static char msg[TDS3012B_MAX_CMD + 1]; /* ************************************************************** */ /* PUBLIC FUNCTIONS */ /* ************************************************************** */ /* * tds3012b_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 * 1/16/02 */ void tds3012b_init(int gpib_board_addr, int gpib_dev_addr, int* ID) { /* Declare variables */ int dev_ID; int err; /* Message */ tds3012b_message(""); tds3012b_message("Initializing the TDS3012B..."); /* Check input parameters */ if (gpib_board_addr < 0 || gpib_board_addr > 10) { Fmt(msg, "%s 30) { Fmt(msg, "%s TDS3012B_MAX_NUM_DEV) { Fmt(msg, "%s TDS3012B_MAX_NUM_DEV) { Fmt(msg, "%s 2) { Fmt(msg, "%s 10.) { Fmt(msg, "%s TDS3012B_MAX_NUM_DEV) { Fmt(msg, "%s 2) { Fmt(msg, "%s 5.) { Fmt(msg, "%s TDS3012B_MAX_NUM_DEV) { Fmt(msg, "%s 2) { Fmt(msg, "%s TDS3012B_MAX_NUM_DEV) { Fmt(msg, "%s 2) { Fmt(msg, "%s TDS3012B_MAX_NUM_DEV) { Fmt(msg, "%s 10.) { Fmt(msg, "%s TDS3012B_MAX_NUM_DEV) { Fmt(msg, "%s TDS3012B_MAX_NUM_DEV) { Fmt(msg, "%s 100) { Fmt(msg, "%s TDS3012B_MAX_NUM_DEV) { Fmt(msg, "%s TDS3012B_MAX_NUM_DEV) { Fmt(msg, "%s TDS3012B_MAX_NUM_DEV) { Fmt(msg, "%s 12.) { Fmt(msg, "%s 100.) { Fmt(msg, "%s TDS3012B_MAX_NUM_DEV) { Fmt(msg, "%s 10.) { Fmt(msg, "%s TDS3012B_MAX_NUM_DEV) { Fmt(msg, "%s TDS3012B_MAX_NUM_DEV) { Fmt(msg, "%s 512) { Fmt(msg, "%s TDS3012B_MAX_NUM_DEV) { Fmt(msg, "%s TDS3012B_MAX_NUM_DEV) { Fmt(msg, "%s 2) { Fmt(msg, "%s:HOR:RECO %i", &rec_len); if (num_scan != 1) tds3012b_error("tds3012b_get_waveform: Problem reading rec_len"); /* Setup to read the waveform */ Fmt(cmd, "%s%i", &opc); if (num_scan != 1) tds3012b_error("tds3012b_get_waveform: Problem reading opc"); if (opc != 1) tds3012b_error("tds3012b_get_waveform: Problem with opc"); /* Get the waveform */ tds3012b_out(dev_ID, "CURVE?"); Delay(1.); tds3012b_in_waveform(dev_ID, data_string); /* Get the number of points in the waveform */ Fmt(cmd, "%s:WFMP:CH%i[w1]:NR_P %i", &chan_rtn, &num_pts); if (num_scan != 2) tds3012b_error("tds3012b_get_waveform: Problem reading num_pts"); if (chan_rtn != chan) tds3012b_error("tds3012b_get_waveform: Problem reading num_pts"); /* Extract the raw voltage values */ num_scan = Scan(data_string, "%s[x]>:CURV %*f[x]", num_pts, v); if (num_scan != 1) tds3012b_error("tds3012b_get_waveform: problem reading raw v"); /* Get the Y offset value */ Fmt(cmd, "%s:WFMP:CH%i[w1]:YOF %f", &chan_rtn, &y_off); if (num_scan != 2) tds3012b_error("tds3012b_get_waveform: Problem reading y_off"); if (chan_rtn != chan) tds3012b_error("tds3012b_get_waveform: Problem reading y_off"); /* Get the Y multiplier value */ Fmt(cmd, "%s:WFMP:CH%i[w1]:YMU %f", &chan_rtn, &y_mult); if (num_scan != 2) tds3012b_error("tds3012b_get_waveform: Problem reading y_mult"); if (chan_rtn != chan) tds3012b_error("tds3012b_get_waveform: Problem reading y_mult"); /* Get the X increment value */ Fmt(cmd, "%s:WFMP:CH%i[w1]:XIN %f", &chan_rtn, &x_incr); if (num_scan != 2) tds3012b_error("tds3012b_get_waveform: Problem reading x_incr"); if (chan_rtn != chan) tds3012b_error("tds3012b_get_waveform: Problem reading x_incr"); /* Get the X trigger point */ Fmt(cmd, "%s:WFMP:CH%i[w1]:PT_O %i", &chan_rtn, &pt_off); if (num_scan != 2) tds3012b_error("tds3012b_get_waveform: Problem reading pt_off"); if (chan_rtn != chan) tds3012b_error("tds3012b_get_waveform: Problem reading pt_off"); /* Return the number of samples in the waveform */ *num_samp = num_pts; /* Calculate the time of each sample */ for (i = 0; i < num_pts; i++) t[i] = (i - pt_off) * x_incr; /* Calculate the voltage of each sample */ for (i = 0; i < num_pts; i++) v[i] = (v[i] - y_off) * y_mult; /* Check for errors */ err = tds3012b_get_errors(dev_ID); if (err != 0) { tds3012b_error("The device has an error"); tds3012b_close_dev(dev_ID); return; } /* Done */ return; } /* ************************************************************** */ /* * tds3012b_exit * This function puts the TDS3012B in a desired state and closes the device. * * Input: * dev_ID, device identifier * * Zachary Wolf * 1/16/02 */ void tds3012b_exit(int dev_ID) { /* Declare variables */ int dev_open; int err; /* Check input parameters */ if (dev_ID < 1 || dev_ID > TDS3012B_MAX_NUM_DEV) { Fmt(msg, "%s 10) { Fmt(msg, "%s 30) { Fmt(msg, "%s%s[t-]", buf); /* Done */ return 0; } /* ************************************************************** */ /* * tds3012b_in_waveform * This function reads a data waveform 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 * 1/16/02 */ int tds3012b_in_waveform(int dev_ID, char* buf) { /* Declare variables */ int err; char in_buf[TDS3012B_MAX_WAVEFORM]; /* Read the message */ err = ibrd(dev_descr[dev_ID], in_buf, TDS3012B_MAX_WAVEFORM); /* Check for errors */ if (err & 0x8000) { Fmt(msg, "%s%s[t-]", buf); /* Done */ return 0; } /* ************************************************************** */ /* * tds3012b_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 tds3012b_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; } } /* ************************************************************** */ /* * tds3012b_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 * 5/23/01 */ int tds3012b_get_errors(int dev_ID) { /* Declare variables */ int status; int num_scan; /* Get the standard event status register value */ tds3012b_out(dev_ID, "*ESR?"); tds3012b_in(dev_ID, msg); /* Extract the status value */ num_scan = Scan(msg, "%s>%i", &status); if (num_scan != 1) { tds3012b_error("Problem getting error status"); return -1; } /* Alert the operator if there is an error */ /* Error if any of bits 5, 4, 3, 2 are set: 00111100 = 60 */ if ((status & 60) != 0) { tds3012b_out(dev_ID, "ALLEV?"); tds3012b_in(dev_ID, msg); tds3012b_message("\nTDS3012B Error:"); tds3012b_message(msg); Fmt(msg, "%s