#include "Hp3458uir.h" // ***************************************************************************************** // // Module HP3458UI // This module contains functions for the HP3458 multimeter // user interface. // // Zachary Wolf // ***************************************************************************************** // INCLUDES #include #include #include #include #include "hp3458uir.h" #include "hp3458ui.h" #include "hp3458.h" // ***************************************************************************************** // PRIVATE VARIABLES static int hp3458_ID; static int hp3458_panel; static double *V; // ***************************************************************************************** // PRIVATE FUNCTION DECLARATIONS void hp3458ui_error(char* msg); // ***************************************************************************************** // PUBLIC FUNCTIONS // ***************************************************************************************** /* * hp3458ui_init * This function initializes the user interface for the HP3458 DMM. * * Input: * ID, HP3458 device identifier * * Zachary Wolf * 8/3/98 */ void hp3458ui_init(int ID) { /* Save the HP3458 ID */ hp3458_ID = ID; /* Open the HP3458 panel */ hp3458_panel = LoadPanel(0, "hp3458uir.uir", HPPANEL); if (hp3458_panel < 0) { hp3458ui_error("Could not open user interface panel"); return; } /* Display the panel when the user interface runs */ DisplayPanel(hp3458_panel); /* Done */ return; } // ***************************************************************************************** /* PRIVATE FUNCTIONS */ // ***************************************************************************************** /* * hp3458ui_error * This function handles error messages for the HP3458 user interface. * * Input: * message, string to display in standard I/O * * Zachary Wolf * 8/3/98 */ void hp3458ui_error(char* message) { /* Declare variables */ char buf[80]; /* Notify the operator of the error */ printf("\nHP3458UI 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); } // ***************************************************************************************** /* PRIVATE USER INTERFACE FUNCTIONS */ // ***************************************************************************************** int CVICALLBACK hp3458ui_quit(int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { switch (event) { case EVENT_COMMIT: hp3458_exit(hp3458_ID); QuitUserInterface(0); break; case EVENT_RIGHT_CLICK: break; } return 0; } // ***************************************************************************************** int CVICALLBACK hp3458ui_get_voltage(int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { double voltage; switch (event) { case EVENT_COMMIT: SetCtrlAttribute (hp3458_panel, HPPANEL_CMD_GET_HP3458_V, ATTR_DIMMED,1); SetCtrlAttribute (hp3458_panel, HPPANEL_CMD_GET_HP3458_Vn, ATTR_DIMMED,1); hp3458_get_voltage(hp3458_ID, &voltage); SetCtrlVal(hp3458_panel, HPPANEL_HP3458_V, voltage); SetCtrlAttribute (hp3458_panel, HPPANEL_CMD_GET_HP3458_V, ATTR_DIMMED, 0); SetCtrlAttribute (hp3458_panel, HPPANEL_CMD_GET_HP3458_Vn, ATTR_DIMMED,0); break; case EVENT_RIGHT_CLICK: break; } return 0; } // ***************************************************************************************** int CVICALLBACK hp3458ui_get_Vsamples (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { int dev_ID; double v_range; float nplc; int num_samples; float dt; switch (event) { case EVENT_COMMIT: SetCtrlAttribute (hp3458_panel, HPPANEL_CMD_GET_HP3458_Vn, ATTR_DIMMED,1); SetCtrlAttribute (hp3458_panel, HPPANEL_CMD_GET_HP3458_V, ATTR_DIMMED,1); dev_ID = hp3458_ID; v_range = 7.; GetCtrlVal (hp3458_panel, HPPANEL_NUMERIC_NUM_SAMPLES, &num_samples); GetCtrlVal (hp3458_panel, HPPANEL_NUMERIC_DT, &dt); GetCtrlVal (hp3458_panel, HPPANEL_NUMERIC_NPLC, &nplc); if (V != NULL) free (V); V = calloc (num_samples, sizeof(double)); hp3458_setup_timed_voltage_samples(dev_ID, v_range, nplc, num_samples, dt); hp3458_trigger_timed_voltage_samples(dev_ID); hp3458_collect_timed_voltage_samples(dev_ID, num_samples, V); DeleteGraphPlot (hp3458_panel, HPPANEL_GRAPH_VvsT, -1, VAL_IMMEDIATE_DRAW); PlotY (hp3458_panel, HPPANEL_GRAPH_VvsT, V, num_samples, VAL_DOUBLE, VAL_THIN_LINE, VAL_SOLID_SQUARE, VAL_SOLID, 1, VAL_RED); SetCtrlAttribute (hp3458_panel, HPPANEL_CMD_GET_HP3458_Vn, ATTR_DIMMED,0); SetCtrlAttribute (hp3458_panel, HPPANEL_CMD_GET_HP3458_V, ATTR_DIMMED,0); break; } return 0; } // ***************************************************************************************** int CVICALLBACK hp3458ui_triggered (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { int dev_ID; float nplc; double v_range; int num_samples; switch (event) { case EVENT_COMMIT: dev_ID = hp3458_ID; v_range = 10.; GetCtrlVal (hp3458_panel, HPPANEL_NUMERIC_NUM_SAMPLES, &num_samples); GetCtrlVal (hp3458_panel, HPPANEL_NUMERIC_NPLC, &nplc); if (V != NULL) free (V); V = calloc (num_samples, sizeof(double)); // hp3458_get_triggered_voltage_samples(dev_ID, v_range, num_plc, num_samples, V); // Use alternate method hp3458_setup_triggered_voltage_samples (dev_ID, v_range, nplc, num_samples); hp3458_start_triggered_voltage_samples (dev_ID); hp3458_collect_triggered_voltage_samples (dev_ID, num_samples, V); DeleteGraphPlot (hp3458_panel, HPPANEL_GRAPH_VvsT, -1, VAL_IMMEDIATE_DRAW); PlotY (hp3458_panel, HPPANEL_GRAPH_VvsT, V, num_samples, VAL_DOUBLE, VAL_THIN_LINE, VAL_SOLID_SQUARE, VAL_SOLID, 1, VAL_RED); break; } return 0; } int CVICALLBACK Save_File (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { unsigned int i, n; float Vave, Vrms; char file_name[260]; FILE* file_ptr; switch (event) { case EVENT_COMMIT: FileSelectPopup ("W:\LCLS-II\data", "*.*", "", "", VAL_SAVE_BUTTON, 0, 0, 1, 0, file_name); file_ptr = fopen (file_name, "w"); fprintf (file_ptr, "Date: %s\n", DateStr ()); fprintf (file_ptr, "Time: %s\n", TimeStr ()); fprintf (file_ptr, " n V\n"); GetCtrlVal (hp3458_panel, HPPANEL_NUMERIC_NUM_SAMPLES, &n); for (i = 0, Vave = 0.0; i < n; i++) Vave += V[i]; Vave /= n; for (i = 0, Vrms = 0.0; i < n; i++) Vrms += ((V[i] - Vave)*(V[i] - Vave)); Vrms /= n; Vrms = sqrt(Vrms); fprintf (file_ptr, "Average value = %e, RMS = %e\n", Vave, Vrms); for (i = 0; i < n; i++) fprintf (file_ptr, " %d %e\n", i, V[i]); fclose (file_ptr); break; case EVENT_RIGHT_CLICK: break; } return 0; }