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

InStream.get_channels_buffer_size uses wrong encoding

Open bkeryan opened this issue 6 months ago • 1 comments

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.

bkeryan avatar Jul 31 '24 23:07 bkeryan