LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Receive CAN messages in a new thread pool

Hi, I use a thread to receive CAN msg like code below: 
 
 
int CVICALLBACK DataAcqThreadFunction (void *functionData);
int main(int argc, char *argv[])
{
    int panelHandle;
    int functionId;
   
        DisplayPanel (panelHandle);

    CmtScheduleThreadPoolFunction (DEFAULT_THREAD_POOL_HANDLE, DataAcqThreadFunction, NULL, &functionId);
    RunUserInterface ();
    DiscardPanel (panelHandle);
    return 0;
}
int CVICALLBACK DataAcqThreadFunction (void *functionData)
{
    while (!quit) {
        ncWaitForState(...)
        ...
    }
    return 0;
}
 
 
the code works fine but i need to close the thread, unfortunately the thread is locked in ncWaitforstate so i can not terminate it until i receive at least one msg.
Have you some idea to implement a receive method in a new thread without polling type?
 
thanks
marco
 
 
 
 
0 Kudos
Message 1 of 3
(2,806 Views)

Can you not use the timeout facility of the ncWaitForState() function to allow for a termination to be handled more cleanly? At least it would prevent the thread from becoming locked in the function.

JR

0 Kudos
Message 2 of 3
(2,802 Views)
I need a thread that stays always in listening mode to catch any kind of msg. In fact, i use ncWaitForState(panelHandle, NC_ST_READ_AVAIL, NC_DURATION_INFINITE,0)
 
Thanks
marco
 
0 Kudos
Message 3 of 3
(2,799 Views)