Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Python DAQmx bindings: get task from task handle

Solved!
Go to solution

Hi all,

 

The Python DAQmx bindings have a bunch of callback registration methods. For example, you can register a callback that will execute when a task completes. The callback methods all have a signature that provides a "task handle" to the callback (the handle appears to be an integer).

 

From what I can tell, there isn't much you can do with that task handle. Ideally, there would be some way to look up a task object using that integer. Is there a method to do that look up? I have not been able to identify one, and if there isn't one, I'm not sure what the point of the handle is. Are there other things you can do with it?

 

Beyond that, all the callbacks have a signature that includes "callback_data," a parameter that contains the value passed to the registration function. However, none of the registration functions take an arbitrary data parameter. If that were an option, I could simply give it a reference to the task object so the callback would have that. In this case, it just seems like the documentation is incorrect.

 

Anyone got any thoughts on this? Thanks!

0 Kudos
Message 1 of 3
(1,679 Views)
Solution
Accepted by Chris_Cilino

The design of the callback deals with the Python API using the C API underneath but trying to have a more Python way of doing things.

 

There currently isn't a way to go from a task ID to a Python task object. Also in the API a void pointer is passed by default for the callbackData so it also isn't usable.

 

The idea I believe is to create callbacks that are either in the scope of a function or to create a lambda so that variables that are in scope can be use in the callback. Like in how the every_n_samples_event.py example does it.

 

This does appear to be an area where the Python API could be improved to either make those parameters usable or change the API where clients would not need to specify those parameters. The register function would then wrap their callback in a callback that would specify the unused parameters so they would not confuse API users. I created this issue and labeled it as an enhancement.

Message 2 of 3
(1,611 Views)

Thanks for the insight and for filing an issue! I'll add a comment over there to describe the use case and provide some context.

 

Thanks again!

0 Kudos
Message 3 of 3
(1,588 Views)