/* ************************************************************** */ /* * Module TDS754D * This module contains I/O functions for the Tektronix TDS754D * oscilloscope. * * Zachary Wolf * 5/18/01 */ /* ************************************************************** */ /* INCLUDES */ #include #include #include #include #include "tds754d.h" /* ************************************************************** */ /* PRIVATE FUNCTIONS */ int tds754d_open_dev(int gpib_board_addr, int gpib_dev_addr); void tds754d_close_dev(int dev_ID); int tds754d_out(int dev_ID, char* buf); int tds754d_in(int dev_ID, char* buf); int tds754d_in_waveform(int dev_ID, char* buf); int tds754d_check_device_open(int dev_ID); int tds754d_get_errors(int dev_ID); void tds754d_message(char* msg); void tds754d_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[TDS754D_MAX_NUM_DEV + 1]; static int dev_descr[TDS754D_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[TDS754D_MAX_CMD + 1]; static char msg[TDS754D_MAX_CMD + 1]; /* ************************************************************** */ /* PUBLIC FUNCTIONS */ /* ************************************************************** */ /* * tds754d_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 * 5/18/01 */ void tds754d_init(int gpib_board_addr, int gpib_dev_addr, int* ID) { /* Declare variables */ int dev_ID; int err; /* Message */ tds754d_message(""); tds754d_message("Initializing the TDS754D..."); /* Check input parameters */ if (gpib_board_addr < 0 || gpib_board_addr > 10) { Fmt(msg, "%s 30) { Fmt(msg, "%s TDS754D_MAX_NUM_DEV) { Fmt(msg, "%s TDS754D_MAX_NUM_DEV) { Fmt(msg, "%s 4) { Fmt(msg, "%s 10.) { Fmt(msg, "%s TDS754D_MAX_NUM_DEV) { Fmt(msg, "%s 4) { Fmt(msg, "%s 5.) { Fmt(msg, "%s TDS754D_MAX_NUM_DEV) { Fmt(msg, "%s 4) { Fmt(msg, "%s TDS754D_MAX_NUM_DEV) { Fmt(msg, "%s 4) { Fmt(msg, "%s TDS754D_MAX_NUM_DEV) { Fmt(msg, "%s 10.) { Fmt(msg, "%s TDS754D_MAX_NUM_DEV) { Fmt(msg, "%s TDS754D_MAX_NUM_DEV) { Fmt(msg, "%s 100) { Fmt(msg, "%s TDS754D_MAX_NUM_DEV) { Fmt(msg, "%s TDS754D_MAX_NUM_DEV) { Fmt(msg, "%s TDS754D_MAX_NUM_DEV) { Fmt(msg, "%s TDS754D_MAX_NUM_DEV) { Fmt(msg, "%s 12.) { Fmt(msg, "%s TDS754D_MAX_NUM_DEV) { Fmt(msg, "%s 10.) { Fmt(msg, "%s TDS754D_MAX_NUM_DEV) { Fmt(msg, "%s TDS754D_MAX_NUM_DEV) { Fmt(msg, "%s 10000) { Fmt(msg, "%s TDS754D_MAX_NUM_DEV) { Fmt(msg, "%s 4) { Fmt(msg, "%s:HOR:RECO %i", &rec_len); if (num_scan != 1) tds754d_error("tds754d_get_waveform: Problem reading rec_len"); /* Setup to read the waveform */ Fmt(cmd, "%s:WFMP:CH%i[w1]:NR_P %i", &chan_rtn, &num_pts); if (num_scan != 2) tds754d_error("tds754d_get_waveform: Problem reading num_pts"); if (chan_rtn != chan) tds754d_error("tds754d_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) tds754d_error("tds754d_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) tds754d_error("tds754d_get_waveform: Problem reading y_off"); if (chan_rtn != chan) tds754d_error("tds754d_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) tds754d_error("tds754d_get_waveform: Problem reading y_mult"); if (chan_rtn != chan) tds754d_error("tds754d_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) tds754d_error("tds754d_get_waveform: Problem reading x_incr"); if (chan_rtn != chan) tds754d_error("tds754d_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) tds754d_error("tds754d_get_waveform: Problem reading pt_off"); if (chan_rtn != chan) tds754d_error("tds754d_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 = tds754d_get_errors(dev_ID); if (err != 0) { tds754d_error("The device has an error"); tds754d_close_dev(dev_ID); return; } /* Done */ return; } /* ************************************************************** */ /* * tds754d_exit * This function puts the TDS754D in a desired state and closes the device. * * Input: * dev_ID, device identifier * * Zachary Wolf * 5/18/01 */ void tds754d_exit(int dev_ID) { /* Declare variables */ int dev_open; int err; /* Check input parameters */ if (dev_ID < 1 || dev_ID > TDS754D_MAX_NUM_DEV) { Fmt(msg, "%s 10) { Fmt(msg, "%s 30) { Fmt(msg, "%s%s[t-]", buf); /* Done */ return 0; } /* ************************************************************** */ /* * tds754d_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 * 5/18/01 */ int tds754d_in_waveform(int dev_ID, char* buf) { /* Declare variables */ int err; char in_buf[TDS754D_MAX_WAVEFORM]; /* Read the message */ err = ibrd(dev_descr[dev_ID], in_buf, TDS754D_MAX_WAVEFORM); /* Check for errors */ if (err & 0x8000) { Fmt(msg, "%s%s[t-]", buf); /* Done */ return 0; } /* ************************************************************** */ /* * tds754d_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 tds754d_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; } } /* ************************************************************** */ /* * tds754d_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 tds754d_get_errors(int dev_ID) { /* Declare variables */ int status; int num_scan; /* Get the standard event status register value */ tds754d_out(dev_ID, "*ESR?"); tds754d_in(dev_ID, msg); /* Extract the status value */ num_scan = Scan(msg, "%s>%i", &status); if (num_scan != 1) { tds754d_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) { tds754d_out(dev_ID, "ALLEV?"); tds754d_in(dev_ID, msg); tds754d_message("\nTDS754D Error:"); tds754d_message(msg); Fmt(msg, "%s