06-04-2024 04:07 PM
So I was trying to use Python API to add and read NI-9234 via ethernet. Although I can add it without problem, there were always issues with the channels.
Everytime I am trying to add the channels I got error:
DaqError: Physical channel specified does not exist on this device.
Refer to the documentation for channels available on this device.
I am attaching my code below and it's output as well. The same code can run on a windows machine without issue. Can anyone please advice where could be the issue?
import nidaqmx
from nidaqmx.constants import AcquisitionType, ExcitationSource, AccelSensitivityUnits
import numpy as np
import time
ip="169.254.245.144" #169.254.62.190
#device_name = "DAQ"#f"{ip}/cDAQ1Mod1" # Optional, a name for the device
channel = 'Mod0/ai0:2' #/Mod1
# Add the device, and attempt to reserve it
try:
added_device = nidaqmx.system.Device.add_network_device(ip, attempt_reservation=True)#device_name=device_name,
print(f"Successfully added and reserved device: {added_device.name}")
print("The device IP:",ip)
except Exception as e:
print(f"Failed to add and reserve network device: {e}")
exit(1)
#Need to wait the device to be loaded
time.sleep(3)
#configure the setting
sample_rate = 51200
samples_to_acq = 51200 #51200
wait_time = samples_to_acq/sample_rate
cont_mode = AcquisitionType.CONTINUOUS
units_g = nidaqmx.constants.AccelUnits.G
all_data = []
#all_timestamps = []
i_flag = 0
print("reading starts")
with nidaqmx.Task() as task:
print("Initilization data acquisition process")
# Create accelerometer channel and configure sample clock and trigger specs
task.ai_channels.add_ai_accel_chan(f"{added_device.name}/{channel}",
min_val=- 100.0,
max_val=100.0,
units=units_g,
sensitivity=50.0,
sensitivity_units=nidaqmx.constants.AccelSensitivityUnits.M_VOLTS_PER_G,
current_excit_source=ExcitationSource.INTERNAL)#, current_excit_val=0.004)
task.timing.cfg_samp_clk_timing(sample_rate, sample_mode = cont_mode, samps_per_chan=samples_to_acq)
print("Reading DAQ...")
Successfully added and reserved device: cDAQ9185-20FB3D9
The device IP: 169.254.245.144
reading starts
Initilization data acquisition process
---------------------------------------------------------------------------
DaqError Traceback (most recent call last)
<ipython-input-1-1cacad5452fa> in <module>
43 sensitivity=50.0,
44 sensitivity_units=nidaqmx.constants.AccelSensitivityUnits.M_VOLTS_PER_G,
---> 45 current_excit_source=ExcitationSource.INTERNAL)#, current_excit_val=0.004)
46 task.timing.cfg_samp_clk_timing(sample_rate, sample_mode = cont_mode, samps_per_chan=samples_to_acq)
47 print("Reading DAQ...")
~/.local/lib/python3.6/site-packages/nidaqmx/_task_modules/ai_channel_collection.py in add_ai_accel_chan(self, physical_channel, name_to_assign_to_channel, terminal_config, min_val, max_val, units, sensitivity, sensitivity_units, current_excit_source, current_excit_val, custom_scale_name)
211 sensitivity_units.value, current_excit_source.value,
212 current_excit_val, custom_scale_name)
--> 213 check_for_error(error_code)
214
215 return self._create_chan(physical_channel, name_to_assign_to_channel)
~/.local/lib/python3.6/site-packages/nidaqmx/errors.py in check_for_error(error_code)
125 cfunc(error_buffer, 2048)
126
--> 127 raise DaqError(error_buffer.value.decode("utf-8"), error_code)
128
129 elif error_code > 0:
DaqError: Physical channel specified does not exist on this device.
Refer to the documentation for channels available on this device.
Device: cDAQ9185-20FB3D9
Physical Channel Name: Mod0/ai0
Task Name: _unnamedTask<0>
Status Code: -200170
06-05-2024 07:45 PM
Use Hardware Configuration Utility to make sure that your NI-DAQmx driver is installed properly and the hardware is detected.