Skip to content

Commit

Permalink
Merge pull request #15 from CarlAndersson/callback-clearing
Browse files Browse the repository at this point in the history
Fix for unregistering callbacks
  • Loading branch information
Wondernutz authored Jul 10, 2017
2 parents 62ba6c4 + 38f9f09 commit 552b12a
Showing 1 changed file with 41 additions and 24 deletions.
65 changes: 41 additions & 24 deletions nidaqmx/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -716,17 +716,21 @@ def register_done_event(self, callback_method):
DAQmxDoneEventCallbackPtr = ctypes.CFUNCTYPE(
ctypes.c_int32, lib_importer.task_handle, ctypes.c_int32,
ctypes.c_void_p)


cfunc = lib_importer.windll.DAQmxRegisterDoneEvent
cfunc.argtypes = [
lib_importer.task_handle, ctypes.c_uint, DAQmxDoneEventCallbackPtr,
ctypes.c_void_p]

if callback_method is not None:
callback_method_ptr = DAQmxDoneEventCallbackPtr(callback_method)
self._done_event_callbacks.append(callback_method_ptr)
else:
del self._done_event_callbacks[:]

cfunc = lib_importer.windll.DAQmxRegisterDoneEvent
cfunc.argtypes = [
lib_importer.task_handle, ctypes.c_uint, DAQmxDoneEventCallbackPtr,
ctypes.c_void_p]
callback_method_ptr = None
cfunc.argtypes = [
lib_importer.task_handle, ctypes.c_uint, ctypes.c_void_ptr,
ctypes.c_void_p]

error_code = cfunc(
self._handle, 0, callback_method_ptr, None)
Expand Down Expand Up @@ -769,19 +773,23 @@ def register_every_n_samples_acquired_into_buffer_event(
DAQmxEveryNSamplesEventCallbackPtr = ctypes.CFUNCTYPE(
ctypes.c_int32, lib_importer.task_handle, ctypes.c_int32,
ctypes.c_uint32, ctypes.c_void_p)


cfunc = lib_importer.windll.DAQmxRegisterEveryNSamplesEvent
cfunc.argtypes = [
lib_importer.task_handle, ctypes.c_int, ctypes.c_uint,
ctypes.c_uint, DAQmxEveryNSamplesEventCallbackPtr, ctypes.c_void_p]

if callback_method is not None:
callback_method_ptr = DAQmxEveryNSamplesEventCallbackPtr(
callback_method)
self._every_n_acquired_event_callbacks.append(
callback_method_ptr)
else:
del self._every_n_acquired_event_callbacks[:]

cfunc = lib_importer.windll.DAQmxRegisterEveryNSamplesEvent
cfunc.argtypes = [
lib_importer.task_handle, ctypes.c_int, ctypes.c_uint,
ctypes.c_uint, DAQmxEveryNSamplesEventCallbackPtr, ctypes.c_void_p]
callback_method_ptr = None
cfunc.argtypes = [
lib_importer.task_handle, ctypes.c_int, ctypes.c_uint,
ctypes.c_uint, ctypes.c_void_p, ctypes.c_void_p]

error_code = cfunc(
self._handle, EveryNSamplesEventType.ACQUIRED_INTO_BUFFER.value,
Expand Down Expand Up @@ -826,20 +834,25 @@ def register_every_n_samples_transferred_from_buffer_event(
ctypes.c_int32, lib_importer.task_handle, ctypes.c_int32,
ctypes.c_uint32, ctypes.c_void_p)

cfunc = lib_importer.windll.DAQmxRegisterEveryNSamplesEvent
cfunc.argtypes = [
lib_importer.task_handle, ctypes.c_int, ctypes.c_uint,
ctypes.c_uint, DAQmxEveryNSamplesEventCallbackPtr,
ctypes.c_void_p]

if callback_method is not None:
callback_method_ptr = DAQmxEveryNSamplesEventCallbackPtr(
callback_method)
self._every_n_transferred_event_callbacks.append(
callback_method_ptr)
else:
del self._every_n_transferred_event_callbacks[:]

cfunc = lib_importer.windll.DAQmxRegisterEveryNSamplesEvent
cfunc.argtypes = [
lib_importer.task_handle, ctypes.c_int, ctypes.c_uint,
ctypes.c_uint, DAQmxEveryNSamplesEventCallbackPtr,
ctypes.c_void_p]

callback_method_ptr = None
cfunc.argtypes = [
lib_importer.task_handle, ctypes.c_int, ctypes.c_uint,
ctypes.c_uint, ctypes.c_void_p,
ctypes.c_void_p]

error_code = cfunc(
self._handle, EveryNSamplesEventType.TRANSFERRED_FROM_BUFFER.value,
sample_interval, 0, callback_method_ptr, None)
Expand Down Expand Up @@ -877,17 +890,21 @@ def register_signal_event(self, signal_type, callback_method):
DAQmxSignalEventCallbackPtr = ctypes.CFUNCTYPE(
ctypes.c_int32, lib_importer.task_handle, ctypes.c_int32,
ctypes.c_void_p)

cfunc = lib_importer.daqlib.DAQmxRegisterSignalEvent
cfunc.argtypes = [
lib_importer.task_handle, ctypes.c_int, ctypes.c_uint,
DAQmxSignalEventCallbackPtr, ctypes.c_void_p]

if callback_method is not None:
callback_method_ptr = DAQmxSignalEventCallbackPtr(callback_method)
self._signal_event_callbacks.append(callback_method_ptr)
else:
del self._signal_event_callbacks[:]

cfunc = lib_importer.daqlib.DAQmxRegisterSignalEvent
cfunc.argtypes = [
lib_importer.task_handle, ctypes.c_int, ctypes.c_uint,
DAQmxSignalEventCallbackPtr, ctypes.c_void_p]
callback_method_ptr = None
cfunc.argtypes = [
lib_importer.task_handle, ctypes.c_int, ctypes.c_uint,
ctypes.c_void_ptr, ctypes.c_void_p]

error_code = cfunc(
self._handle, signal_type.value, 0, callback_method_ptr, None)
Expand Down

0 comments on commit 552b12a

Please sign in to comment.