From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
09-15-2015 08:34 AM
Hello,
I have a project using multiple .c files that requires the use of a ComCallback. The ComCallback works fine under the "first.c" where the callback is located but once the program is running under functions in the "second.c", the callback will not function when the appropriate triggers are received on the serial port.
A call to ProcessSystemsEvents() will allow the ComCallback to work but this is not the ideal solution since I would need to call this repeatedly throughout the entire project.
"first.c"
void COMCallback(int portNumber, int eventMask, void *callbackdata) {
if (eventMask & LWRS_RXFLAG){
// Process stuff
}
}
int Some_function (void) {
// Open and config COM
if (OpenComConfig (comNum, "", 19200, 0, 8, 1, 512, 512)) {
COMerror();
return -1;
}
// Set CTS/RTS
if (SetCTSMode (comNum, LWRS_HWHANDSHAKE_CTS_RTS)){
COMerror();
return -1;
}
// Set COM timeout
if (SetComTime (comNum, 5.0)){
COMerror();
return -1;
}
FlushInQ (comNum);
FlushOutQ (comNum);
InstallComCallback (comNum, LWRS_RXFLAG, 0, 0x07, COMCallback, NULL);
// Call a function under "second.c"
}
Solved! Go to Solution.
09-15-2015 04:55 PM
This is odd behavior, as described. Your code looks good. I've got several projects like you have described: many *.C files, wherein only one *.C file comprises the InstallComCallback function.
But I think you might be confused about how the callback is supposed to work. While the program is "between callbacks", when the conditions you've set up for the ComCallback are met, this function gets called. That's regardless of which C file does what.
You don't call the ComCallback function manually. It gets triggered by serial input data that you set up.
Now if one of your other callback functions is stuck in a blocking loop (for, do/while), then the ComCallback won't ever happen without ProcessSystemEvents in those loops.
09-17-2015 08:47 AM
I believe I found the problem. My Callback was calling a function (under //Process stuff) in order to process the serial data. I eliminated the function and placed the code in the Callback. This seems to have changed the priorities and resolved the issue.
09-17-2015 09:05 AM
Ok, great! Nice work.