/* ************************************************************** */ /* * Module SXDRIVEUI * This module contains functions for the Compumotor SXDRIVE * user interface. * * Zachary Wolf * 2/28/02 */ /* ************************************************************** */ /* INCLUDES */ #include #include #include /* Needed if linking in external compiler; harmless otherwise */ #include #include "sxdriveuir.h" #include "sxdriveui.h" #include "sxdrive.h" /* ************************************************************** */ /* PRIVATE VARIABLES */ static int sxdrive_ID; static int sxdrive_panel; /* ************************************************************** */ /* PRIVATE FUNCTION DECLARATIONSS */ void sxdriveui_error(char* msg); /* ************************************************************** */ /* PUBLIC FUNCTIONS */ /* ************************************************************** */ /* * sxdriveui_init * This function initializes the user interface for the SXDRIVE. * * Input: * ID, SXDRIVE device identifier * * Zachary Wolf * 2/28/02 */ void sxdriveui_init(int ID) { /* Save the device ID */ sxdrive_ID = ID; /* Open the SXDRIVE panel */ sxdrive_panel = LoadPanel(0, "sxdriveuir.uir", SXDRIVEPAN); if (sxdrive_panel < 0) { sxdriveui_error("Could not open user interface panel"); return; } /* Display the panel when the user interface runs */ DisplayPanel(sxdrive_panel); /* Done */ return; } /* ************************************************************** */ /* PRIVATE FUNCTIONS */ /* ************************************************************** */ /* * sxdriveui_error * This function handles error messages for the SXDRIVE user interface. * * Input: * message, string to display in standard I/O * * Zachary Wolf * 2/28/02 */ void sxdriveui_error(char* message) { /* Declare variables */ char buf[80]; /* Notify the operator of the error */ printf("\nSXDRIVEUI 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 sxdriveui_move_rel(int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { double acc, vel, dis; switch (event) { case EVENT_COMMIT: GetCtrlVal(panel, SXDRIVEPAN_NUM_ACCELERATION, &acc); GetCtrlVal(panel, SXDRIVEPAN_NUM_VELOCITY, &vel); GetCtrlVal(panel, SXDRIVEPAN_NUM_DISTANCE, &dis); sxdrive_rel_move(sxdrive_ID, acc, vel, dis); break; } return 0; } /* ************************************************************** */ int CVICALLBACK sxdriveui_move_abs(int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { double acc, vel, pos; switch (event) { case EVENT_COMMIT: GetCtrlVal(panel, SXDRIVEPAN_NUM_ACCELERATION, &acc); GetCtrlVal(panel, SXDRIVEPAN_NUM_VELOCITY, &vel); GetCtrlVal(panel, SXDRIVEPAN_NUM_DISTANCE, &pos); sxdrive_abs_move(sxdrive_ID, acc, vel, pos); break; } return 0; } /* ************************************************************** */ int CVICALLBACK sxdriveui_get_mot_position(int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { double pos; switch (event) { case EVENT_COMMIT: sxdrive_get_mot_position(sxdrive_ID, &pos); SetCtrlVal(panel, SXDRIVEPAN_NUM_MOT_POSITION, pos); break; } return 0; } /* ************************************************************** */ int CVICALLBACK sxdriveui_get_enc_position(int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { double pos; switch (event) { case EVENT_COMMIT: sxdrive_get_enc_position(sxdrive_ID, &pos); SetCtrlVal(panel, SXDRIVEPAN_NUM_ENC_POSITION, pos); break; } return 0; } /* ************************************************************** */ int CVICALLBACK sxdriveui_zero(int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { double pos; switch (event) { case EVENT_COMMIT: sxdrive_zero(sxdrive_ID); sxdrive_get_mot_position(sxdrive_ID, &pos); SetCtrlVal(panel, SXDRIVEPAN_NUM_MOT_POSITION, pos); sxdrive_get_enc_position(sxdrive_ID, &pos); SetCtrlVal(panel, SXDRIVEPAN_NUM_ENC_POSITION, pos); break; case EVENT_RIGHT_CLICK: break; } return 0; } /* ************************************************************** */ int CVICALLBACK sxdriveui_go_home(int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { double acc, vel; switch (event) { case EVENT_COMMIT: GetCtrlVal(panel, SXDRIVEPAN_NUM_ACCELERATION, &acc); GetCtrlVal(panel, SXDRIVEPAN_NUM_VELOCITY, &vel); sxdrive_go_home(sxdrive_ID, acc, vel); break; case EVENT_RIGHT_CLICK: break; } return 0; } /* ************************************************************** */ int CVICALLBACK sxdriveui_quit(int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { switch (event) { case EVENT_COMMIT: sxdrive_exit(sxdrive_ID); QuitUserInterface(0); break; } return 0; }