Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Multithreading with PCIe-6363 AI channels

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!

 

0 Kudos
Message 1 of 5
(177 Views)

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.

Santhosh
Soliton Technologies

New to the forum? Please read community guidelines and how to ask smart questions

Only two ways to appreciate someone who spent their free time to reply/answer your question - give them Kudos or mark their reply as the answer/solution.

Finding it hard to source NI hardware? Try NI Trading Post
0 Kudos
Message 2 of 5
(154 Views)

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

0 Kudos
Message 3 of 5
(121 Views)

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.

0 Kudos
Message 4 of 5
(107 Views)

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.

santo_13_0-1730644910721.png

 

Another related article, https://knowledge.ni.com/KnowledgeArticleDetails?id=kA00Z000000P8kmSAC&l=en-US

 

santo_13_1-1730645083964.png

 

 

Santhosh
Soliton Technologies

New to the forum? Please read community guidelines and how to ask smart questions

Only two ways to appreciate someone who spent their free time to reply/answer your question - give them Kudos or mark their reply as the answer/solution.

Finding it hard to source NI hardware? Try NI Trading Post
Message 5 of 5
(98 Views)