nidaqmx-python icon indicating copy to clipboard operation
nidaqmx-python copied to clipboard

Cannot access properties on `DO/DIChannel` with multiple lines an `LineGrouping.CHAN_FOR_ALL_LINES`

Open jgersti opened this issue 1 year ago • 1 comments

Properties on DI/DOChannels with multiple lines and Grouping.CHAN_FOR_ALL_LINES cannot be accessed, because channel.name contains the wrong name.

On an (emulated and real) PCIe-6612 the following code snippet

with nidaqmx.Task() as task:
    channel = task.do_channel.add_do_chan(
        lines="Dev1/PFI25,Dev1/PFI26,Dev1/PFI29,Dev1/PFI30",
        line_grouping=LineGrouping.CHAN_FOR_ALL_LINES,
        name_to_assign_to_lines="Input",
    )
    print(channel.do_num_lines)

results in

nidaqmx.errors.DaqError: Property cannot be set seperately for each line.
When setting this property, specify a virtual channel as the active channel.
Property: DAQmx_DO_NumLines
Channel Name: Input
Physical Channel Name: Dev1/PFI25

Task Name: _unnamedTask<0>

Status Code: -200641

Unassigning channel._name (so that channel.name is resolved to channel._all_channels_name) or directly setting it to "Input" fixes this issues and the proper value (4) is returned.

jgersti avatar Feb 23 '24 13:02 jgersti

@jgersti, thank you for reporting this.

To work around this issue without using private implementation details, you should be able to index the channel collection to create a new channel object with the right name. The channel object is a proxy for the task and channel name, so it's ok to create a new channel object. (Note: I haven't tested this code snippet.)

task.do_channels.add_do_chan(
    lines="Dev1/PFI25,Dev1/PFI26,Dev1/PFI29,Dev1/PFI30",
    line_grouping=LineGrouping.CHAN_FOR_ALL_LINES,
    name_to_assign_to_lines="Input",
)
channel = task.do_channels["Input"]

FYI, when getting/setting per-line DIO properties, you should be able to index the channel collection with the physical channel name (again, untested code snippet):

task.di_channels["Dev1/PFI25"].di_dig_fltr_enable = true

bkeryan avatar Feb 23 '24 14:02 bkeryan