LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Example for timer control initialization programmatically ?

In user interface it is easy to generate the timer control callback, but how to make it work programmatically with Newctrl and etc. functions ? Is there available example how to do this ? I'm using Labwindows 4.0.1 version.
0 Kudos
Message 1 of 3
(3,640 Views)
I attach a simple project that creates a timer programmatically and uses it to flash a led on a panel. You can use it as a skeleton for you needs.
Regards.
Roberto


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?
0 Kudos
Message 2 of 3
(3,640 Views)
I've just knocked this code up which might help you out...

If not, let me know...

Note: This was done with CVI 5.5 so I hope it works for 4.0.1.

Regards

Chris

#include
#include "a.h"
#include
#include


int CVICALLBACK timerCb (int panel, int control, int event,void *callbackData, int eventData1, int eventData2);

int iCount = 0;

int hPanel;
int hTimerID;
int hCountBox;



int __stdcall WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpszCmdLine, int nCmdShow)
{

if (InitCVIRTE (hInstance, 0, 0) == 0)
return -1; /* out of memory */


hPanel = NewPanel (0, "Timer Test", 0, 0, 120, 120);

hCountBox = NewCtrl (hPanel, CTRL_TEXT_MSG, "Count", 20, 20);


DisplayPanel (hPanel);

hTimerID = NewCtrl
(hPanel, CTRL_TIMER, "Timer", 0, 0);


SetCtrlAttribute (hPanel, hTimerID, ATTR_CALLBACK_NAME, "timerCb");
SetCtrlAttribute (hPanel, hTimerID, ATTR_CALLBACK_FUNCTION_POINTER,&timerCb);


SetCtrlAttribute (hPanel, hTimerID, ATTR_ENABLED, 1);



RunUserInterface ();


return 0;
}

int CVICALLBACK timerCb (int panel, int control, int event,void *callbackData, int eventData1, int eventData2)
{

#define COUNT_MSG "Count:%d\n"

char szMsg[63];

switch (event)
{
case EVENT_TIMER_TICK:

iCount++;

sprintf(szMsg,COUNT_MSG,iCount);

SetCtrlVal (hPanel, hCountBox, szMsg);


if(iCount>10)
{
QuitUserInterface (0);
}

break;
}
return 0;
}
0 Kudos
Message 3 of 3
(3,640 Views)