Hi all,
I have a code with two buttons placed on the panel, one is RUN, another is STOP. Initially, STOP is disabled and when I kick RUN, the STOP will be disable. But when STOP is kicked, the RUN will be activated.
#include "testimg.h" //============================================================================== // // Title: BECQCL_mainkick // Purpose: This is the CVI implementation for BEC_PAkick.vi, which will // generate MOT, BEC and submit kicking if loaded // // Created on: 2013/08/11 by Wakun Lam // Copyright: All Rights Reserved by Bose-Einstein Condensation and Quantum Chaos Laboratory in Oklahoma State University // //============================================================================== #include <windows.h> #include <utility.h> #include "asynctmr.h" #include <ansi_c.h> #include <cvirte.h> #include <userint.h> #include <NIDAQmx.h> #include "toolbox.h" static int panelHandle = 0; static int stoprun = 0; int main (int argc, char *argv[]) { int error = 0; nullChk (InitCVIRTE (0, argv, 0)); errChk (panelHandle = LoadPanel (0, "testimg.uir", PANEL)); SetCtrlAttribute(PANEL, PANEL_STOPBUTTON, ATTR_DIMMED, TRUE); errChk (DisplayPanel (panelHandle)); errChk (RunUserInterface ()); Error: if (panelHandle > 0) DiscardPanel (panelHandle); return 0; } int CVICALLBACK MainPanelResponse(int panel, int event, void *callbackData, int eventData1, int eventData2) { if (event == EVENT_CLOSE) QuitUserInterface (0); return 0; } int CVICALLBACK RunButtonResponse (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { if (event==EVENT_COMMIT) { int N=20; stoprun = 0; SetCtrlAttribute(panel, PANEL_STOPBUTTON, ATTR_DIMMED, FALSE); SetCtrlAttribute(panel, PANEL_RUNBUTTON, ATTR_DIMMED, TRUE); for (int i=0; i<N; i++) { // some heavy task // here I use Sleep instead Sleep(5000); ProcessSystemEvents(); Sleep(2000); if (stoprun>0) break; } SetCtrlAttribute(panel, PANEL_STOPBUTTON, ATTR_DIMMED, TRUE); SetCtrlAttribute(panel, PANEL_RUNBUTTON, ATTR_DIMMED, FALSE); } return 0; } int CVICALLBACK StopButtonResponse (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { if (event==EVENT_COMMIT) { stoprun = 1; } return 0; }
My code is designed so to repeat a operation for N times after the START button is kicked. And if STOP button is kicked before the task is finished running. Stop the current application and return false; I wrote the code but it seems doesn't work. It seems that the application cannot be interrupted before the completete of the task. I don't know what's wrong with my code. If you have any experienence with that, could you please tell me what's wrong with my cdoe? Thanks.