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 Count Match Notification.
Please refer to the sample program for these specific coding contents.

For the callback function of Count Match Notification, Counter Error Notification,
Carry/Borrow Notification, Timer Notification, Sampling Stop Notification, Specified Time Sampling Completion,
please refer to the description in the ccnt.py file and read the prototype function as a reference.
 

Checking function prototype definition of callback function

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

For Count Match Notification

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

Creating Callback Function

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

For Count Match Notification

def count_call_back(dev_id, wparam, lparam, param):
    ・・・・・
    retrun
 
pcount_callback = ccnt.PCNT_MATCH_CALLBACK(count_call_back)
 

Setting Callback Function

Use the cnt_id retrieved from CntInit function and set the created callback routine as follows.

For Count Match Notification

lret.value = ccnt.CntCountUpCallbackProc(cnt_id, pcount_callback, "Match Count")