Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Using task_handle in callback of register_every_n_samples_acquired_in_buffer(..., callback) - non homogeneous to task = nidaqmx.Task(...)

Solved!
Go to solution

Again on callback topic (note that I am posting in HW forum where I have already seen python code snippets while nothing seems to match in SW boards. Maybe there could be a SW board about nidaqmx-python)

 

  • I store all the tasks I am creating: task = nidaqmx.Task("Task_" + device.name); all_tasks.append(task)
  • in my callback I try to match 1 of these tasks with the task_handle (def callback_nidaq(task_handle, every_n_samples_event_type, number_of_samples, callback_data))
  • testing task._handle == task_handle did not work, I ended up doing task._handle.value == task_handle

 

When I dump both handles, I get: task._handle: c_void_p(138902160250752) task_handle: 138902160250752. So it explains why task._handle.value works

 

Why is it not homogeneous ? Is it intended to be used as I am using it (at least in C API, I guess yes) ? nidaqmx-python is a front-end to C libs so I understand handles as ctypes but don't see why task_handled is not ctype

 

 

0 Kudos
Message 1 of 2
(127 Views)
Solution
Accepted by topic author ft_06

As discussed in other threads, task_handle can be answered through functools.partial like callback_data. Above method works but NI uses internally partial. In my case:

 

def callback_nidaq(task, task_handle, every_n_samples_event_type, number_of_samples, callback_data):

    # task is the task referred by task_handle so no need to use task_handle

 

When configuring the tasks:

for task in all_tasks:

    task.register_every_n_samples_acquired_into_buffer_event(xxx, functools.partial(callback_nidaq, task))

 

 

 

 

 

0 Kudos
Message 2 of 2
(79 Views)