ni / nidaqmx-python

A Python API for interacting with NI-DAQmx
Other
413 stars 155 forks source link

Physical Channel.do_port_width fails for ports of width 1 #588

Closed luhatx closed 2 months ago

luhatx commented 2 months ago

Physical Channels with width 1 give errors when querying the port width. This is e.g. an issue for the NI device USB-6001 (named in our case "USB_6001_1") on PORT2 with width 1. However, the port can be read correctly by system.devices[].do_ports, but its width cannot be queried.

See code below:

import nidaqmx.system

system = nidaqmx.system.System.local()
print(system.driver_version)

for device in system.devices:
    print(device)
    print(hex(device.serial_num))
    print(device.terminals)

    print(device.ai_physical_chans.channel_names)
    print(device.ao_physical_chans.channel_names)
    for do_port in device.do_ports:
        print(do_port)
        print(do_port.do_port_width)
    for di_port in device.di_ports:
        print(di_port)
        print(di_port.di_port_width)

Output is then:

DriverVersion(major_version=24, minor_version=0, update_version=0)
Device(name=USB_6001_1)
0x1b11833
['/USB_6001_1/PFI0', '/USB_6001_1/PFI1', '/USB_6001_1/ai/StartTrigger', '/USB_6001_1/ao/StartTrigger', '/USB_6001_1/Ctr0Source']
['USB_6001_1/ai0', 'USB_6001_1/ai1', 'USB_6001_1/ai2', 'USB_6001_1/ai3', 'USB_6001_1/ai4', 'USB_6001_1/ai5', 'USB_6001_1/ai6', 'USB_6001_1/ai7']
['USB_6001_1/ao0', 'USB_6001_1/ao1']
PhysicalChannel(name=USB_6001_1/port0)
8
PhysicalChannel(name=USB_6001_1/port1)
4
PhysicalChannel(name=USB_6001_1/port2)
Traceback (most recent call last):
  File "H:\PythonSourceAndRun\run_door\nidaqmx_issue.py", line 15, in <module>
    print(do_port.do_port_width)
  File "H:\PythonSourceAndRun\venv\lib\site-packages\nidaqmx\system\physical_channel.py", line 516, in do_port_width
    val = self._interpreter.get_physical_chan_attribute_uint32(self._name, 0x29a7)
  File "H:\PythonSourceAndRun\venv\lib\site-packages\nidaqmx\_library_interpreter.py", line 3185, in get_physical_chan_attribute_uint32
    self.check_for_error(error_code)
  File "H:\PythonSourceAndRun\venv\lib\site-packages\nidaqmx\_library_interpreter.py", line 6381, in check_for_error
    raise DaqError(extended_error_info, error_code)
nidaqmx.errors.DaqError: Device does not support this property.
Device: USB_6001_1
Property: DAQmx_PhysicalChan_DO_PortWidth

Status Code: -200197

Expected output would be:

DriverVersion(major_version=24, minor_version=0, update_version=0)
Device(name=USB_6001_1)
0x1b11833
['/USB_6001_1/PFI0', '/USB_6001_1/PFI1', '/USB_6001_1/ai/StartTrigger', '/USB_6001_1/ao/StartTrigger', '/USB_6001_1/Ctr0Source']
['USB_6001_1/ai0', 'USB_6001_1/ai1', 'USB_6001_1/ai2', 'USB_6001_1/ai3', 'USB_6001_1/ai4', 'USB_6001_1/ai5', 'USB_6001_1/ai6', 'USB_6001_1/ai7']
['USB_6001_1/ao0', 'USB_6001_1/ao1']
PhysicalChannel(name=USB_6001_1/port0)
8
PhysicalChannel(name=USB_6001_1/port1)
4
PhysicalChannel(name=USB_6001_1/port2)
1

Version Infos: nidaqmx 1.0.0.dev0 (but same behaviour with 0.9.0)

Python Version: 3.9.13 (tags/v3.9.13:6de2ca5, May 17 2022, 16:36:42) [MSC v.1929 64 bit (AMD64)]

NI-DAQmx Driver 2024Q1

zhindes commented 2 months ago

This is a device-specific problem. The same issue appears in LabVIEW. I filed this bug internally: