/* ************************************************************** */ /* * Module VMAG * This module contains functions for making magnet voltage * measurements. * * Zachary Wolf * 12/15/00 */ /* ************************************************************** */ /* INCLUDES */ #include #include #include #include #include "vmag.h" #include "hp3457.h" #include "k7011.h" /* ************************************************************** */ /* PRIVATE FUNCTIONS */ void vmag_message(char* msg); void vmag_error(char* msg); void vmag_log_device_type(enum vmag_device_type_enum device_type); void vmag_log_get_voltage(double voltage); /* ************************************************************** */ /* PRIVATE GLOBAL VARIABLES */ static int hp3457_ID; static int k7011_ID; /* ************************************************************** */ /* PRIVATE PARAMETERS */ static char log_file[100]; static struct vmag_param_struct vmag_param; /* ************************************************************** */ /* PUBLIC FUNCTIONS */ /* ************************************************************** */ /* * vmag_init * This function opens devices, queries for ID, and * initializes the devices to a known state. * * Zachary Wolf * 12/15/00 */ void vmag_init(char log_file_in[], struct vmag_param_struct vmag_param_in) { /* Save the module parameters */ strcpy(log_file, log_file_in); vmag_param = vmag_param_in; /* Initialize the appropriate devices */ if (vmag_param.device_type == VMAG_HP3457) { hp3457_init(vmag_param.board_addr, vmag_param.hp3457_addr, &hp3457_ID); } else if (vmag_param.device_type == VMAG_K7011_HP3457) { k7011_init(vmag_param.board_addr, vmag_param.k7011_addr, &k7011_ID); hp3457_init(vmag_param.board_addr, vmag_param.hp3457_addr, &hp3457_ID); } else if (vmag_param.device_type == VMAG_NONE); else vmag_error("Unknown device type."); /* Log the device type */ vmag_log_device_type(vmag_param.device_type); /* Done */ return; } /* ************************************************************** */ /* * vmag_get_voltage * This function gets the magnet voltage. * * Output: * voltage, magnet voltage (V) * * Zachary Wolf * 12/15/00 */ void vmag_get_voltage(double* voltage) { /* Perform the appropriate voltage measurement */ if (vmag_param.device_type == VMAG_HP3457) { hp3457_get_chan_voltage(hp3457_ID, vmag_param.hp3457_chan, voltage); } else if (vmag_param.device_type == VMAG_K7011_HP3457) { k7011_close_card_chan(k7011_ID, vmag_param.k7011_card_num, vmag_param.k7011_chan); hp3457_get_chan_voltage(hp3457_ID, vmag_param.k7011_hp3457_chan, voltage); k7011_open_all(k7011_ID); } else if (vmag_param.device_type == VMAG_NONE) *voltage = 0.; else vmag_error("Unknown device type."); /* Log the measurement */ vmag_log_get_voltage(*voltage); /* Done */ return; } /* ************************************************************** */ /* * vmag_exit * This function configures the vmag system for program exit. * * Zachary Wolf * 12/15/00 */ void vmag_exit(void) { /* Exit the appropriate devices */ if (vmag_param.device_type == VMAG_HP3457) { hp3457_exit(hp3457_ID); } else if (vmag_param.device_type == VMAG_K7011_HP3457) { k7011_exit(k7011_ID); hp3457_exit(hp3457_ID); } else if (vmag_param.device_type == VMAG_NONE); else vmag_error("Unknown device type."); /* Done */ return; } /* ************************************************************** */ /* PRIVATE FUNCTIONS */ /* ************************************************************** */ /* * vmag_message * This function handles messages for the module. * * Input: * message, string to display in standard I/O * * Zachary Wolf * 12/15/00 */ void vmag_message(char* message) { /* Print the message */ printf("%s\n", message); /* Done */ return; } /* ************************************************************** */ /* * vmag_error * This function handles error messages for the module. * * Input: * message, string to display in standard I/O * * Zachary Wolf * 12/15/00 */ void vmag_error(char* message) { /* Declare variables */ char buf[80]; /* Notify the operator of the error */ printf("\nVMAG 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); } /* ************************************************************** */ /* * vmag_log_device_type * This function logs the type of equipment being used. * * Input: * device_type, type of vmag readout devices * * Zachary Wolf * 12/15/00 */ void vmag_log_device_type(enum vmag_device_type_enum device_type) { /* Declare variables */ FILE* file_ptr; char type[80]; /* Put the device type in a string */ if (device_type == VMAG_HP3457) strcpy(type, "HP3457"); else if (device_type == VMAG_K7011_HP3457) strcpy(type, "K7011_HP3457"); else if (device_type == VMAG_NONE) strcpy(type, "None"); else vmag_error("Unknown device type in log device function."); /* Open the log file */ file_ptr = fopen(log_file, "a"); if (file_ptr == NULL) { vmag_message("Unable to open log file"); return; } /* Write the device type to the log file */ fprintf(file_ptr, "%s Magnet Voltage Measurement Device(s) Being Used, type = %s\n", TimeStr(), type); /* Close the log file */ fclose(file_ptr); /* Done */ return; } /* ************************************************************** */ /* * vmag_log_get_voltage * This function logs the result of a magnet voltage measurement. * * Input: * voltage, magnet voltage (V) * * Zachary Wolf * 12/15/00 */ void vmag_log_get_voltage(double voltage) { /* Declare variables */ FILE* file_ptr; /* Open the log file */ file_ptr = fopen(log_file, "a"); if (file_ptr == NULL) { vmag_message("Unable to open log file"); return; } /* Write the measured value to the log file */ fprintf(file_ptr, "%s Magnet Voltage Measurement, V = %f V\n", TimeStr(), voltage); /* Close the log file */ fclose(file_ptr); /* Done */ return; }