/* ************************************************************** */ /* * Module BHALL * This module contains functions for making Hall probe measurements. * It is for a single Hall probe. It provides a common interface for * Hall probes from different companies. * * Zachary Wolf * 1/28/00 */ /* ************************************************************** */ /* INCLUDES */ #include #include #include #include #include "bhall.h" #include "gp3.h" #include "b9900.h" #include "ls450.h" /* ************************************************************** */ /* PRIVATE FUNCTIONS */ void bhall_message(char* msg); void bhall_error(char* msg); void bhall_log_device_type(enum bhall_device_type_enum device_type); void bhall_log_range(int range); void bhall_log_zero(void); void bhall_log_b(double B); /* ************************************************************** */ /* PRIVATE GLOBAL VARIABLES */ static int dev_ID; /* ************************************************************** */ /* PRIVATE PARAMETERS */ static char log_file[100]; static struct bhall_param_struct bhall_param; /* ************************************************************** */ /* PUBLIC FUNCTIONS */ /* ************************************************************** */ /* * bhall_init * This function opens the device, queries for ID, * initializes the device to a known state, and zeros the probe. * * Zachary Wolf * 1/28/00 */ void bhall_init(char log_file_in[], struct bhall_param_struct bhall_param_in) { /* Save the module parameters */ strcpy(log_file, log_file_in); bhall_param = bhall_param_in; /* Initialize the appropriate Hall probe */ if (bhall_param.device_type == BHALL_B9900) b9900_init(bhall_param.board_addr, bhall_param.b9900_addr, &dev_ID); else if (bhall_param.device_type == BHALL_GP3) gp3_init(bhall_param.board_addr, bhall_param.gp3_addr, &dev_ID); else if (bhall_param.device_type == BHALL_LS450) ls450_init(bhall_param.board_addr, bhall_param.ls450_addr, &dev_ID); else if (bhall_param.device_type == BHALL_NONE); else bhall_error("Unknown device type."); /* Set the Hall probe to a known state */ //bhall_default_setup(); /* This is already done in hallprobe_init */ /* Zero the Hall probe */ bhall_zero(); /* Log the device type */ bhall_log_device_type(bhall_param.device_type); /* Done */ return; } /* ************************************************************** */ /* * bhall_default_setup * This function sets up the teslameter in a default state. * * Zachary Wolf * 1/28/00 */ void bhall_default_setup(void) { /* Set up the appropriate Hall probe */ if (bhall_param.device_type == BHALL_B9900) b9900_default_setup(dev_ID); else if (bhall_param.device_type == BHALL_GP3) gp3_default_setup(dev_ID); else if (bhall_param.device_type == BHALL_LS450) ls450_default_setup(dev_ID); else if (bhall_param.device_type == BHALL_NONE); else bhall_error("Unknown device type."); /* Done */ return; } /* ************************************************************** */ /* * bhall_set_range * This function sets the range of the teslameter. * * Input: * range, range, must be appropriate for the device being used * * Zachary Wolf * 1/28/00 */ void bhall_set_range(int range) { /* Set range on the appropriate Hall probe */ if (bhall_param.device_type == BHALL_B9900) b9900_set_range(dev_ID, bhall_param.b9900_chan, range); else if (bhall_param.device_type == BHALL_GP3) gp3_set_range(dev_ID, range); else if (bhall_param.device_type == BHALL_LS450) ls450_set_range(dev_ID, range); else if (bhall_param.device_type == BHALL_NONE); else bhall_error("Unknown device type."); /* Log the range */ bhall_log_range(range); /* Done */ return; } /* ************************************************************** */ /* * bhall_zero * This function zeros all ranges of the teslameter. * * Zachary Wolf * 1/28/00 */ void bhall_zero(void) { /* Declare variables */ char buf[80]; /* Have the user put the probe in a zero Gauss chamber */ printf("\nGaussmeter Zero\n"); printf("Please place the Hall probe in a zero Gauss chamber.\n"); printf("Press ENTER when ready."); fgets(buf, 80, stdin); printf("Zeroing the Gaussmeter...\n"); printf("This will take 10 to 20 seconds.\n"); /* Zero the appropriate Hall probe */ if (bhall_param.device_type == BHALL_B9900) b9900_zero(dev_ID, bhall_param.b9900_chan); else if (bhall_param.device_type == BHALL_GP3) gp3_zero(dev_ID); else if (bhall_param.device_type == BHALL_LS450) ls450_zero(dev_ID); else if (bhall_param.device_type == BHALL_NONE); else bhall_error("Unknown device type."); /* Log the zeroing */ bhall_log_zero(); /* Message */ printf("The Hall probe is zeroed.\n"); /* Done */ return; } /* ************************************************************** */ /* * bhall_get_B * This function gets the field reading from the teslameter. * * Output: * B, field reading (T) * * Zachary Wolf * 1/28/00 */ void bhall_get_B(double* B) { /* Get the appropriate field measurement */ if (bhall_param.device_type == BHALL_B9900) b9900_get_B(dev_ID, bhall_param.b9900_chan, B); else if (bhall_param.device_type == BHALL_GP3) gp3_get_B(dev_ID, B); else if (bhall_param.device_type == BHALL_LS450) ls450_get_B(dev_ID, B); else if (bhall_param.device_type == BHALL_NONE) *B = 0.; else bhall_error("Unknown device type."); /* Log the measurement */ bhall_log_b(*B); /* Done */ return; } /* ************************************************************** */ /* * bhall_exit * This function configures the BHALL for program exit and * closes the device. * * Zachary Wolf * 1/28/00 */ void bhall_exit(void) { /* Get the appropriate field measurement */ if (bhall_param.device_type == BHALL_B9900) b9900_exit(dev_ID); else if (bhall_param.device_type == BHALL_GP3) gp3_exit(dev_ID); else if (bhall_param.device_type == BHALL_LS450) ls450_exit(dev_ID); else if (bhall_param.device_type == BHALL_NONE); else bhall_error("Unknown device type."); /* Done */ return; } /* ************************************************************** */ /* PRIVATE FUNCTIONS */ /* ************************************************************** */ /* * bhall_message * This function handles messages about the BHALL. * * Input: * message, string to display in standard I/O * * Zachary Wolf * 12/20/99 */ void bhall_message(char* message) { /* Print the message */ printf("%s\n", message); /* Done */ return; } /* ************************************************************** */ /* * bhall_error * This function handles error messages for the BHALL. * * Input: * message, string to display in standard I/O * * Zachary Wolf * 12/20/99 */ void bhall_error(char* message) { /* Declare variables */ char buf[80]; /* Notify the operator of the error */ printf("\nBHALL 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); } /* ************************************************************** */ /* * bhall_log_device_type * This function logs the type of Hall probe being used. * * Input: * device_type, type of Hall probe * * Zachary Wolf * 1/31/00 */ void bhall_log_device_type(enum bhall_device_type_enum device_type) { /* Declare variables */ FILE* file_ptr; char type[30]; /* Put the device type in a string */ if (device_type == BHALL_B9900) strcpy(type, "B9900"); else if (device_type == BHALL_GP3) strcpy(type, "Group3"); else if (device_type == BHALL_LS450) strcpy(type, "LS450"); else if (device_type == BHALL_NONE) strcpy(type, "None"); else bhall_error("Unknown device type in log device function."); /* Open the log file */ file_ptr = fopen(log_file, "a"); if (file_ptr == NULL) { bhall_message("Unable to open log file"); return; } /* Write the measured value to the log file */ fprintf(file_ptr, "%s Hall Probe Type Being Used, type = %s\n", TimeStr(), type); /* Close the log file */ fclose(file_ptr); /* Done */ return; } /* ************************************************************** */ /* * bhall_log_range * This function logs the Hall probe range setting. * * Input: * range, field strength range * * Zachary Wolf * 1/31/00 */ void bhall_log_range(int range) { /* Declare variables */ FILE* file_ptr; /* Open the log file */ file_ptr = fopen(log_file, "a"); if (file_ptr == NULL) { bhall_message("Unable to open log file"); return; } /* Write the measured value to the log file */ fprintf(file_ptr, "%s Hall Probe Range Set, range = %i\n", TimeStr(), range); /* Close the log file */ fclose(file_ptr); /* Done */ return; } /* ************************************************************** */ /* * bhall_log_zero * This function logs the zeroing of a Hall probe. * * Zachary Wolf * 1/31/00 */ void bhall_log_zero(void) { /* Declare variables */ FILE* file_ptr; /* Open the log file */ file_ptr = fopen(log_file, "a"); if (file_ptr == NULL) { bhall_message("Unable to open log file"); return; } /* Write the measured value to the log file */ fprintf(file_ptr, "%s Hall Probe Zeroed\n", TimeStr()); /* Close the log file */ fclose(file_ptr); /* Done */ return; } /* ************************************************************** */ /* * bhall_log_b * This function logs the result of a field strength measurement. * * Input: * B, field strength (T) * * Zachary Wolf * 1/31/00 */ void bhall_log_b(double B) { /* Declare variables */ FILE* file_ptr; /* Open the log file */ file_ptr = fopen(log_file, "a"); if (file_ptr == NULL) { bhall_message("Unable to open log file"); return; } /* Write the measured value to the log file */ fprintf(file_ptr, "%s Hall Probe Field Measurement, B = %f T\n", TimeStr(), B); /* Close the log file */ fclose(file_ptr); /* Done */ return; }