/* ************************************************************** */ /* * Module BNMR * This module contains functions for making NMR probe measurements. * It is for a single NMR probe. It provides a common interface for * NMR probes from different companies. * * Zachary Wolf * 1/27/03 */ /* ************************************************************** */ /* INCLUDES */ #include #include #include #include #include "bnmr.h" #include "pt2025.h" /* ************************************************************** */ /* PRIVATE FUNCTIONS */ void bnmr_message(char* msg); void bnmr_error(char* msg); void bnmr_log_device_type(enum bnmr_device_type_enum device_type); void bnmr_log_set_mux_chan(char mux_chan); void bnmr_log_set_field_dir(char field_dir); void bnmr_log_set_coarse_adj(int probe_num, double nom_field); void bnmr_log_set_search_mode(enum bnmr_search_mode_enum search_mode); void bnmr_log_get_b(double b); /* ************************************************************** */ /* PRIVATE GLOBAL VARIABLES */ static int dev_ID; /* ************************************************************** */ /* PRIVATE PARAMETERS */ static char log_file[100]; static struct bnmr_param_struct bnmr_param; /* ************************************************************** */ /* PUBLIC FUNCTIONS */ /* ************************************************************** */ /* * bnmr_init * This function opens the device, queries for ID, and * initializes the device to a known state. * * Zachary Wolf * 1/27/03 */ void bnmr_init(char log_file_in[], struct bnmr_param_struct bnmr_param_in) { /* Save the module parameters */ strcpy(log_file, log_file_in); bnmr_param = bnmr_param_in; /* Initialize the appropriate NMR probe */ if (bnmr_param.device_type == BNMR_PT2025) pt2025_init(bnmr_param.board_addr, bnmr_param.pt2025_addr, &dev_ID); else if (bnmr_param.device_type == BNMR_NONE); else bnmr_error("Unknown device type."); /* Prepare the NMR probe for measurements */ if (bnmr_param.device_type == BNMR_PT2025) { bnmr_set_mux_chan(bnmr_param.pt2025_chan); bnmr_set_field_dir(bnmr_param.field_dir); bnmr_set_coarse_adj(bnmr_param.pt2025_probe_num, bnmr_param.nom_field); bnmr_set_search_mode(BNMR_AUTO); } else if (bnmr_param.device_type == BNMR_NONE); else bnmr_error("Unknown device type."); /* Log the device type */ bnmr_log_device_type(bnmr_param.device_type); /* Done */ return; } /* ************************************************************** */ /* * bnmr_set_mux_chan * This function sets the multiplexer channel of the teslameter. * * Input: * mux_chan, multiplexer channel * * Zachary Wolf * 1/27/03 */ void bnmr_set_mux_chan(char mux_chan) { /* Set the nominal field strength */ if (bnmr_param.device_type == BNMR_PT2025) pt2025_set_mux_chan(dev_ID, mux_chan); else if (bnmr_param.device_type == BNMR_NONE); else bnmr_error("Unknown device type."); /* Log the multiplexer channel */ bnmr_log_set_mux_chan(mux_chan); /* Done */ return; } /* ************************************************************** */ /* * bnmr_set_field_dir * This function sets the field direction setting of the teslameter. * * Input: * field_dir, field direction (+ or -) * * Zachary Wolf * 1/27/03 */ void bnmr_set_field_dir(char field_dir) { /* Set the nominal field strength */ if (bnmr_param.device_type == BNMR_PT2025) pt2025_set_field_dir(dev_ID, field_dir); else if (bnmr_param.device_type == BNMR_NONE); else bnmr_error("Unknown device type."); /* Log the field direction */ bnmr_log_set_field_dir(field_dir); /* Done */ return; } /* ************************************************************** */ /* * bnmr_set_coarse_adj * This function sets the nominal field setting of the teslameter. * Searches for a signal are centered on this value. * * Input: * probe_num, probe number * nom_field, nominal field strength (T) * * Zachary Wolf * 1/27/03 */ void bnmr_set_coarse_adj(int probe_num, double nom_field) { /* Set the nominal field strength */ if (bnmr_param.device_type == BNMR_PT2025) pt2025_set_manual_coarse(dev_ID, probe_num, nom_field); else if (bnmr_param.device_type == BNMR_NONE); else bnmr_error("Unknown device type."); /* Log the coarse adjust setting */ bnmr_log_set_coarse_adj(probe_num, nom_field); /* Done */ return; } /* ************************************************************** */ /* * bnmr_set_search_mode * This function sets the search mode of the teslameter. * * Input: * search_mode, search mode * * Zachary Wolf * 1/27/03 */ void bnmr_set_search_mode(enum bnmr_search_mode_enum search_mode) { /* Set the search mode */ if (bnmr_param.device_type == BNMR_PT2025) { if (search_mode == BNMR_MANUAL) pt2025_set_mode_manual(dev_ID); else if (search_mode == BNMR_AUTO) pt2025_set_mode_auto(dev_ID); else if (search_mode == BNMR_SEARCH) pt2025_set_mode_search(dev_ID); else bnmr_error("Unknown search mode type."); } else if (bnmr_param.device_type == BNMR_NONE); else bnmr_error("Unknown device type."); /* Log the search mode */ bnmr_log_set_search_mode(search_mode); /* Done */ return; } /* ************************************************************** */ /* * bnmr_get_b * This function gets the field reading from the teslameter. * * Output: * b, field reading (T) * * Zachary Wolf * 1/27/03 */ void bnmr_get_b(double* b) { /* Get the appropriate field measurement */ if (bnmr_param.device_type == BNMR_PT2025) pt2025_get_b(dev_ID, b); else if (bnmr_param.device_type == BNMR_NONE) *b = 0.; else bnmr_error("Unknown device type."); /* Log the measurement */ bnmr_log_get_b(*b); /* Done */ return; } /* ************************************************************** */ /* * bnmr_exit * This function configures the BNMR module for program exit and * closes the device. * * Zachary Wolf * 1/27/03 */ void bnmr_exit(void) { /* Exit the appropriate device */ if (bnmr_param.device_type == BNMR_PT2025) pt2025_exit(dev_ID); else if (bnmr_param.device_type == BNMR_NONE); else bnmr_error("Unknown device type."); /* Done */ return; } /* ************************************************************** */ /* PRIVATE FUNCTIONS */ /* ************************************************************** */ /* * bnmr_message * This function handles messages about the BNMR. * * Input: * message, string to display in standard I/O * * Zachary Wolf * 12/20/99 */ void bnmr_message(char* message) { /* Print the message */ printf("%s\n", message); /* Done */ return; } /* ************************************************************** */ /* * bnmr_error * This function handles error messages for the BNMR. * * Input: * message, string to display in standard I/O * * Zachary Wolf * 12/20/99 */ void bnmr_error(char* message) { /* Declare variables */ char buf[80]; /* Notify the operator of the error */ printf("\nBNMR 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); } /* ************************************************************** */ /* * bnmr_log_device_type * This function logs the type of NMR probe being used. * * Input: * device_type, type of NMR probe * * Zachary Wolf * 1/27/03 */ void bnmr_log_device_type(enum bnmr_device_type_enum device_type) { /* Declare variables */ FILE* file_ptr; char type[30]; /* Put the device type in a string */ if (device_type == BNMR_PT2025) strcpy(type, "PT2025"); else if (device_type == BNMR_NONE) strcpy(type, "None"); else bnmr_error("Unknown device type in log device function."); /* Open the log file */ file_ptr = fopen(log_file, "a"); if (file_ptr == NULL) { bnmr_message("Unable to open log file"); return; } /* Write the measured value to the log file */ fprintf(file_ptr, "%s NMR Probe Type Being Used, type = %s\n", TimeStr(), type); /* Close the log file */ fclose(file_ptr); /* Done */ return; } /* ************************************************************** */ /* * bnmr_log_set_mux_chan * This function logs the multiplexer channel setting. * * Input: * mux_chan, multiplexer channel * * Zachary Wolf * 1/27/03 */ void bnmr_log_set_mux_chan(char mux_chan) { /* Declare variables */ FILE* file_ptr; /* Open the log file */ file_ptr = fopen(log_file, "a"); if (file_ptr == NULL) { bnmr_message("Unable to open log file"); return; } /* Write the value to the log file */ fprintf(file_ptr, "%s NMR Probe Multiplexer Channel Setting, chan = %c\n", TimeStr(), mux_chan); /* Close the log file */ fclose(file_ptr); /* Done */ return; } /* ************************************************************** */ /* * bnmr_log_set_field_dir * This function logs the field direction setting. * * Input: * field_dir, field direction * * Zachary Wolf * 1/27/03 */ void bnmr_log_set_field_dir(char field_dir) { /* Declare variables */ FILE* file_ptr; /* Open the log file */ file_ptr = fopen(log_file, "a"); if (file_ptr == NULL) { bnmr_message("Unable to open log file"); return; } /* Write the value to the log file */ fprintf(file_ptr, "%s NMR Probe Field Direction Setting, dir = %c\n", TimeStr(), field_dir); /* Close the log file */ fclose(file_ptr); /* Done */ return; } /* ************************************************************** */ /* * bnmr_log_set_coarse_adj * This function logs the coarse adjust setting. * * Input: * probe_num, probe number * nom_field, nominal field strength (T) * * Zachary Wolf * 1/27/03 */ void bnmr_log_set_coarse_adj(int probe_num, double nom_field) { /* Declare variables */ FILE* file_ptr; /* Open the log file */ file_ptr = fopen(log_file, "a"); if (file_ptr == NULL) { bnmr_message("Unable to open log file"); return; } /* Write the measured value to the log file */ fprintf(file_ptr, "%s NMR Probe Coarse Adjust Setting, probe_num = %i, nom_field = %f T\n", TimeStr(), probe_num, nom_field); /* Close the log file */ fclose(file_ptr); /* Done */ return; } /* ************************************************************** */ /* * bnmr_log_set_search_mode * This function logs the NMR signal search mode being used. * * Input: * search_mode, type of NMR probe search mode * * Zachary Wolf * 1/27/03 */ void bnmr_log_set_search_mode(enum bnmr_search_mode_enum search_mode) { /* Declare variables */ FILE* file_ptr; char mode[30]; /* Put the search mode in a string */ if (search_mode == BNMR_MANUAL) strcpy(mode, "Manual"); else if (search_mode == BNMR_AUTO) strcpy(mode, "Auto"); else if (search_mode == BNMR_SEARCH) strcpy(mode, "Search"); else bnmr_error("Unknown search mode."); /* Open the log file */ file_ptr = fopen(log_file, "a"); if (file_ptr == NULL) { bnmr_message("Unable to open log file"); return; } /* Write the value to the log file */ fprintf(file_ptr, "%s NMR Probe Search Mode Type Being Used, mode = %s\n", TimeStr(), mode); /* Close the log file */ fclose(file_ptr); /* Done */ return; } /* ************************************************************** */ /* * bnmr_log_get_b * This function logs the result of a field strength measurement. * * Input: * b, field strength (T) * * Zachary Wolf * 1/27/03 */ void bnmr_log_get_b(double b) { /* Declare variables */ FILE* file_ptr; /* Open the log file */ file_ptr = fopen(log_file, "a"); if (file_ptr == NULL) { bnmr_message("Unable to open log file"); return; } /* Write the measured value to the log file */ fprintf(file_ptr, "%s NMR Probe Field Measurement, B = %f T\n", TimeStr(), b); /* Close the log file */ fclose(file_ptr); /* Done */ return; }