/* ************************************************************** */ /* * Module CM6KUI * This module contains functions for the Compumotor CM6K * user interface. * * Zachary Wolf * 9/11/02 */ /* ************************************************************** */ /* INCLUDES */ #include #include #include /* Needed if linking in external compiler; harmless otherwise */ #include #include "cm6kuir.h" #include "cm6kui.h" #include "cm6k.h" /* ************************************************************** */ /* PRIVATE VARIABLES */ static int cm6k_ID; static int cm6k_panel; /* ************************************************************** */ /* PRIVATE FUNCTION DECLARATIONSS */ void cm6kui_error(char* msg); /* ************************************************************** */ /* PUBLIC FUNCTIONS */ /* ************************************************************** */ /* * cm6kui_init * This function initializes the user interface for the CM6K. * * Input: * ID, CM6K device identifier * * Zachary Wolf * 9/11/02 */ void cm6kui_init(int ID) { /* Save the device ID */ cm6k_ID = ID; /* Open the CM6K panel */ cm6k_panel = LoadPanel(0, "cm6kuir.uir", CM6KPAN); if (cm6k_panel < 0) { cm6kui_error("Could not open user interface panel"); return; } /* Display the panel when the user interface runs */ DisplayPanel(cm6k_panel); /* Done */ return; } /* ************************************************************** */ /* PRIVATE FUNCTIONS */ /* ************************************************************** */ /* * cm6kui_error * This function handles error messages for the CM6K user interface. * * Input: * message, string to display in standard I/O * * Zachary Wolf * 9/11/02 */ void cm6kui_error(char* message) { /* Declare variables */ char buf[80]; /* Notify the operator of the error */ printf("\nCM6KUI 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 cm6kui_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, CM6KPAN_NUM_AXIS, &axis); GetCtrlVal(panel, CM6KPAN_NUM_ACCELERATION, &acc); GetCtrlVal(panel, CM6KPAN_NUM_VELOCITY, &vel); GetCtrlVal(panel, CM6KPAN_NUM_DISTANCE, &dis); cm6k_rel_move(cm6k_ID, axis, acc, vel, dis); break; } return 0; } /* ************************************************************** */ int CVICALLBACK cm6kui_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, CM6KPAN_NUM_AXIS, &axis); GetCtrlVal(panel, CM6KPAN_NUM_ACCELERATION, &acc); GetCtrlVal(panel, CM6KPAN_NUM_VELOCITY, &vel); GetCtrlVal(panel, CM6KPAN_NUM_DISTANCE, &pos); cm6k_abs_move(cm6k_ID, axis, acc, vel, pos); break; } return 0; } /* ************************************************************** */ int CVICALLBACK cm6kui_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, CM6KPAN_NUM_AXIS, &axis); cm6k_get_mot_position(cm6k_ID, axis, &pos); SetCtrlVal(panel, CM6KPAN_NUM_MOT_POSITION, pos); break; } return 0; } /* ************************************************************** */ int CVICALLBACK cm6kui_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, CM6KPAN_NUM_AXIS, &axis); cm6k_get_enc_position(cm6k_ID, axis, &pos); SetCtrlVal(panel, CM6KPAN_NUM_ENC_POSITION, pos); break; } return 0; } /* ************************************************************** */ int CVICALLBACK cm6kui_zero(int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { int axis; double pos; switch (event) { case EVENT_COMMIT: GetCtrlVal(panel, CM6KPAN_NUM_AXIS, &axis); cm6k_zero(cm6k_ID, axis); cm6k_get_mot_position(cm6k_ID, axis, &pos); SetCtrlVal(panel, CM6KPAN_NUM_MOT_POSITION, pos); cm6k_get_enc_position(cm6k_ID, axis, &pos); SetCtrlVal(panel, CM6KPAN_NUM_ENC_POSITION, pos); break; case EVENT_RIGHT_CLICK: break; } return 0; } /* ************************************************************** */ int CVICALLBACK cm6kui_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, CM6KPAN_NUM_AXIS, &axis); GetCtrlVal(panel, CM6KPAN_NUM_ACCELERATION, &acc); GetCtrlVal(panel, CM6KPAN_NUM_VELOCITY, &vel); cm6k_go_home(cm6k_ID, axis, acc, vel); break; case EVENT_RIGHT_CLICK: break; } return 0; } /* ************************************************************** */ int CVICALLBACK cm6kui_quit(int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { switch (event) { case EVENT_COMMIT: cm6k_exit(cm6k_ID); QuitUserInterface(0); break; } return 0; }