10-26-2016 04:22 PM
I want to get an event when my funtion returns 3 (as an example). How can I do this?
In procedure code. How can I do "Some how" at the below code?
int myFunction(int intVal) {
if (intVal == 'X_condition') return -1;
else if (intVal == 'O_conditon') return 3;
}
//---------------Some how -----------------
if (myFunction(intStatus) == 3) mapping an eventmessage to EVENT_MYFUNCTION;
//-----------------------------------------------
int CVICALLBACK frmMainCallback (int panel, int event, void *callbackData, int eventData1, int eventData2) {
int intRtn;
switch (event) {
case EVENT_GOT_FOCUS:
doSomething0();
break;
case EVENT_LOST_FOCUS:
doSomething1();
break;
case EVENT_CLOSE:
doSomething2();
break;
case EVENT_MYFUNCTION: // Got a custom event!
doSomething3();
break;
}
return 0;
}
10-26-2016 05:08 PM
My solution is not exactly what you describe. Inside the function, immediately before returning 3 (or maybe instead of returning 3) you could issue a PostDeferredCall to launch a specific function.
10-26-2016 05:34 PM
Can you give an example code?
I just searched it, but it does not easly come out...
10-27-2016 03:47 AM
It is just as simple as doing something along this line:
void CVICALLBACK outFunction (void *callbackData); // Output function on event
int myFunction(int intVal) { if (intVal == 'X_condition')
return -1; else if (intVal == 'O_conditon') { PostDeferredCall (OutFunction, NULL); return 3; }
return 0; }
void CVICALLBACK outFunction (void *callbackData)
{
doSometing ();
}
10-27-2016 12:46 PM - edited 10-27-2016 12:47 PM
Thank you for your example,
but I'm a little bit more confused.
What is the difference between issuing PostDeferredCall and calling dosomething() function.
What I want is asynchronous interrupt.
Assume that intVal is a memory location updated by an external program or an external device.
When intVal is 3, I want to do something.
at CVI2013 help: http://zone.ni.com/reference/en-XX/help/370051Y-01/cvi/uiref/cvipostdeferredcall/
It says that "This function is useful when external devices generate interrupts during source program execution."
but I cannot find an example that I want to do.
I do not use NI board, so GPIB is not available to use ibnotify(). A similar example is here at appendix C: http://www.ni.com/tutorial/3458/en/#toc7
10-27-2016 03:59 PM
Hi Robert,
I just tested with an example on my local disk: National Instruments\CVI2013\samples\utility\Threading\Simple
This is working but I have some data lost.
Is there more secured or reliable method for asynchronous interrupt without data loosing??
Please help me..
10-27-2016 04:45 PM
There is a basic difference between directly calling a function and using PostDeferredCall: in the first case you do not leave the timer while doSomething function is executing: this means that if the function lasts too much it may affect timer event scheduling.
Post deferred functions are executed in the main thread after the originating function has terminated. Even if it lasts too much, the timer could fire again if schedule expires.