LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Multithreadingproblems

Hello,

i habe a problem with mutlithreading in LabWindow/CVI 6.0.
I have two main functions which habe to work at the same time.

1. PANEL:
int CVICALLBACK OPEN_COM (...)
{
OpenComConfig(1,...) //Function to open a COM-Port
CmtScheduleThreadPoolFunction(DEFAULT_THREAD_POOL_HANDLE; Start_Timer, NULL, NULL);
return 0;
}

int CVICALLBACK Start_Timer(void *funtionData)
{
timerID1 = NewAsyncTimer(1.0, -1, 1, ComPort, NULL);
return 0;
}

int CVICALLBACK ComPort (int reserved, int theTimerId, int ebent, void *callbackData, int eventData1, int eventData2)
{
... //get the string from ComPort 1 an write it to global string Puffer
}

2. PANEL:
void Function()
{
SendByComPort(string); //This functions sends a String to another PC 2
Delay(100); //wait for the answer of PC 2
ReceiveAnswerFromPC2(string); //receive the data from PC 2 which a written to global string Puffer to work with
}

The problem is that the timer which is startet in PANEL1 stops working when i call Delay(100) in Panel2 Function()

thx
Paco
0 Kudos
Message 1 of 2
(2,925 Views)
I'm not sure exactly what you are seeing, but I have a few words on it. When you call NewAsyncTimer, your are starting a new thread. Thus, you have a thread running inside a thread. Since NewAsyncTimer starts a new thread, the first thread immediately terminates. Thus, you see the timer quit.

Better solution is to use Delay() inside the new thread. If you need this repeated multiple times, put the Delay() inside a while loop.

Note: From my experience, you cannot issue two NewAsyncTimers in a program. They appear to try to use the same thread, and thus do not work.
0 Kudos
Message 2 of 2
(2,916 Views)