/* ************************************************************** */ /* * Module MF10D * This module contains I/O functions for the Walker fluxmeter * model MF-10D. * * Zachary Wolf * 12/14/05 */ /* ************************************************************** */ /* INCLUDES */ #include #include #include #include #include "mf10d.h" /* ************************************************************** */ /* PRIVATE FUNCTIONS */ int mf10d_open_dev(int gpib_board_addr, int gpib_dev_addr); void mf10d_close_dev(int dev_ID); int mf10d_check_dev_open(int dev_ID); int mf10d_out(int dev_ID, char* buf); int mf10d_in(int dev_ID, char* buf); void mf10d_message(char* msg); void mf10d_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[MF10D_MAX_NUM_DEV + 1]; static int dev_descr[MF10D_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[MF10D_MAX_CMD + 1]; static char msg[MF10D_MAX_CMD + 1]; /* ************************************************************** */ /* PUBLIC FUNCTIONS */ /* ************************************************************** */ /* * mf10d_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: * ID, identifier for future references to the device * * Zachary Wolf * 12/14/05 */ void mf10d_init(int gpib_board_addr, int gpib_dev_addr, int* ID) { /* Declare variables */ int dev_ID; int err; int i; /* Message */ mf10d_message(""); mf10d_message("Initializing the MF10D..."); /* Check input parameters */ if (gpib_board_addr < 0 || gpib_board_addr > 10) { Fmt(msg, "%s 30) { Fmt(msg, "%s MF10D_MAX_NUM_DEV) { Fmt(msg, "%s MF10D_MAX_NUM_DEV) { Fmt(msg, "%s MF10D_MAX_NUM_DEV) { Fmt(msg, "%s MF10D_MAX_NUM_DEV) { Fmt(msg, "%s MF10D_MAX_NUM_DEV) { Fmt(msg, "%s%c%f %s", &sign, &value, units); if (num_scan != 3) mf10d_error("Error reading measurement"); if (strcmp(units, "mWebts") != 0) mf10d_error("Error reading measurement, units wrong"); /* Return the measured value in Vs */ *vt = value; /* Done */ return; } /* ************************************************************** */ /* * mf10d_start_vt_peak_meas * This function sets up the fluxmeter for a peak integrated voltage * measurement. At the end, it resets the fluxmeter and the * integration begins. * * Input: * dev_ID, device identifier * gain, amplifier gain (1, 10, or 100) * * Zachary Wolf * 12/14/05 */ void mf10d_start_vt_peak_meas(int dev_ID, int gain) { /* Declare variables */ int dev_open; /* Check input parameters */ if (dev_ID < 1 || dev_ID > MF10D_MAX_NUM_DEV) { Fmt(msg, "%s MF10D_MAX_NUM_DEV) { Fmt(msg, "%sPeak value is: %f %s", &value, units); if (num_scan != 2) mf10d_error("Error reading peak measurement"); if (strcmp(units, "uWt's") != 0) mf10d_error("Error reading peak measurement, units wrong"); /* Return the measured peak value in Vs */ *vt_peak = value; /* Done */ return; } /* ************************************************************** */ /* * mf10d_exit * This function puts the MF10D in the desired state for exit * and closes the device. * * Input: * dev_ID, device identifier * * Zachary Wolf * 12/14/05 */ void mf10d_exit(int dev_ID) { /* Declare variables */ int dev_open; /* Check input parameters */ if (dev_ID < 1 || dev_ID > MF10D_MAX_NUM_DEV) { Fmt(msg, "%s 10) { Fmt(msg, "%s 30) { Fmt(msg, "%s 0) { return 1; /* Open */ } else { return 0; /* Not open */ } } /* ************************************************************** */ /* * mf10d_out * This function writes a buffer of data to the device. * * Input: * dev_ID, device identifier * buf, null terminated string, the contents up to \0 are sent * * Output: * err, 0 if ok, -1 otherwise * * Zachary Wolf * 12/14/05 */ int mf10d_out(int dev_ID, char* buf) { /* Declare variables */ char out_buf[MF10D_MAX_CMD]; int nbytes; int err; /* Add CR LF to the command */ Fmt(out_buf, "%s<%s%c%c", buf, 13, 10); /* Send the command */ nbytes = StringLength(out_buf); err = ibwrt(dev_descr[dev_ID], out_buf, (long)nbytes); /* Check for errors */ if (err & 0x8000) { Fmt(msg, "%s%s[t-]", buf); /* Only LF is sent */ //Scan(in_buf, "%s[t13t00]>%s[t-]", buf); /* Done */ return 0; } /* ************************************************************** */ /* * mf10d_message * This function handles messages about the MF10D. * * Input: * message, string to display in standard I/O * * Zachary Wolf * 8/3/98 */ void mf10d_message(char* message) { /* Print the message */ printf("%s\n", message); /* Done */ return; } /* ************************************************************** */ /* * mf10d_error * This function handles error messages for the MF10D. * * Input: * message, string to display in standard I/O * * Zachary Wolf * 8/3/98 */ void mf10d_error(char* message) { /* Declare variables */ char buf[80]; /* Notify the operator of the error */ printf("\nMF10D 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); }