Skip to content

InStream.get_channels_buffer_size uses wrong encoding #620

@bkeryan

Description

@bkeryan

InStream.get_channels_buffer_size and OutStream.get_channels_buffer_size read the Task.channel_names property to calculate the maximum buffer size for a fault condition status property such as overcurrent_chans.

The problem is that these functions are calculating the length of the channel_names property after decoding from bytes to str. If Python represents str as UTF-16 or UTF-32, the number of characters in a str may be smaller than the number of UTF-8 bytes used to return that str from the DAQmx C API. When this happens, reading the fault condition property will likely return a "buffer too small" error when there is a fault.

Some potential solutions:

  • Use DAQmxGetTaskChannels(task, NULL, 0) to query the size of the TaskChannels property in the C API's native encoding (UTF-8 or MBCS). This would also be a small optimization because it would query the size of the TaskChannels property without querying the actual value.
  • Convert the task channels back to the C API's native encoding. This is a hack, so the first solution is better.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions