The callback function has the following format. You can specify any name for this function.
public int CallBackProc(short Id, short Message, int wParam, int lParam, void *Param);
[unsafe] keyword is required for any functions dealing with pointers.
Add [unsafe] keyword to the created callback routine.
unsafe public int CallBackProc(short Id, short Message, int wParam, int lParam, void *Param)
{
.
.
.
In Visual C#, please use delegate to handle a function pointer.
The delegate declarations for each callback routine are written in the CaioCs.cs file.
Analog Input |
PAICALLBACK |
Analog Output |
PAOCALLBACK |
Counter |
PCNTCALLBACK |
Timer |
PTMCALLBACK |
Please use the following functions to register callback functions.
Analog Input |
AioSetAiCallBackProc |
Analog Output |
AioSetAoCallBackProc |
Counter |
AioSetCntCallBackProc |
Timer |
AioSetTmCallBackProc |
. Initialize delegate
. Get the GCHandle to prevent the garbage collector from moving the delegate used for interrupt processing
. Get a stable pointer to the delegate used for interrupt processing
. Register the retrieved stable pointer by using functions such as AioSetAiCallBackProc function
. Release the GCHandle for the delegate used for interrupt processing, when it become unnecessary (for example, when the application terminates)
For these specific coding content, please refer to samples and Note of Using Visual C#.