02-15-2019 02:32 PM
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
Solved! Go to Solution.
02-18-2019 10:01 AM
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
02-18-2019 11:37 AM
Thank you, Natalia. This solves my issue.
12-08-2022 11:30 AM
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'
12-08-2022 05:46 PM
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