From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

How to automatically find a DAQ device number using Python

Solved!
Go to solution

Hello,

 

I'm using the NI DAQ USB-6001 on our assembly line as part of our functional test machine. It works great, but I have one problem.

 

When I plug in a different USB-6001 to the computer, it comes up as a different "Device number". In my Python code, I have to change this manually. If I forget, our code fails and the operators can't figure it out on their own. Considering each computer only has one USB DAQ, it should be easy to figure out automatically the device number, especially considering the error message on the console gives me a suggested device number/name to choose. 

 

Is there a python function in PyDaqmx that already does this? If so, what is it?

 

I have tried to find the Python code that spits out the error message with the suggested device name, but can't find it on my computer. Where is this located?

 

Thank you,

Rob H

0 Kudos
Message 1 of 5
(5,522 Views)
Solution
Accepted by topic author Rob_Helvestine

Hi Rob,

Have you tried to use the nidaqmx.system.System object?

 

You can find more about in the following link: https://nidaqmx-python.readthedocs.io/en/latest/

 

Also, here it is an example of how to do so in different text-based languages:

 

Programmatically Detect DAQ Device Information in Text-Based Environments - https://knowledge.ni.com/KnowledgeArticleDetails?id=kA00Z0000019P0rSAE&l=en-US

 

Regards,

 

Natalia

Applications Engineering

National Instruments

 

0 Kudos
Message 2 of 5
(5,491 Views)

Thank you, Natalia. This solves my issue. 

0 Kudos
Message 3 of 5
(5,487 Views)

Hi, I'm having trouble understanding the API guide you linked to.

 

How does one use Python code to get the device names connected via USB to the computer? Mine are just a pair of NI USB-6501 at the moment.

 

I tried the following:

 

import nidaqmx

from nidaqmx.system import System

 

device_collection = System.devices
device_names = device_collection.device_names
print(*device_names, sep = ", ")

 

 

But, I get:

 

(venv) masked@masked:~/Desktop/try_ni_daq$ python3 ./nidaqctrl_launcher.py
Top of nidaqctrl()...
Traceback (most recent call last):
File "/home/masked/Desktop/try_ni_daq/./nidaqctrl_launcher.py", line 17, in <module>
sys.exit(main())
File "/home/masked/Desktop/try_ni_daq/./nidaqctrl_launcher.py", line 12, in main
nidaqctrl.nidaqctrl()
File "/home/masked/Desktop/try_ni_daq/nidaqctrl/nidaqctrl.py", line 15, in nidaqctrl
device_names = device_collection.device_names
AttributeError: 'property' object has no attribute 'device_names'

0 Kudos
Message 4 of 5
(3,014 Views)

You can use this example to get the device names: https://github.com/ni/nidaqmx-python/blob/master/nidaqmx_examples/system_properties.py

The device name can be found in NI MAX as well

Here you can find more examples: https://github.com/ni/nidaqmx-python/tree/master/nidaqmx_examples

0 Kudos
Message 5 of 5
(2,990 Views)