/* ************************************************************** */ /* * 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 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[], struct tmag_param_struct tmag_param_in) { /* Save the module parameters */ strcpy(log_file, log_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_THERMISTOR_HP3457) { hp3457_init(tmag_param.board_addr, tmag_param.hp3457_addr, &hp3457_ID); } else if (tmag_param.device_type == TMAG_THERMISTOR_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_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; /* 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_THERMISTOR_HP3457) { hp3457_get_chan_temperature(hp3457_ID, chan, probe_temp); } else if (tmag_param.device_type == TMAG_THERMISTOR_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_NONE) *probe_temp = 0.; else tmag_error("Unknown device type."); /* Log the measurement */ tmag_log_probe_temp(probe_num, *probe_temp); /* 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_THERMISTOR_HP3457) { hp3457_exit(hp3457_ID); } else if (tmag_param.device_type == TMAG_THERMISTOR_K7011_HP3457) { k7011_exit(k7011_ID); 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_THERMISTOR_HP3457) strcpy(type, "THERMISTOR_HP3457"); else if (device_type == TMAG_THERMISTOR_K7011_HP3457) strcpy(type, "THERMISTOR_K7011_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; }