diff --git a/daqhats/hats.py b/daqhats/hats.py index e93ce4d..80e0e1d 100644 --- a/daqhats/hats.py +++ b/daqhats/hats.py @@ -58,8 +58,8 @@ class HatCallback(object): DAQ HAT interrupt callback function class. This class handles passing Python functions to the shared library as a - callback then retrieving the passed user data as a Python object when - the function is called from the library. + callback. It stores the user data internally and passes it to the callback + function to avoid issues with passing the object through the library. The callback function should have a single argument (optional) that is a Python object the user provides to :py:func:`interrupt_callback_enable` that @@ -77,6 +77,7 @@ def __init__(self, function): self.function = function self.cbfunctype = CFUNCTYPE(None, c_void_p) self.cbfunc = None + self.user_data = None def get_callback_func(self): """ @@ -88,17 +89,17 @@ def func(user_data): """ Function wrapper. """ - self.handle_callback(user_data) + self.handle_callback() self.cbfunc = self.cbfunctype(func) return self.cbfunc - def handle_callback(self, user_data): + def handle_callback(self): """ - This is directly called from the interrupt thread. It converts the - void* back into a python object then calls the user's callback. + This is directly called from the interrupt thread. It calls the user's + callback, passing the user_data object that gets set with + interrupt_callback_enable(). """ - p_user_data = cast(user_data, POINTER(py_object)).contents.value - self.function(p_user_data) + self.function(self.user_data) def _load_daqhats_library(): """ @@ -301,11 +302,12 @@ def my_function(data): c_void_p] _libc.hat_interrupt_callback_enable.restype = c_int - # cast the python user_data object to a void* - c_user_data = cast(pointer(py_object(user_data)), c_void_p) + # save the user data in the HatCallback object + callback.user_data = user_data + # pass the callback class handler function and void * to the library if (_libc.hat_interrupt_callback_enable(callback.get_callback_func(), - c_user_data) != 0): + None) != 0): raise Exception("Could not enable callback function.") def interrupt_callback_disable(): diff --git a/version_history.txt b/version_history.txt index 5cfbaba..91f64c0 100644 --- a/version_history.txt +++ b/version_history.txt @@ -3,10 +3,15 @@ MCC 118 - updated both library and trigger examples. - Lowered the max SPI clock rate for the MCC 118 to fix communications issues on some systems. + - Fixed an issue with MCC 152 DIO interrupt callbacks in Python when + running a scan on a separate MCC 118 -1.1.0.1: Fixed an issue with resource conflicts when using multiple threads in +1.1.0.1: + - Fixed an issue with resource conflicts when using multiple threads in the same process (such as using multiple MCC 118s.) -1.1.0: Added support for the MCC 152. +1.1.0: + - Added support for the MCC 152. -1.0.0: Initial release for the MCC 118. +1.0.0: + - Initial release for the MCC 118.