01-18-2013 10:51 AM
I have a callback function which is activated when there it receives a message from an application on a PXI controller on the network " CNVCreateSubscriber (path, RespondToRecordDataCommandCallback, 0, 0, 10000, 0, &gRespondToRecordData);"
After I receive the message I do a few things in the call back function and after I am done I want to respond with a message that tells the PXI controller application that I received the message and have finished the task.
So I had these lines of code in the callback function:
CNVCreateScalarDataValue(&cntrlData, CNVBool, 1);
CNVWrite(gRegCalRecordingComplete, cntrlData, CNVDoNotWait);
CNVDisposeData(cntrlData);
When I did this I got an error message dialog that said "Not supported when thread is in a network variable callback function"
So I used the PostDelayedCall() function so I could return the message after the thread is done:
PostDelayedCall(SendRecordingCompleteMessage, &g_dataToSend, 0.2);
Here is the callback function:
void CVICALLBACK SendRecordingCompleteMessage(void *callbackData)
{
CNVData cntrlData;
CNVCreateScalarDataValue(&cntrlData, CNVBool, 1);
CNVWrite(gRegCalRecordingComplete, cntrlData, CNVDoNotWait);
CNVDisposeData(cntrlData);
}
My problem is it never starts the callback function SendRecordingCompleteMessage(). I put a breakpoint to see if it is ever called. Obviously I am missing something important. What am I missing? Do I need to another thread to get this to work or something like that? I would appreciate if anyone has an example of code that works in this instance.
thanks,
Don
01-21-2013 06:32 AM
In looking at the PostDelayedCall source code (which you can also do: it's in toolslib\toolbox\toolbox.c), it looks as if the callback is always called in the same thread. It doesn't sound to me that as if this is what you want.
Also, the reason why your breakpoint is never hit is probably because your network variable callback never processes UI events, (for example, via a ProcessSytemEvent function call) which is a requirement for callbacks scheduled via PostDelayedCall. But even if it did get called, it would get called in the same thread, and you'd run into the same network variable error you were running into before.
Assuming that the 0.2 second delay is not that important for you, and you really just want the callback to be called in a different thread, you should use the PostDeferredCall function (if you want the callback to go to the main thread) or the PostDeferredCallToThread function (if you want to go to some other thread).
Luis
01-22-2013 08:45 AM
My problem is not on the PXI controller side. My problem is the application on my host computer which has a Windows OS. I believe the PostDeferredCall() is a function used on a RT OS.
01-22-2013 10:46 AM
PostDeferredCall is available on both Windows and RT. The RT label in the help is referring to RT specific functionality of the function, but only that paragraph pertains to RT only functionality.