/* ************************************************************** */ /* * Module TELETRAC * This module contains I/O functions for the TELETRAC interferometer. * * Zachary Wolf * 1/21/03 */ /* ************************************************************** */ /* INCLUDES */ #include #include #include #include #include "teletrac.h" /* ************************************************************** */ /* PRIVATE FUNCTIONS */ int teletrac_open_dev(int gpib_board_addr, int gpib_dev_addr); void teletrac_close_dev(int dev_ID); int teletrac_check_dev_open(int dev_ID); int teletrac_out(int dev_ID, char* buf); int teletrac_in(int dev_ID, char* buf); int teletrac_spoll(int dev_ID, int* spoll); int teletrac_get_errors(int dev_ID); void teletrac_message(char* msg); void teletrac_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[TELETRAC_MAX_NUM_DEV + 1]; static int dev_descr[TELETRAC_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[TELETRAC_MAX_CMD + 1]; static char msg[TELETRAC_MAX_CMD + 1]; /* ************************************************************** */ /* PUBLIC FUNCTIONS */ /* ************************************************************** */ /* * teletrac_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 * 1/21/03 */ void teletrac_init(int gpib_board_addr, int gpib_dev_addr, int* ID) { /* Declare variables */ int dev_ID; int err; int i; /* Message */ teletrac_message(""); teletrac_message("Initializing the TELETRAC interferometer..."); printf("\nThis module has not been tested yet.\n"); /* Check input parameters */ if (gpib_board_addr < 0 || gpib_board_addr > 10) { Fmt(msg, "%s 30) { Fmt(msg, "%s TELETRAC_MAX_NUM_DEV) { Fmt(msg, "%s%c%c[d] %f", &sign, &pos_cm); if (num_scan != 3) { printf("TELETRAC problem getting interferometer reading: %s\n", msg); *pos = 0.; return; } /* Convert from cm to m */ *pos = pos_cm / 100.; /* Account for the sign */ if (sign == '-') *pos = - *pos; /* Done */ return; } /* ************************************************************** */ /* * teletrac_zero * This function zeros the interferometer. * * Input: * dev_ID, device identifier * axis, which axis position to return (x or y) * * Zachary Wolf * 1/21/03 */ void teletrac_zero(int dev_ID, char axis) { /* Declare variables */ int dev_open; /* Check input parameters */ if (dev_ID < 1 || dev_ID > TELETRAC_MAX_NUM_DEV) { Fmt(msg, "%s TELETRAC_MAX_NUM_DEV) { Fmt(msg, "%s 10) { Fmt(msg, "%s 30) { Fmt(msg, "%s 0) { return 1; /* Open */ } else { return 0; /* Not open */ } } /* ************************************************************** */ /* * teletrac_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 * 1/21/03 */ int teletrac_out(int dev_ID, char* buf) { /* Declare variables */ int nbytes; int err; char out_buf[TELETRAC_MAX_CMD + 1]; /* Add CR to the message */ Fmt(out_buf, "%s<%s%c", buf, 13); /* Send the message */ 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); /* Done */ return 0; } /* ************************************************************** */ /* * teletrac_message * This function handles messages about the TELETRAC. * * Input: * message, string to display in standard I/O * * Zachary Wolf * 12/20/99 */ void teletrac_message(char* message) { /* Print the message */ printf("%s\n", message); /* Done */ return; } /* ************************************************************** */ /* * teletrac_error * This function handles error messages for the TELETRAC. * * Input: * message, string to display in standard I/O * * Zachary Wolf * 12/20/99 */ void teletrac_error(char* message) { /* Declare variables */ char buf[80]; /* Notify the operator of the error */ printf("\nTELETRAC 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); }