Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for unregistering callbacks #15

Merged
merged 1 commit into from
Jul 10, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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