04-16-2024 02:25 AM - edited 04-16-2024 02:26 AM
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):
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:
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
04-16-2024 07:14 AM
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.
04-18-2024 02:55 AM
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
04-18-2024 07:59 AM
I never had to use threading with DAQmx.
nidaqmx-python/examples are all you need to get started.