LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

User Interface update issue while CVI executes callback functions

Solved!
Go to solution

Hi,

 

I have a simple CVI code that is intended to blink an LED on the panel for certain amount of time when the user double clicks(right) on a button in the panel. The CVI code is as bellow.

 

#include <ansi_c.h>
#include <utility.h>
#include <cvirte.h>
#include <userint.h>
#include "Run Callback Fn.h"
#include <stdio.h>

static int panelHandle;
int i=0;

int main (int argc, char *argv[])
{
if (InitCVIRTE (0, argv, 0) == 0)
return -1; /* out of memory */
if ((panelHandle = LoadPanel (0, "Run Callback Fn.uir", PANEL)) < 0)
return -1;
DisplayPanel (panelHandle);
RunUserInterface ();
DiscardPanel (panelHandle);
}


int CVICALLBACK Run (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{ int i=0;
switch (event)
{
case EVENT_RIGHT_DOUBLE_CLICK:
printf("Event Detected");
SetCtrlVal(panelHandle,PANEL_NUMERIC,23.78);
SetCtrlVal(panelHandle,PANEL_LED,1);
for(i=0;i<=100;i++)
{
SetCtrlVal(panelHandle,PANEL_LED,0);
Delay(1);
SetCtrlVal(panelHandle,PANEL_LED,1);
}
break;
}
return 0;
}

 

But its not working as intended. The state of led on front panel is updated only after the switch case finishes execution. Actually it has to update during the for loop is executing. Being a newbie, I don't have much idea about CVI programming. However i found the following information.

 

http://zone.ni.com/reference/en-XX/help/370051V-01/cvi/uiref/cviprocessing_events/

http://zone.ni.com/reference/en-XX/help/370051V-01/cvi/uiref/cviprocessdrawevents/

 

But i'm not sure how to use them.

 

Any help is highly appreciated.

 

Best Regards

Deepu Jacob

-----------------------------------------------------------------------------------------------------------------------------
Waiting For the inner calling 🙂


0 Kudos
Message 1 of 3
(3,814 Views)
Solution
Accepted by djac91

Actually you don't need any of the commands you have found since SetCtrlVal already forses an update of the UI: you simply need to give the ON state some time for the user to see it. Smiley Wink

for(i=0;i<=100;i++) {
    SetCtrlVal (panelHandle, PANEL_LED, 0);
    Delay(0.5);
    SetCtrlVal (panelHandle, PANEL_LED, 1);
    Delay(0.5);
}

 

A little insight in those commands you have found:

ProcessDrawEvents () will force an update of the user interface, but as I told you this is already implicit in SetCtrlVal, at least for the control addressed. You would need to use this command if other tasks in the application would update values displayed on screen.

ProcessSystemEvents () permits the program to honour user interface events even inside a tight loop like yours: at present there is no way to stop the process until the for loop completes because even if the user pressed a Stop button the system would not see that event while inside the loop: ProcessSystemEvents () would permit this.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 2 of 3
(3,802 Views)

Thanks for the tip, the code works fine.

-----------------------------------------------------------------------------------------------------------------------------
Waiting For the inner calling 🙂


0 Kudos
Message 3 of 3
(3,794 Views)