LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I assign a specific function return to an event?

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;
}

0 Kudos
Message 1 of 7
(3,350 Views)

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.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 7
(3,337 Views)

Can you give an example code?

I just searched it, but it does not easly come out...

 

 

0 Kudos
Message 3 of 7
(3,333 Views)

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 ();
}

 

 

 



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 4 of 7
(3,308 Views)

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

 

 

0 Kudos
Message 5 of 7
(3,299 Views)

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..

0 Kudos
Message 6 of 7
(3,290 Views)

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.

 



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 7 of 7
(3,286 Views)