・Checking function prototype definition of callback routine
・Creating callback routine
・Setting callback routine
The following explains how to use the callback function for Analog Input.
Please refer to the sample program for these specific coding contents.
For the callback function of Analog Output, Counter, Timer,
please refer to the description in the caio.py file and read the prototype function as a reference.
To deal with callback functions in Python, we need to define a function prototype.
Function prototype declarations for each callback routine are in the caio.py file.
Please check the contents of the function prototype.
For Analog Input
PAIO_AI_CALLBACK = ctypes.WINFUNCTYPE(None,
ctypes.c_short, ctypes.c_short, ctypes.wintypes.WPARAM,
ctypes.wintypes.LPARAM, ctypes.c_void_p)
A callback function has the following format. The function name is arbitrary.
For Analog Input
def CallBackProc(dev_id, AiEvent, wparam, lparam, param):
・・・・・
retrun
pai_callback = caio.PAIO_AI_CALLBACK(CallBackProc)
Use the aio_id retrieved from AioInit function and set the created callback routine as follows.
For Analog Input
lret.value = caio.AioSetAiCallBackProc(aio_id, pai_callback, caio.AIE_END | caio.AIE_OFERR | caio.AIE_SCERR | caio.AIE_ADERR, ctypes.byref(CallBackFlag))