Linux Users

cancel
Showing results for 
Search instead for 
Did you mean: 

DAQmx Python API Adding a Network Device Channel Error

So I was successfully added a NI-9185 via Ethernet using the Python API. But when I trying to add channels (NI-9234 ai0:2 to read a tri-accelerometer), there is always issue with the channel name.

The current programming environment is Ubuntu, the same code can be run on the Windows machine. Is there something wrong with the way I am adding the channels?

 

I am attaching my code below (running on jupyter notebook) along with the error:

 

#################### this program is used to monitor the vibration data ########################################################
#################### the monitored data is saved into folder: x ############
#################### the monitored data is saved into small segments @ 1 second per segment ####################################

import nidaqmx
from nidaqmx.constants import AcquisitionType, ExcitationSource, AccelSensitivityUnits
import numpy as np
import time
from datetime import datetime
import os

ip="169.254.245.144" #169.254.62.190
device_name = "CNC_DAQ"  # Optional, a name for the device

# Add the device, and attempt to reserve it
try:
    added_device = nidaqmx.system.Device.add_network_device(ip, device_name=device_name, attempt_reservation=True)
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)
print(f"Successfully added and reserved device: {added_device.name}")
print("The device IP:",ip)

channel = 'Mod1/ai0:2'
sample_rate = 51200
samples_to_acq = 51200 #51200
wait_time = samples_to_acq/sample_rate
# recording time
listening_time = 480
# specify IP instead to get the connection
cont_mode = AcquisitionType.CONTINUOUS
units_g = nidaqmx.constants.AccelUnits.G

all_data = []
#all_timestamps = []

i_flag = 0

#create folder if it is not there already
output_folder = r"C:\Users\NJAMI\DAQ_Vibration\Python_DAQ\Acquired data"
if not os.path.exists(output_folder):
    os.makedirs(output_folder)
    
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.MILLIVOLTS_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...")
    while True:
        try:
            # Reading data from sensor and generating time data with numpy
            ydata = task.read(number_of_samples_per_channel=samples_to_acq)
            #current_timestamp = datetime.now()
            
            all_data.append(ydata)
            #all_timestamps.append(current_timestamp)

            i_flag += 1
            ## to save the data into small pieces
            np.save(os.path.join(output_folder, f'accel_data_temp_{i_flag}.npy'), np.array(all_data))  # for save into smaller files
            #np.save(os.path.join(output_folder, f'timestamps_temp_{i_flag}.npy'), np.array(all_timestamps))  # for save into smaller files
            ## to save the data into small pieces, comments out if not needed
            all_data = []
            #all_timestamps = []

            # exit the monitoring after the number * wait time
            if i_flag % listening_time == 0:               
                print("Data recorded with", sample_rate, "Hz sampling rate")
                break
        except KeyboardInterrupt:
            print("Data acquisition stopped.")
try:
    added_device.delete_network_device()
    print(f"Successfully deleted network device: {added_device.name}")
except Exception as e:
    print(f"Failed to delete network device: {e}")

 

 

the output and error:

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
0 Kudos
Message 1 of 7
(342 Views)

I'm not sure this is the problem, but it's something I noticed: the code is using Mod1 but the error is reporting Mod0.

 

#Need to wait the device to be loaded
time.sleep(3)
print(f"Successfully added and reserved device: {added_device.name}")
print("The device IP:",ip)

channel = 'Mod1/ai0:2'

 

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

 

Joe Friedchicken
NI Configuration Based Software
Get with your fellow OS users
[ Linux ] [ macOS ]
Principal Software Engineer :: Configuration Based Software
Senior Software Engineer :: Multifunction Instruments Applications Group (until May 2018)
Software Engineer :: Measurements RLP Group (until Mar 2014)
Applications Engineer :: High Speed Product Group (until Sep 2008)
0 Kudos
Message 2 of 7
(334 Views)

Sorry for the confusion, the error code should be Mod1 and I also tried Mod0 but getting the same error code so I just attached that to here.

0 Kudos
Message 3 of 7
(332 Views)

I think I found the issue. I did not reboot the system after install the NI daqmx api. After reboot it is working.

0 Kudos
Message 4 of 7
(320 Views)

Question: i am working with DAQmx and python but just started using network devics ( same as you)

do i all ways have to do this section before defining a task ?

 

ip="169.254.245.144" #169.254.62.190
device_name = "CNC_DAQ"  # Optional, a name for the device

# Add the device, and attempt to reserve it
try:
    added_device = nidaqmx.system.Device.add_network_device(ip, device_name=device_name, attempt_reservation=True)
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)
print(f"Successfully added and reserved device: {added_device.name}")
print("The device IP:",ip)​




0 Kudos
Message 5 of 7
(189 Views)

Yes, you need to add the network device before it can be read. And after you finish the task, you need to delete the network device so others can add it to the system later.

0 Kudos
Message 6 of 7
(143 Views)

when running the foloing command:

self.added_device = nidaqmx.system.Device.add_network_device("172.23.138.251", "cDAQ9185-251")

I get :

Fatal Python error: Segmentation fault

Current thread 0x00007f4f90cbd500 (most recent call first):
File "third_party/py/nidaqmx/_library_interpreter.py", line 102 in add_network_device
File "third_party/py/nidaqmx/system/device.py", line 1289 in add_network_device


unisg python NIDAQMX 1.0.0
DAQMX drives 23Q4

I suspect that it relgiths to Version 1.0.0of python cause in stend alone command with version 0.8  it passed
 

0 Kudos
Message 7 of 7
(131 Views)