/* ************************************************************** */ /* * Module TMAG * This module contains functions for making temperature measurements. * * Zachary Wolf * 11/17/00 */ /* ************************************************************** */ /* INCLUDES */ #include #include #include #include #include "tmag.h" #include "hp3457.h" #include "k7011.h" /* ************************************************************** */ /* PRIVATE FUNCTIONS */ void tmag_message(char* msg); void tmag_error(char* msg); void tmag_log_device_type(enum tmag_device_type_enum device_type); void tmag_log_probe_temp(int probe_num, double probe_temp); /* ************************************************************** */ /* PRIVATE GLOBAL VARIABLES */ static int hp3457_ID; static int k7011_ID; /* ************************************************************** */ /* PRIVATE PARAMETERS */ static char dat_file[100]; static char log_file[100]; static struct tmag_param_struct tmag_param; /* ************************************************************** */ /* PUBLIC FUNCTIONS */ /* ************************************************************** */ /* * tmag_init * This function opens devices, queries for ID, and * initializes the devices to a known state. * * Zachary Wolf * 11/17/00 */ void tmag_init(char log_file_in[], char dat_file_in[], struct tmag_param_struct tmag_param_in) { /* Save the module parameters */ strcpy(log_file, log_file_in); strcpy(dat_file, dat_file_in); tmag_param = tmag_param_in; /* Check parameters */ if (tmag_param.num_tmag_probes < 0 || tmag_param.num_tmag_probes > TMAG_MAX_NUM_PROBES) { tmag_error("tmag_init: Improper num_tmag_probes"); return; } /* Initialize the appropriate devices */ if (tmag_param.device_type == TMAG_HPTHERM_HP3457) { hp3457_init(tmag_param.board_addr, tmag_param.hp3457_addr, &hp3457_ID); } else if (tmag_param.device_type == TMAG_HPTHERM_K7011_HP3457) { k7011_init(tmag_param.board_addr, tmag_param.k7011_addr, &k7011_ID); hp3457_init(tmag_param.board_addr, tmag_param.hp3457_addr, &hp3457_ID); } else if (tmag_param.device_type == TMAG_YSI44036_HP3457) { hp3457_init(tmag_param.board_addr, tmag_param.hp3457_addr, &hp3457_ID); } else if (tmag_param.device_type == TMAG_NONE); else tmag_error("Unknown device type."); /* Log the device type */ tmag_log_device_type(tmag_param.device_type); /* Done */ return; } /* ************************************************************** */ /* * tmag_get_num_probes * This function gets the number of temperature probes. * * Output: * num_probes, number of temperature probes * * Zachary Wolf * 11/17/00 */ void tmag_get_num_probes(int* num_probes) { /* Return the number of probes */ if (tmag_param.device_type != TMAG_NONE) *num_probes = tmag_param.num_tmag_probes; else *num_probes = 0; /* Done */ return; } /* ************************************************************** */ /* * tmag_get_probe_name * This function gets the name of a specified probe. * * Input: * probe_num, probe number, 0 to tmag_param.num_tmag_probes - 1 * * Output: * probe_name, name of the specified probe * * Zachary Wolf * 12/14/00 */ void tmag_get_probe_name(int probe_num, char probe_name[]) { /* Check parameters */ if (tmag_param.device_type == TMAG_NONE) return; if (probe_num < 0 || probe_num >= tmag_param.num_tmag_probes) { tmag_error("Improper probe_num"); return; } /* Return the name of the probe */ strcpy(probe_name, tmag_param.probe[probe_num].name); /* Done */ return; } /* ************************************************************** */ /* * tmag_get_probe_temp * This function gets the temperature from a specified probe. * * Input: * probe_num, probe number, 0 to tmag_param.num_tmag_probes - 1 * * Output: * probe_temp, temperature from the specified probe (deg C) * * Zachary Wolf * 11/17/00 */ void tmag_get_probe_temp(int probe_num, double* probe_temp) { /* Declare variables */ int chan; double probe_resistance; double R_25, dRdT_25, T_25, A, B; /* Check parameters */ if (tmag_param.device_type == TMAG_NONE) return; if (probe_num < 0 || probe_num >= tmag_param.num_tmag_probes) { tmag_error("Improper probe_num"); return; } /* Get the channel number for the specified probe */ chan = tmag_param.probe[probe_num].chan_num; /* Perform the appropriate temperature measurement */ if (tmag_param.device_type == TMAG_HPTHERM_HP3457) { hp3457_get_chan_temperature(hp3457_ID, chan, probe_temp); } else if (tmag_param.device_type == TMAG_HPTHERM_K7011_HP3457) { k7011_close_card_chan(k7011_ID, tmag_param.k7011_card_num, chan); hp3457_get_chan_temperature(hp3457_ID, tmag_param.k7011_hp3457_chan, probe_temp); k7011_open_all(k7011_ID); } else if (tmag_param.device_type == TMAG_YSI44036_HP3457) { hp3457_get_chan_resistance(hp3457_ID, chan, &probe_resistance); R_25 = TMAG_YSI44036_R25; dRdT_25 = TMAG_YSI44036_dRdT25; T_25 = 25. + 273.15; /* R = A e^(B/T) */ B = - pow(T_25, 2) * dRdT_25 / R_25; A = R_25 * exp(-B/T_25); *probe_temp = (B / log(probe_resistance / A)) - 273.15; } else if (tmag_param.device_type == TMAG_NONE) *probe_temp = 0.; else tmag_error("Unknown device type."); /* Log the measurement */ tmag_log_probe_temp(probe_num, *probe_temp); /* Done */ return; } /* ************************************************************** */ /* * tmag_meas * This function measures all temperatures. * * Output: * tmag_num, number of temperature measurements * tmag_name[0 to num_tmag - 1], name of each temperature measurement * tmag_value[0 to num_tmag - 1], temperature measurement values (deg C) * * Zachary Wolf * 10/12/01 */ void tmag_meas(int* tmag_num, char tmag_name[][TMAG_MAX_NAME_LENGTH], double tmag_value[]) { /* Declare variables */ int i; /* Measure all temperatures */ tmag_get_num_probes(tmag_num); if (*tmag_num > TMAG_MAX_NUM_PROBES) tmag_error("Maximum number of temperature probes exceeded"); for (i = 0; i < *tmag_num; i++) { tmag_get_probe_name(i, tmag_name[i]); tmag_get_probe_temp(i, &tmag_value[i]); } /* Write a header for the results */ printf("\n"); printf(" Temperature Measurements\n"); printf("\n"); for (i = 0; i < *tmag_num; i++) { printf("T%i = %s\n", i, tmag_name[i]); } printf("\n"); for (i = 0; i < *tmag_num; i++) printf(" T%i ", i); printf("\n"); for (i = 0; i < *tmag_num; i++) printf(" -------"); printf("\n"); /* Write the data */ for (i = 0; i < *tmag_num; i++) printf(" %7.2f", tmag_value[i]); printf("\n"); /* Done */ return; } /* ************************************************************** */ /* * tmag_dat_meas * This function writes the results of magnet temperature measurements * to the data file. * * Input: * tmag_num, number of temperature measurements * tmag_name[0 to num_tmag - 1], name of each temperature measurement * tmag_value[0 to num_tmag - 1], temperature measurement values (deg C) * * Zachary Wolf * 10/12/01 */ void tmag_dat_meas(int tmag_num, char tmag_name[][TMAG_MAX_NAME_LENGTH], double tmag_value[]) { /* Declare variables */ FILE* file_ptr; int i; /* Open the data file */ file_ptr = fopen(dat_file, "a"); if (file_ptr == NULL) { printf("tmag_dat_meas: Unable to open dat file\n"); return; } /* Write a header */ fprintf(file_ptr, "\nTemperature Measurements:\n"); /* Write the data */ for (i = 0; i < tmag_num; i++) fprintf(file_ptr, "%s, T%i = %7.2f C\n", tmag_name[i], i, tmag_value[i]); /* Close the dat file */ fclose(file_ptr); /* Done */ return; } /* ************************************************************** */ /* * tmag_dat_meas_vs_time * This function writes the results of magnet temperature measurements * to the data file. * * Input: * tmag_num, number of temperature measurements * tmag_name[0 to num_tmag - 1], name of each temperature measurement * tmag_value[0 to num_tmag - 1], temperature measurement values (deg C) * * Zachary Wolf * 10/12/01 */ void tmag_dat_meas_vs_time(int tmag_num, char tmag_name[][TMAG_MAX_NAME_LENGTH], double tmag_value[]) { /* Declare variables */ FILE* file_ptr; static int call_num; int i; /* Open the data file */ file_ptr = fopen(dat_file, "a"); if (file_ptr == NULL) { printf("tmag_dat_meas: Unable to open dat file\n"); return; } /* Increment the number of calls */ call_num++; /* Write a header on the first call */ if (call_num == 1) { fprintf(file_ptr, "\n"); fprintf(file_ptr, "\n"); fprintf(file_ptr, " Temperature Measurements\n"); fprintf(file_ptr, "\n"); for (i = 0; i < tmag_num; i++) { fprintf(file_ptr, "T%i = %s\n", i, tmag_name[i]); } fprintf(file_ptr, "\n"); fprintf(file_ptr, " Time "); for (i = 0; i < tmag_num; i++) fprintf(file_ptr, " T%i ", i); fprintf(file_ptr, "\n"); fprintf(file_ptr, "--------"); for (i = 0; i < tmag_num; i++) fprintf(file_ptr, " -------"); fprintf(file_ptr, "\n"); } /* Write the data */ fprintf(file_ptr, "%s", TimeStr()); for (i = 0; i < tmag_num; i++) fprintf(file_ptr, " %7.2f", tmag_value[i]); fprintf(file_ptr, "\n"); /* Close the dat file */ fclose(file_ptr); /* Done */ return; } /* ************************************************************** */ /* * tmag_exit * This function configures the tmag system for program exit. * * Zachary Wolf * 11/17/00 */ void tmag_exit(void) { /* Exit the appropriate devices */ if (tmag_param.device_type == TMAG_HPTHERM_HP3457) { hp3457_exit(hp3457_ID); } else if (tmag_param.device_type == TMAG_HPTHERM_K7011_HP3457) { k7011_exit(k7011_ID); hp3457_exit(hp3457_ID); } else if (tmag_param.device_type == TMAG_YSI44036_HP3457) { hp3457_exit(hp3457_ID); } else if (tmag_param.device_type == TMAG_NONE); else tmag_error("Unknown device type."); /* Done */ return; } /* ************************************************************** */ /* PRIVATE FUNCTIONS */ /* ************************************************************** */ /* * tmag_message * This function handles messages for the module. * * Input: * message, string to display in standard I/O * * Zachary Wolf * 11/17/00 */ void tmag_message(char* message) { /* Print the message */ printf("%s\n", message); /* Done */ return; } /* ************************************************************** */ /* * tmag_error * This function handles error messages for the module. * * Input: * message, string to display in standard I/O * * Zachary Wolf * 11/17/00 */ void tmag_error(char* message) { /* Declare variables */ char buf[80]; /* Notify the operator of the error */ printf("\nTMAG 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); } /* ************************************************************** */ /* * tmag_log_device_type * This function logs the type of equipment being used. * * Input: * device_type, type of tmag readout devices * * Zachary Wolf * 11/17/00 */ void tmag_log_device_type(enum tmag_device_type_enum device_type) { /* Declare variables */ FILE* file_ptr; char type[80]; /* Put the device type in a string */ if (device_type == TMAG_HPTHERM_HP3457) strcpy(type, "HPTHERM_HP3457"); else if (device_type == TMAG_HPTHERM_K7011_HP3457) strcpy(type, "HPTHERM_K7011_HP3457"); else if (device_type == TMAG_YSI44036_HP3457) strcpy(type, "YSI44036_HP3457"); else if (device_type == TMAG_NONE) strcpy(type, "None"); else tmag_error("Unknown device type in log device function."); /* Open the log file */ file_ptr = fopen(log_file, "a"); if (file_ptr == NULL) { tmag_message("Unable to open log file"); return; } /* Write the device type to the log file */ fprintf(file_ptr, "%s Temperature Measurement Device(s) Being Used, type = %s\n", TimeStr(), type); /* Close the log file */ fclose(file_ptr); /* Done */ return; } /* ************************************************************** */ /* * tmag_log_probe_temp * This function logs the result of a probe temperature measurement. * * Input: * probe_num, probe number * probe_temp, temperature (deg C) * * Zachary Wolf * 11/17/00 */ void tmag_log_probe_temp(int probe_num, double probe_temp) { /* Declare variables */ FILE* file_ptr; /* Open the log file */ file_ptr = fopen(log_file, "a"); if (file_ptr == NULL) { tmag_message("Unable to open log file"); return; } /* Write the measured value to the log file */ fprintf(file_ptr, "%s Temperature Measurement, Probe Number = %i, T = %f C\n", TimeStr(), probe_num, probe_temp); /* Close the log file */ fclose(file_ptr); /* Done */ return; }