LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Why does my LabWindows code run slower?

I am running LabWindows/CVI version 6.0
Why does my code run slower with a UIR interface compared to a command
prompt program?

How can I speed this up?
0 Kudos
Message 1 of 11
(4,179 Views)
What you mean code runs slower?


vishi

ddc1553 wrote:
> I am running LabWindows/CVI version 6.0
> Why does my code run slower with a UIR interface compared to a command
> prompt program?
>
> How can I speed this up?
0 Kudos
Message 2 of 11
(4,179 Views)
0 Kudos
Message 3 of 11
(4,179 Views)
What I mean is that I have a thread which interrupts and then reads all data from my hardwares memory. When I run using MS Visual C++ in a command prompt environment all works okay. Using the same code in LabWindows/CVI all still works okay. Now if I add a UIR to input data and make everything graphical my cards memory buffer fills up. The code is not executing fast enough to dequeue the memory. Hence code runs slower this is fact. Any ideas?
0 Kudos
Message 4 of 11
(4,179 Views)
Do you have any suggestions?
0 Kudos
Message 5 of 11
(4,045 Views)
What thruput does your read memory thread need?
- with CVI's RunUserInterface(), I think there is CPU processing required that may interfere with your card processing. Or are you using GetNextEvent() processing?

I have a thread in my CVI application that sends out data to the 100Mbps serial port at a 300Hz rate (data size about 60-80 bytes).

I read all UIR input first, then when the user presses (START), the thread is executed.
- the hardware does not have any problems with CVI running in the background, as long as I used CreateThread(), and exit out of my (START) callback.
0 Kudos
Message 6 of 11
(4,179 Views)
I am using RunUserInterface(). From a recommendation I commented out RunUserInterface() and replaced it with:

//comment this out as per LabWindows recommendation
//RunUserInterface ();
while(!globalQuit)
{
ProcessSystemEvents();
Sleep(1);
}

I have also tried changing the sleep value and it makes no difference.

How do I use CreatThread()? Do you have any code samples that you can attach? That may correct the issue.
0 Kudos
Message 7 of 11
(4,179 Views)
Attached is a dumb application that utilizes CreateThread(). It has examples of other NI issues that I have, but the snippet gives a one-shot example of a thread that I used.

- I dont have hand-shaking in this thread, it just gets created, processed, and then exits. You may want some hand-shaking in your thread, so you don't exit while your thread is still active.

- good luck...

static DWORD WINAPI reset_thread(
LPVOID parameter) /* in: thread data */
{
char buf[1024];
time_t present_time; /* Present time from time() function */
struct tm * converted_time = NULL; /* Time converted for use in strftime*/

time(&present_time);

converted_time = localtime(&present_time);
strftime(buf, 1023, "%H:%M:%S ", converted_time);

SetCtrlVal( untitledID, PANEL_STRING, buf );

return 0;
} // end reset_thread


int CVICALLBACK getCurrentTime (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
if (event == EVENT_COMMIT)
{
HANDLE thread = NULL; /* Power-down thread handle */

thread = CreateThread(NULL, 0, reset_thread, NULL, 0, NULL);
}
return 0;
}
0 Kudos
Message 8 of 11
(4,179 Views)
Thanks. However the thread is only run when I hit my button for the CVICALLBACK (i.e in your example above getCurrentTime). How can I make this thread run in the background forever once I hit the button.
0 Kudos
Message 9 of 11
(4,179 Views)
In this simple mod, the thread reset_thread() will keep running for 1Hz until the STOP button is pressed . The WaitForSingleObject() will slow down the app, so other threads can run, without eating up most of the CPU time.

I hope this helps!

HANDLE g_sync = NULL;

static DWORD WINAPI reset_thread(LPVOID)
{
char buf[1024];
time_t present_time; /* Present time from time() function */
struct tm * converted_time = NULL; /* Time converted for use in strftime*/

if (g_sync == NULL)
g_sync = CreateEvent(NULL, TRUE, FALSE, "stop-thread");

// loop at 1Hz waiting for STOP
while ( WaitForSingleObject(g_sync,1000) != WAIT_OBJECT_0
)
{
time(&present_time);
converted_time = localtime(&present_time);
strftime(buf, 1023, "%H:%M:%S ", converted_time);

SetCtrlVal( untitledID, PANEL_STRING, buf );
}

return 0;
} // end reset_thread


int CVICALLBACK getCurrentTime (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
if (event == EVENT_COMMIT)
{
HANDLE thread = NULL; /* Power-down thread handle */

if (g_sync == NULL)
g_sync = CreateEvent(NULL, TRUE, FALSE, "stop-thread");

thread = CreateThread(NULL, 0, reset_thread, NULL, 0, NULL);
}
return 0;
}

int CVICALLBACK stopThread (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
if (event == EVENT_COMMIT)
{
if (g_sync == NULL)
g_sync = CreateEvent(NULL, TRUE, FALSE, "stop-thread");


SetEvent(g_sync);
}
return 0;
}
0 Kudos
Message 10 of 11
(4,179 Views)