Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Trigger implementation with Python NIDAQmx

Hi all,

 

 

I am using Python 3.10.14 with NIDAQmx 0.9.0. I have a motorized stage, which I control via the serial port in my Python script. The stage is programed to output a trigger at the start of its movement. I want to use this trigger to start my data acquisition. I have a code that works, but I feel I'm over-complicating things and I'd like to have a second opinion.

 

In my code, I'm using the threading module. My idea is to start the DAQmx task (reading 6k samples in two analog input channels) in a separate thread, such that I can keep control of my stage, which ultimately sends the trigger. So, I defined a function to arm my DAQ (USB-6002 for reference):

 

import threading

def arm_daq(data):
    with nidaqmx.Task() as task:
        task.ai_channels.add_ai_voltage_chan("Dev1/ai0:1")
        task.timing.cfg_samp_clk_timing(rate=25e3, samps_per_chan=6000)
        task.triggers.start_trigger.cfg_dig_edge_start_trig("PFI0")
        data[:] = task.read(number_of_samples_per_channel=6000)

 

Then, in my main program, where I control the movement of my stage, I start the thread such that the DAQ becomes ready for triggering, and then I send the commands to move my stage:

 

if __name__ == "__main__":
    data = np.zeros((2, 6000))
    t1 = threading.Thread(target=arm_daq, args=(data,))
    # Instructions to move the stage
    t1.join()

 

Note that the data array is modified in-place within the thread and will be available in the main code automatically.

 

As I said, this works fine for me, but I have to commit a thread for the DAQ. And this is the reason I think I am over-complicating this. I thought the very idea of a DAQ was to offload the "processing" to a separate board (the DAQ). Can someone share their experience on this task? Is it how you'd program your DAQ as well?

 

Thanks for your help and take care,

 

David

 

0 Kudos
Message 1 of 4
(143 Views)

Committing a thread allows you to offline the processing to another CPU core.

DAQ device does not have a processor and cannot run any code. It simply reacts according to the commands sent by the DAQmx driver, which runs on a PC.

If you are not doing any parallel processing, using threading does not make any difference.

-------------------------------------------------------
Control Lead | Intelline Inc
0 Kudos
Message 2 of 4
(115 Views)

Makes sense. I couldn't find any implementation of this before posting. Is it how you would implement this solution as well?

Thanks a lot.

 

David

0 Kudos
Message 3 of 4
(71 Views)

I never had to use threading with DAQmx.

nidaqmx-python/examples are all you need to get started.

-------------------------------------------------------
Control Lead | Intelline Inc
0 Kudos
Message 4 of 4
(60 Views)