/* ************************************************************** */ /* * Module VRZ404 * This module contains I/O functions for the Heidenhain model * VRZ404 counters. * * Zachary Wolf * 4/4/01 */ /* ************************************************************** */ /* INCLUDES */ #include #include #include #include #include "vrz404.h" /* ************************************************************** */ /* PRIVATE FUNCTIONS */ int vrz404_open_dev(int gpib_board_addr, int gpib_dev_addr); void vrz404_close_dev(int dev_ID); int vrz404_check_dev_open(int dev_ID); int vrz404_out(int dev_ID, char* buf); int vrz404_in(int dev_ID, char* buf); int vrz404_spoll(int dev_ID, int* spoll); int vrz404_get_errors(int dev_ID); void vrz404_message(char* msg); void vrz404_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[VRZ404_MAX_NUM_DEV + 1]; static int dev_descr[VRZ404_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[VRZ404_MAX_CMD + 1]; static char msg[VRZ404_MAX_CMD + 1]; /* ************************************************************** */ /* PUBLIC FUNCTIONS */ /* ************************************************************** */ /* * vrz404_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 * 4/4/01 */ void vrz404_init(int gpib_board_addr, int gpib_dev_addr, int* ID) { /* Declare variables */ int dev_ID; int err; int i; /* Message */ vrz404_message(""); vrz404_message("Initializing the Heidenhain VRZ404 counter..."); /* Check input parameters */ if (gpib_board_addr < 0 || gpib_board_addr > 10) { Fmt(msg, "%s 30) { Fmt(msg, "%s VRZ404_MAX_NUM_DEV) { Fmt(msg, "%s VRZ404_MAX_NUM_DEV) { Fmt(msg, "%s%f", &pos_mm); if (num_scan != 1) { printf("VRZ404 problem getting counter reading: %s\n", msg); printf("Try again...\n"); Delay(1.); goto try_again; } if (sign == '-') pos_mm = -pos_mm; else if (sign == '+') pos_mm = pos_mm; else printf("VRZ404 problem getting counter reading."); /* Convert from mm to m */ *pos = pos_mm / 1000.; /* Check for errors */ err = vrz404_get_errors(dev_ID); if (err != 0) { vrz404_error("The counter has an error"); vrz404_close_dev(dev_ID); *pos = 0.; return; } /* Perform a serial poll to prepare for the next read */ vrz404_spoll(dev_ID, &spoll); //printf("spoll = %i\n", spoll); /* Done */ return; } /* ************************************************************** */ /* * vrz404_exit * This function configures the VRZ404 for program exit and * closes the device. * * Input: * dev_ID, device identifier * * Zachary Wolf * 1/24/00 */ void vrz404_exit(int dev_ID) { /* Declare variables */ int dev_open; int err; /* Check input parameters */ if (dev_ID < 1 || dev_ID > VRZ404_MAX_NUM_DEV) { Fmt(msg, "%s 10) { Fmt(msg, "%s 30) { Fmt(msg, "%s 0) { return 1; /* Open */ } else { return 0; /* Not open */ } } /* ************************************************************** */ /* * vrz404_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 * 4/4/01 */ int vrz404_out(int dev_ID, char* buf) { /* Declare variables */ int nbytes; int err; char out_buf[VRZ404_MAX_CMD + 1]; /* Add CR LF to the message */ Fmt(out_buf, "%s<%s%c%c", buf, 13, 10); /* 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; } /* ************************************************************** */ /* * vrz404_spoll * This function performs a serial poll on the device. * * Input: * dev_ID, device identifier * * Output: * spoll, integer encoding the serial poll information * err, 0 if ok, -1 otherwise * * Zachary Wolf * 4/4/01 */ int vrz404_spoll(int dev_ID, int* spoll) { /* Declare variables */ int err; char spoll_byte; /* Perform the serial poll */ err = ibrsp(dev_descr[dev_ID], &spoll_byte); /* Check for errors */ if (err & 0x8000) { Fmt(msg, "%s