06-21-2024 05:21 AM
Hi ,
I am using NI-cRIO-9066-01d17a1d controller (version 3.0.0f0) connected with NI 9207 , 9266 IO cards and to automate my process I am trying to access the controller and read / write IO card data using python over windows platform. Below is my code snippet of sample code I wrote along with error.
import nidaqmx
import nisyscfg
from nidaqmx.constants import AcquisitionType
def list_systems():
# List all systems
format_string = "{0: <16} {1: <32} {2}"
with nisyscfg.Session() as session:
print(format_string.format("Expert", "Alias", "Resource"))
filter = session.create_filter()
filter.is_present = True
filter.is_ni_product = True
for resource in session.find_hardware(filter):
# The first user alias in the list is from the primary expert
print(
format_string.format(
resource.expert_name[0],
resource.expert_user_alias[0],
resource.expert_resource_name[0],
)
)
def read_analog_input():
with nidaqmx.Task() as task:
# Add an analog input voltage channel
task.ai_channels.add_ai_voltage_chan("RIO0/ai0", terminal_config=nidaqmx.constants.TerminalConfiguration.RSE)
# Configure the timing for continuous acquisition
task.timing.cfg_samp_clk_timing(rate=1000, sample_mode=AcquisitionType.CONTINUOUS, samps_per_chan=1000)
# Start the task
task.start()
try:
# Read a single sample
data = task.read(number_of_samples_per_channel=1)
print(f"Analog Input Value: {data[0]} V")
except nidaqmx.errors.DaqError as e:
print(f"An error occurred: {e}")
finally:
# Stop the task
task.stop()
if __name__ == "__main__":
# List available systems
list_systems()
# Read analog input from the device
read_analog_input()
I am getting error as :
Traceback (most recent call last):
File "D:\Rahul\Project work\pythonProject\nisyscfg-python-main\nisyscfg-python-main\nisyscfg\NI_Test.py", line 52, in <module>
read_analog_input(device_name, channel)
File "D:\Rahul\Project work\pythonProject\nisyscfg-python-main\nisyscfg-python-main\nisyscfg\NI_Test.py", line 31, in read_analog_input
task.ai_channels.add_ai_voltage_chan("RIO0/ai0", terminal_config=nidaqmx.constants.TerminalConfiguration.RSE)
File "C:\Users\rahul.sharma\AppData\Local\Programs\Python\Python312\Lib\site-packages\nidaqmx\_task_modules\ai_channel_collection.py", line 2222, in add_ai_voltage_chan
self._interpreter.create_ai_voltage_chan(
File "C:\Users\rahul.sharma\AppData\Local\Programs\Python\Python312\Lib\site-packages\nidaqmx\_library_interpreter.py", line 1240, in create_ai_voltage_chan
self.check_for_error(error_code)
File "C:\Users\rahul.sharma\AppData\Local\Programs\Python\Python312\Lib\site-packages\nidaqmx\_library_interpreter.py", line 6041, in check_for_error
raise DaqError(extended_error_info, error_code)
nidaqmx.errors.DaqError: Device identifier is invalid.
Device Specified: RIO0
Task Name: _unnamedTask<0>
Status Code: -200220
I have attached snap of system firmware version and resource name I have used.
Please help me if i am missing or doing something wrong