11-01-2024 12:45 AM
I'm trying to figure out how I can use the AI channels with multithreading in Python. Here is my experiment: I created two threads, and each thread would create a task to read one analog input channel. There would be an error of "nidaqmx.errors.DaqReadError: The specified resource is reserved". But it doesn't happen if I use the two threads to operate on other channel combinations, like
analog input + analog output,
analog output + analog output,
analog input + digital input,
.....
So far I only found that error happens with analog input + analog input.
I wonder why is that? Are the analog input channels share any resources (like clock)? Why that error doesn't happen with other combinations?
Thanks!
11-01-2024 07:57 AM - edited 11-01-2024 07:58 AM
Fundamental rule: on 6363, you can have only one DAQmx Task per board per type for hardware-timed operations on AI, AO, DI, and DO. So, when the first thread creates a hardware-timed task for AI, the next thread cannot create another DAQmx task for AI unless the first thread releases.
On the other hand, when each thread creates Task for a different type, there is no issue as it doesn't exceed the 1 task per type rule.
This applies to most NI DAQ hardware and by hardware design.
11-01-2024 03:18 PM
Here is how we leveraged mult-threading:
- only 1 thread per card for AI can be registered
task.register_every_n_samples_acquired_into_buffer_event(xxx, callback_nidaq)
def callback_nidaq(..., task_handle, every_n_samples_event_type, number_of_samples, callback_data):
task = .... # some magic to get the task easily, see thread mentionning functools.partial
# read task: all AI channels are read containing a list of list
data = task.read(number_of_samples_per_channel = number_of_samples)
- copy the data in a specific place
- start various processing threads from this thread, here you can have 1 thread per channel if you want as you have copied them internally
11-03-2024 12:49 AM
Is there any official document describing "only one DAQmx Task per board per type for hardware-timed operations on AI, AO, DI, and DO"?
It's weird as I was able to use two threads to process two digital lines, as well as two analog outputs at the same time.
11-03-2024 08:42 AM - edited 11-03-2024 08:44 AM
dwang@aurora.tech wrote:
Is there any official document describing "only one DAQmx Task per board per type for hardware-timed operations on AI, AO, DI, and DO"?
It's weird as I was able to use two threads to process two digital lines, as well as two analog outputs at the same time.
You can use it as long as the hardware timed task is not running simultaneously or you were using software timed single point, i.e., doesn't use a sample clock.
Here you go,
https://knowledge.ni.com/KnowledgeArticleDetails?id=kA00Z0000019KWYSA2
Check out the Hardware-timed section, i.e., if it uses a sample clock.
Another related article, https://knowledge.ni.com/KnowledgeArticleDetails?id=kA00Z000000P8kmSAC&l=en-US