NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

teststand two UI

Solved!
Go to solution

No, that is DllMain, an entry point function that will be called by new threads when they are created. Do not modify that function.

 

The functions for multithreading in CVI are located under the Utility\Multithreading API. There are numerous example programs that come with CVI to illustrate these APIs. I haven't tested this code, but you will need something similar to the following:

 

static int CVICALLBACK MyThreadFunc(void *parameter)
{

 if ((panelHandle = LoadPanelEx (0, "panel.uir", PANEL, __CVIUserHInst)) < 0)
  return -1;
 DisplayPanel (panelHandle);

RunUserInterface ();

 

return 0;

}

 

static void CVICALLBACK QuitUICallback (void *returnValue)
{
    QuitUserInterface ((int)(intptr_t)returnValue);
}

 

static CmtThreadFunctionID sThreadFunctionId = 0;

 

void StartThread()

{

   char errorBuf[CMT_MAX_MESSAGE_BUF_SIZE];

   int error = 0;

 

   errChk(CmtScheduleThreadPoolFunction(DEFAULT_THREAD_POOL_HANDLE, MyThreadFunc, NULL, &sThreadFunctionId));

 

Error:

    if (error < 0) {
        CmtGetErrorMessage (error, errorBuf);
        MessagePopup ("Error:", errorBuf);
    }

}

 

void EndThread()

{

   char errorBuf[CMT_MAX_MESSAGE_BUF_SIZE];

   int error = 0;

   unsigned int threadID = 0;

 

    errChk(CmtGetThreadPoolFunctionAttribute (DEFAULT_THREAD_POOL_HANDLE, sThreadFunctionId,
                                               ATTR_TP_FUNCTION_THREAD_ID,
                                               &threadID));

 

    PostDeferredCallToThread (QuitUICallback, 0, threadID);

    errChk(CmtWaitForThreadPoolFunctionCompletion(DEFAULT_THREAD_POOL_HANDLE, sThreadFunctionId, OPT_TP_PROCESS_EVENTS_WHILE_WAITING));

 

Error:

    if (error < 0) {
        CmtGetErrorMessage (error, errorBuf);
        MessagePopup ("Error:", errorBuf);
    }

}

 

 

Call StartThread in your load callback and EndThread in your unload callback.

 

-Doug

 

 

0 Kudos
Message 11 of 11
(722 Views)