Python

Flow of Registering Callback Routine Function

・Checking function prototype definition of callback routine
・Creating callback routine
・Setting callback routine
 

The following explains how to use the callback function for receive.
Please refer to the sample program for these specific coding contents.

 

Check function prototype definition of callback function

To deal with callback functions in Python, we need to define a function prototype.
Function prototype declarations for callback routine are in the ccan.py file.
Please check the contents of the function prototype.

For receive

PCAN_EVENT_CALLBACK = ctypes.WINFUNCTYPE(None,
                                         ctypes.c_short, ctypes.wintypes.WPARAM, ctypes.wintypes.LPARAM,
                                         ctypes.c_void_p)
 

Create Callback Function

A callback function has the following format. The function name is arbitrary.

For receive

def CallBackProc(id, wParam, lParam, Param):
    ・・・・・
    retrun
 
pcan_callback = ccan.PCAN_EVENT_CALLBACK(CallBackProc)
 

Set Callback Function

Use the id retrieved from CanInit function and set the created callback routine as follows.

For receive

lret.value = ccan.CanNotifyEvent(id, channel_no, ccan.CCAN_EVENT_RECEIVE, pcan_callback, ctypes.byref(receive_no))