/* ************************************************************** */ /* * Module ps_gap_ui * This module contains functions for the phase shifter gap measurement * system user interface. * * Zachary Wolf * 11/28/17 */ /* ************************************************************** */ /* INCLUDES */ #include #include #include #include #include /* Needed if linking in external compiler; harmless otherwise */ #include #include "ps_gap_uir.h" #include "ps_gap_ui.h" #include "ps_gap.h" #include "ps_gap_ctrl_ui.h" #include "hp34970.h" #include #include #include #include #include /* ************************************************************** */ /* PRIVATE VARIABLES */ static int hp34970_id; static int ps_gap_panel_id; static char log_file[200]; static char gap_dat_file[200]; double dist_up; double dist_dn; double gap; long enc_count; double enc_gap; double temp; double temp_ref; /* ************************************************************** */ /* PRIVATE FUNCTION DECLARATIONS */ void ps_gap_ui_error(char* msg); void ps_gap_ui_get_enc(double* enc_gap); void ps_gap_ui_get_enc_count(long* enc_count); /* ************************************************************** */ /* PUBLIC FUNCTIONS */ /* ************************************************************** */ /* * ps_gap_ui_init * This function initializes the user interface for the phase shifter gap measurements. * * Input: * dev_id, HP34970 device identifier * * Zachary Wolf * 11/28/17 */ void ps_gap_ui_init(int hp34970_id_in, char log_file_in[], char gap_dat_file_in[]) { /* Declare variables */ int screen_height, screen_width; int top, left, height, width; /* Save parameters */ hp34970_id = hp34970_id_in; strcpy(log_file, log_file_in); strcpy(gap_dat_file, gap_dat_file_in); /* Open the panel */ ps_gap_panel_id = LoadPanel(0, "ps_gap_uir.uir", PANEL); if (ps_gap_panel_id < 0) { ps_gap_ui_error("Could not open user interface panel"); return; } /* Set the panel size and position */ GetScreenSize (&screen_height, &screen_width); top = (int)((40. / 1080.) * screen_height); left = (int)((20. / 1920.) * screen_width); height = (int)((1000. / 1080.) * screen_height); width = (int)((1500. / 1920.) * screen_width); SetPanelSize(ps_gap_panel_id, height, width); SetPanelPos (ps_gap_panel_id, top, left); /* Display the panel when the user interface runs */ DisplayPanel(ps_gap_panel_id); /* Done */ return; } /* ************************************************************** */ /* PRIVATE FUNCTIONS */ /* ************************************************************** */ /* * ps_gap_ui_error * This function handles error messages for the user interface. * * Input: * message, string to display in standard I/O * * Zachary Wolf * 11/28/17 */ void ps_gap_ui_error(char* message) { /* Declare variables */ char buf[80]; /* Notify the operator of the error */ printf("\nPS_GAP_UI 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); } /* ************************************************************** */ /* USER INTERFACE FUNCTIONS */ /* ************************************************************** */ int CVICALLBACK ps_gap_ui_quit (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { switch (event) { case EVENT_COMMIT: QuitUserInterface(0); DiscardPanel(ps_gap_panel_id); hp34970_exit(hp34970_id); break; } return 0; } /* ************************************************************** */ int CVICALLBACK ps_gap_ui_timer (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { int chan[20]; char meas[20]; int num_chan; double meas_vals[20]; double volt_up; double volt_dn; double res; double a = 1.128625e-3; //Thermistor in G10 block, Steinhart-Hart coefficients double b = 2.342078e-4; double c = 8.736248e-8; FILE* fid; switch (event) { case EVENT_TIMER_TICK: chan[0] = CHAN_UP; chan[1] = CHAN_DN; chan[2] = CHAN_TEMP; chan[3] = CHAN_TEMP_REF; meas[0] = 'v'; meas[1] = 'v'; meas[2] = 'r'; meas[3] = 't'; num_chan = 4; hp34970_scan_chan(hp34970_id, num_chan, chan, meas, meas_vals); volt_up = meas_vals[0]; volt_dn = meas_vals[1]; res = meas_vals[2]; temp = 1. / (a + b * log(res) + c * pow(log(res), 3)); //Thermistor in capacitive sensor mount (K) temp = temp - 273.15; //(C) temp_ref = meas_vals[3]; //HP thermistor, reference piece SetCtrlVal(ps_gap_panel_id, PANEL_UPPER_SENSOR_VOLTAGE, volt_up); SetCtrlVal(ps_gap_panel_id, PANEL_LOWER_SENSOR_VOLTAGE, volt_dn); SetCtrlVal(ps_gap_panel_id, PANEL_TEMP, temp); dist_up = volt_up * CAP_SEN_M_PER_VOLT + CAP_SEN_OFFSET; //(m) dist_dn = volt_dn * CAP_SEN_M_PER_VOLT + CAP_SEN_OFFSET; //(m) SetCtrlVal(ps_gap_panel_id, PANEL_UPPER_SENSOR_DIST, dist_up * 1000.); SetCtrlVal(ps_gap_panel_id, PANEL_LOWER_SENSOR_DIST, dist_dn * 1000.); SetCtrlVal(ps_gap_panel_id, PANEL_DIST_BTWN_SENSORS, DIST_BTWN_SENSORS * 1000.); gap = dist_up + DIST_BTWN_SENSORS + dist_dn; SetCtrlVal(ps_gap_panel_id, PANEL_UND_GAP, gap * 1000.); ps_gap_ctrl_ui_get_gap(&enc_gap); ps_gap_ctrl_ui_get_gap_counts(&enc_count); fid = fopen(log_file, "a"); fprintf(fid, "%s %s %10.4f %10d %7.2f %7.2f %10.4f %10.4f %10.4f %10.4f %10.4f\n", DateStr(), TimeStr(), enc_gap * 1000., enc_count, temp_ref, temp, volt_up, volt_dn, dist_up * 1000., dist_dn * 1000., gap * 1000.); fclose(fid); break; } return 0; } /* ************************************************************** */ int CVICALLBACK ps_gap_ui_save (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { char meas_loc[100]; FILE* fid; switch (event) { case EVENT_COMMIT: GetCtrlVal(panel, PANEL_RING_MEAS_LOC, meas_loc); fid = fopen(gap_dat_file, "a"); fprintf(fid, "%s %s %6s %10.4f %10d %7.2f %7.2f %10.4f %10.4f %10.4f\n", DateStr(), TimeStr(), meas_loc, enc_gap * 1000., enc_count, temp_ref, temp, dist_up * 1000., dist_dn * 1000., gap * 1000.); fclose(fid); break; } return 0; }