/* ************************************************************** */ /* * Module CM4000UI * This module contains functions for the Compumotor CM4000 * user interface. * * Zachary Wolf * 9/11/02 */ /* ************************************************************** */ /* INCLUDES */ #include #include #include /* Needed if linking in external compiler; harmless otherwise */ #include #include "cm4000uir.h" #include "cm4000ui.h" #include "cm4000.h" /* ************************************************************** */ /* PRIVATE VARIABLES */ static int cm4000_ID; static int cm4000_panel; /* ************************************************************** */ /* PRIVATE FUNCTION DECLARATIONSS */ void cm4000ui_error(char* msg); /* ************************************************************** */ /* PUBLIC FUNCTIONS */ /* ************************************************************** */ /* * cm4000ui_init * This function initializes the user interface for the CM4000. * * Input: * ID, CM4000 device identifier * * Zachary Wolf * 9/11/02 */ void cm4000ui_init(int ID) { /* Save the device ID */ cm4000_ID = ID; /* Open the CM4000 panel */ cm4000_panel = LoadPanel(0, "cm4000uir.uir", CM4000PAN); if (cm4000_panel < 0) { cm4000ui_error("Could not open user interface panel"); return; } /* Display the panel when the user interface runs */ DisplayPanel(cm4000_panel); /* Done */ return; } /* ************************************************************** */ /* PRIVATE FUNCTIONS */ /* ************************************************************** */ /* * cm4000ui_error * This function handles error messages for the CM4000 user interface. * * Input: * message, string to display in standard I/O * * Zachary Wolf * 9/11/02 */ void cm4000ui_error(char* message) { /* Declare variables */ char buf[80]; /* Notify the operator of the error */ printf("\nCM4000UI 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 cm4000ui_move_rel(int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { int axis; double acc, vel, dis; switch (event) { case EVENT_COMMIT: GetCtrlVal(panel, CM4000PAN_NUM_AXIS, &axis); GetCtrlVal(panel, CM4000PAN_NUM_ACCELERATION, &acc); GetCtrlVal(panel, CM4000PAN_NUM_VELOCITY, &vel); GetCtrlVal(panel, CM4000PAN_NUM_DISTANCE, &dis); cm4000_rel_move(cm4000_ID, axis, acc, vel, dis); break; } return 0; } /* ************************************************************** */ int CVICALLBACK cm4000ui_move_abs(int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { int axis; double acc, vel, pos; switch (event) { case EVENT_COMMIT: GetCtrlVal(panel, CM4000PAN_NUM_AXIS, &axis); GetCtrlVal(panel, CM4000PAN_NUM_ACCELERATION, &acc); GetCtrlVal(panel, CM4000PAN_NUM_VELOCITY, &vel); GetCtrlVal(panel, CM4000PAN_NUM_DISTANCE, &pos); cm4000_abs_move(cm4000_ID, axis, acc, vel, pos); break; } return 0; } /* ************************************************************** */ int CVICALLBACK cm4000ui_get_mot_position(int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { int axis; double pos; switch (event) { case EVENT_COMMIT: GetCtrlVal(panel, CM4000PAN_NUM_AXIS, &axis); cm4000_get_mot_position(cm4000_ID, axis, &pos); SetCtrlVal(panel, CM4000PAN_NUM_MOT_POSITION, pos); break; } return 0; } /* ************************************************************** */ int CVICALLBACK cm4000ui_get_enc_position(int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { int axis; double pos; switch (event) { case EVENT_COMMIT: GetCtrlVal(panel, CM4000PAN_NUM_AXIS, &axis); cm4000_get_enc_position(cm4000_ID, axis, &pos); SetCtrlVal(panel, CM4000PAN_NUM_ENC_POSITION, pos); break; } return 0; } /* ************************************************************** */ int CVICALLBACK cm4000ui_zero(int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { int axis; double pos; switch (event) { case EVENT_COMMIT: GetCtrlVal(panel, CM4000PAN_NUM_AXIS, &axis); cm4000_zero(cm4000_ID, axis); cm4000_get_mot_position(cm4000_ID, axis, &pos); SetCtrlVal(panel, CM4000PAN_NUM_MOT_POSITION, pos); cm4000_get_enc_position(cm4000_ID, axis, &pos); SetCtrlVal(panel, CM4000PAN_NUM_ENC_POSITION, pos); break; case EVENT_RIGHT_CLICK: break; } return 0; } /* ************************************************************** */ int CVICALLBACK cm4000ui_go_home(int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { int axis; double acc, vel; switch (event) { case EVENT_COMMIT: GetCtrlVal(panel, CM4000PAN_NUM_AXIS, &axis); GetCtrlVal(panel, CM4000PAN_NUM_ACCELERATION, &acc); GetCtrlVal(panel, CM4000PAN_NUM_VELOCITY, &vel); cm4000_go_home(cm4000_ID, axis, acc, vel); break; case EVENT_RIGHT_CLICK: break; } return 0; } /* ************************************************************** */ int CVICALLBACK cm4000ui_quit(int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { switch (event) { case EVENT_COMMIT: cm4000_exit(cm4000_ID); QuitUserInterface(0); break; } return 0; }