Skip to content

Commit

Permalink
Allocate Buffer Size for Read/Write String Status Properties (#537)
Browse files Browse the repository at this point in the history
* Allocate buffer size to read/write string properties

* fix channels_to_read in out_stream

* Address comments

* Address comment
  • Loading branch information
charitylxy authored Mar 14, 2024
1 parent 0f65354 commit 91cea8e
Show file tree
Hide file tree
Showing 13 changed files with 106 additions and 36 deletions.
4 changes: 2 additions & 2 deletions generated/nidaqmx/_base_interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,7 @@ def get_read_attribute_int32(self, task, attribute):
raise NotImplementedError

@abc.abstractmethod
def get_read_attribute_string(self, task, attribute):
def get_read_attribute_string(self, task, attribute, size_hint=0):
raise NotImplementedError

@abc.abstractmethod
Expand Down Expand Up @@ -1157,7 +1157,7 @@ def get_write_attribute_int32(self, task, attribute):
raise NotImplementedError

@abc.abstractmethod
def get_write_attribute_string(self, task, attribute):
def get_write_attribute_string(self, task, attribute, size_hint=0):
raise NotImplementedError

@abc.abstractmethod
Expand Down
4 changes: 2 additions & 2 deletions generated/nidaqmx/_grpc_interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2031,7 +2031,7 @@ def get_read_attribute_int32(self, task, attribute):
grpc_types.GetReadAttributeInt32Request(task=task, attribute_raw=attribute))
return response.value_raw

def get_read_attribute_string(self, task, attribute):
def get_read_attribute_string(self, task, attribute, size_hint=0):
response = self._invoke(
self._client.GetReadAttributeString,
grpc_types.GetReadAttributeStringRequest(task=task, attribute_raw=attribute))
Expand Down Expand Up @@ -2285,7 +2285,7 @@ def get_write_attribute_int32(self, task, attribute):
grpc_types.GetWriteAttributeInt32Request(task=task, attribute_raw=attribute))
return response.value_raw

def get_write_attribute_string(self, task, attribute):
def get_write_attribute_string(self, task, attribute, size_hint=0):
response = self._invoke(
self._client.GetWriteAttributeString,
grpc_types.GetWriteAttributeStringRequest(task=task, attribute_raw=attribute))
Expand Down
8 changes: 4 additions & 4 deletions generated/nidaqmx/_library_interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3230,15 +3230,15 @@ def get_read_attribute_int32(self, task, attribute):
self.check_for_error(error_code)
return value.value

def get_read_attribute_string(self, task, attribute):
def get_read_attribute_string(self, task, attribute, size_hint=0):
cfunc = lib_importer.cdll.DAQmxGetReadAttribute
if cfunc.argtypes is None:
with cfunc.arglock:
if cfunc.argtypes is None:
cfunc.argtypes = [
lib_importer.task_handle, ctypes.c_int32]

temp_size = 0
temp_size = size_hint
while True:
value = ctypes.create_string_buffer(temp_size)
size_or_code = cfunc(
Expand Down Expand Up @@ -3951,15 +3951,15 @@ def get_write_attribute_int32(self, task, attribute):
self.check_for_error(error_code)
return value.value

def get_write_attribute_string(self, task, attribute):
def get_write_attribute_string(self, task, attribute, size_hint=0):
cfunc = lib_importer.cdll.DAQmxGetWriteAttribute
if cfunc.argtypes is None:
with cfunc.arglock:
if cfunc.argtypes is None:
cfunc.argtypes = [
lib_importer.task_handle, ctypes.c_int32]

temp_size = 0
temp_size = size_hint
while True:
value = ctypes.create_string_buffer(temp_size)
size_or_code = cfunc(
Expand Down
56 changes: 39 additions & 17 deletions generated/nidaqmx/_task_modules/in_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ def aux_power_error_chans(self):
Otherwise, you will receive an error.
"""

val = self._interpreter.get_read_attribute_string(self._handle, 0x31e0)
buffer_size = self.get_channels_buffer_size()
val = self._interpreter.get_read_attribute_string(self._handle, 0x31e0, buffer_size)
return unflatten_channel_string(val)

@property
Expand Down Expand Up @@ -180,7 +181,8 @@ def common_mode_range_error_chans(self):
property. Otherwise, you will receive an error.
"""

val = self._interpreter.get_read_attribute_string(self._handle, 0x2a99)
buffer_size = self.get_channels_buffer_size()
val = self._interpreter.get_read_attribute_string(self._handle, 0x2a99, buffer_size)
return unflatten_channel_string(val)

@property
Expand Down Expand Up @@ -220,7 +222,8 @@ def devs_with_inserted_or_removed_accessories(self):
an error.
"""

val = self._interpreter.get_read_attribute_string(self._handle, 0x2f71)
buffer_size = self.get_channels_buffer_size()
val = self._interpreter.get_read_attribute_string(self._handle, 0x2f71, buffer_size)
return unflatten_channel_string(val)

@property
Expand All @@ -244,7 +247,8 @@ def excit_fault_chans(self):
an error.
"""

val = self._interpreter.get_read_attribute_string(self._handle, 0x3089)
buffer_size = self.get_channels_buffer_size()
val = self._interpreter.get_read_attribute_string(self._handle, 0x3089, buffer_size)
return unflatten_channel_string(val)

@property
Expand Down Expand Up @@ -292,7 +296,8 @@ def input_limits_fault_chans(self):
property. Otherwise, you will receive an error.
"""

val = self._interpreter.get_read_attribute_string(self._handle, 0x3190)
buffer_size = self.get_channels_buffer_size()
val = self._interpreter.get_read_attribute_string(self._handle, 0x3190, buffer_size)
return unflatten_channel_string(val)

@property
Expand Down Expand Up @@ -544,7 +549,8 @@ def open_chans(self):
this property. Otherwise you will receive an error.
"""

val = self._interpreter.get_read_attribute_string(self._handle, 0x3101)
buffer_size = self.get_channels_buffer_size()
val = self._interpreter.get_read_attribute_string(self._handle, 0x3101, buffer_size)
return unflatten_channel_string(val)

@property
Expand All @@ -555,7 +561,8 @@ def open_chans_details(self):
this property. Otherwise you will receive an error.
"""

val = self._interpreter.get_read_attribute_string(self._handle, 0x3102)
buffer_size = self.get_channels_buffer_size()
val = self._interpreter.get_read_attribute_string(self._handle, 0x3102, buffer_size)
return unflatten_channel_string(val)

@property
Expand All @@ -582,7 +589,8 @@ def open_current_loop_chans(self):
error.
"""

val = self._interpreter.get_read_attribute_string(self._handle, 0x2a0a)
buffer_size = self.get_channels_buffer_size()
val = self._interpreter.get_read_attribute_string(self._handle, 0x2a0a, buffer_size)
return unflatten_channel_string(val)

@property
Expand All @@ -609,7 +617,8 @@ def open_thrmcpl_chans(self):
an error.
"""

val = self._interpreter.get_read_attribute_string(self._handle, 0x2a97)
buffer_size = self.get_channels_buffer_size()
val = self._interpreter.get_read_attribute_string(self._handle, 0x2a97, buffer_size)
return unflatten_channel_string(val)

@property
Expand Down Expand Up @@ -637,7 +646,8 @@ def overcurrent_chans(self):
overcurrent channels to recover.
"""

val = self._interpreter.get_read_attribute_string(self._handle, 0x29e7)
buffer_size = self.get_channels_buffer_size()
val = self._interpreter.get_read_attribute_string(self._handle, 0x29e7, buffer_size)
return unflatten_channel_string(val)

@property
Expand All @@ -662,7 +672,8 @@ def overloaded_chans(self):
Otherwise, you will receive an error.
"""

val = self._interpreter.get_read_attribute_string(self._handle, 0x2175)
buffer_size = self.get_channels_buffer_size()
val = self._interpreter.get_read_attribute_string(self._handle, 0x2175, buffer_size)
return unflatten_channel_string(val)

@property
Expand All @@ -687,7 +698,8 @@ def overtemperature_chans(self):
property. Otherwise, you will receive an error.
"""

val = self._interpreter.get_read_attribute_string(self._handle, 0x3082)
buffer_size = self.get_channels_buffer_size()
val = self._interpreter.get_read_attribute_string(self._handle, 0x3082, buffer_size)
return unflatten_channel_string(val)

@property
Expand Down Expand Up @@ -729,7 +741,8 @@ def pll_unlocked_chans(self):
List[str]: Indicates the channels that had their PLLs unlock.
"""

val = self._interpreter.get_read_attribute_string(self._handle, 0x3119)
buffer_size = self.get_channels_buffer_size()
val = self._interpreter.get_read_attribute_string(self._handle, 0x3119, buffer_size)
return unflatten_channel_string(val)

@property
Expand All @@ -753,7 +766,8 @@ def power_supply_fault_chans(self):
property. Otherwise, you will receive an error.
"""

val = self._interpreter.get_read_attribute_string(self._handle, 0x3193)
buffer_size = self.get_channels_buffer_size()
val = self._interpreter.get_read_attribute_string(self._handle, 0x3193, buffer_size)
return unflatten_channel_string(val)

@property
Expand Down Expand Up @@ -838,7 +852,8 @@ def remote_sense_error_chans(self):
receive an error.
"""

val = self._interpreter.get_read_attribute_string(self._handle, 0x31de)
buffer_size = self.get_channels_buffer_size()
val = self._interpreter.get_read_attribute_string(self._handle, 0x31de, buffer_size)
return unflatten_channel_string(val)

@property
Expand All @@ -865,7 +880,8 @@ def reverse_voltage_error_chans(self):
will receive an error.
"""

val = self._interpreter.get_read_attribute_string(self._handle, 0x31e7)
buffer_size = self.get_channels_buffer_size()
val = self._interpreter.get_read_attribute_string(self._handle, 0x31e7, buffer_size)
return unflatten_channel_string(val)

@property
Expand Down Expand Up @@ -909,7 +925,8 @@ def sync_unlocked_chans(self):
target.
"""

val = self._interpreter.get_read_attribute_string(self._handle, 0x313e)
buffer_size = self.get_channels_buffer_size()
val = self._interpreter.get_read_attribute_string(self._handle, 0x313e, buffer_size)
return unflatten_channel_string(val)

@property
Expand Down Expand Up @@ -955,6 +972,11 @@ def wait_mode(self, val):
def wait_mode(self):
self._interpreter.reset_read_attribute(self._handle, 0x2232)

def get_channels_buffer_size(self):
channel_names = self._task.channel_names
total_size = sum(len(name) + 2 for name in channel_names) + 1
return total_size

def _calculate_num_samps_per_chan(self, num_samps_per_chan):
if num_samps_per_chan == -1:
acq_type = self._task.timing.samp_quant_samp_mode
Expand Down
30 changes: 21 additions & 9 deletions generated/nidaqmx/_task_modules/out_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from nidaqmx.constants import (
RegenerationMode, ResolutionType, WaitMode, WriteRelativeTo)


class OutStream:
"""
Exposes an output data stream on a DAQmx task.
Expand Down Expand Up @@ -116,7 +115,8 @@ def devs_with_inserted_or_removed_accessories(self):
an error.
"""

val = self._interpreter.get_write_attribute_string(self._handle, 0x3054)
buffer_size = self.get_channels_buffer_size()
val = self._interpreter.get_write_attribute_string(self._handle, 0x3054, buffer_size)
return unflatten_channel_string(val)

@property
Expand All @@ -142,7 +142,8 @@ def external_overvoltage_chans(self):
an error.
"""

val = self._interpreter.get_write_attribute_string(self._handle, 0x30bc)
buffer_size = self.get_channels_buffer_size()
val = self._interpreter.get_write_attribute_string(self._handle, 0x30bc, buffer_size)
return unflatten_channel_string(val)

@property
Expand Down Expand Up @@ -198,7 +199,8 @@ def open_current_loop_chans(self):
error.
"""

val = self._interpreter.get_write_attribute_string(self._handle, 0x29eb)
buffer_size = self.get_channels_buffer_size()
val = self._interpreter.get_write_attribute_string(self._handle, 0x29eb, buffer_size)
return unflatten_channel_string(val)

@property
Expand Down Expand Up @@ -265,7 +267,8 @@ def overcurrent_chans(self):
error.
"""

val = self._interpreter.get_write_attribute_string(self._handle, 0x29e9)
buffer_size = self.get_channels_buffer_size()
val = self._interpreter.get_write_attribute_string(self._handle, 0x29e9, buffer_size)
return unflatten_channel_string(val)

@property
Expand All @@ -290,7 +293,8 @@ def overloaded_chans(self):
Otherwise, you will receive an error.
"""

val = self._interpreter.get_write_attribute_string(self._handle, 0x3085)
buffer_size = self.get_channels_buffer_size()
val = self._interpreter.get_write_attribute_string(self._handle, 0x3085, buffer_size)
return unflatten_channel_string(val)

@property
Expand All @@ -317,7 +321,8 @@ def overtemperature_chans(self):
of the overtemperature.
"""

val = self._interpreter.get_write_attribute_string(self._handle, 0x3083)
buffer_size = self.get_channels_buffer_size()
val = self._interpreter.get_write_attribute_string(self._handle, 0x3083, buffer_size)
return unflatten_channel_string(val)

@property
Expand All @@ -343,7 +348,8 @@ def power_supply_fault_chans(self):
property. Otherwise, you will receive an error.
"""

val = self._interpreter.get_write_attribute_string(self._handle, 0x29ed)
buffer_size = self.get_channels_buffer_size()
val = self._interpreter.get_write_attribute_string(self._handle, 0x29ed, buffer_size)
return unflatten_channel_string(val)

@property
Expand Down Expand Up @@ -446,7 +452,8 @@ def sync_unlocked_chans(self):
target.
"""

val = self._interpreter.get_write_attribute_string(self._handle, 0x3140)
buffer_size = self.get_channels_buffer_size()
val = self._interpreter.get_write_attribute_string(self._handle, 0x3140, buffer_size)
return unflatten_channel_string(val)

@property
Expand Down Expand Up @@ -563,3 +570,8 @@ def write(self, numpy_array):
return self._interpreter.write_raw(
self._handle, number_of_samples_per_channel,
self.auto_start, self.timeout, numpy_array)

def get_channels_buffer_size(self):
channel_names = self._task.channel_names
total_size = sum(len(name) + 2 for name in channel_names) + 1
return total_size
3 changes: 3 additions & 0 deletions src/codegen/templates/_base_interpreter.py.mako
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
get_interpreter_functions,
get_interpreter_parameter_signature,
get_params_for_function_signature,
INCLUDE_SIZE_HINT_FUNCTIONS
)
from codegen.utilities.function_helpers import order_function_parameters_by_optional
from codegen.utilities.text_wrappers import wrap, docstring_wrap
Expand Down Expand Up @@ -38,6 +39,8 @@ class BaseInterpreter(abc.ABC):
params = get_params_for_function_signature(func)
sorted_params = order_function_parameters_by_optional(params)
parameter_signature = get_interpreter_parameter_signature(is_python_factory, sorted_params)
if func.function_name in INCLUDE_SIZE_HINT_FUNCTIONS:
parameter_signature = ", ".join([parameter_signature, "size_hint=0"])
%>\
@abc.abstractmethod
%if (len(func.function_name) + len(parameter_signature)) > 68:
Expand Down
3 changes: 3 additions & 0 deletions src/codegen/templates/_grpc_interpreter.py.mako
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
get_response_parameters,
is_event_register_function,
GRPC_INTERPRETER_IGNORED_FUNCTIONS,
INCLUDE_SIZE_HINT_FUNCTIONS,
)
from codegen.utilities.function_helpers import order_function_parameters_by_optional
from codegen.utilities.text_wrappers import wrap, docstring_wrap
Expand Down Expand Up @@ -190,6 +191,8 @@ class GrpcStubInterpreter(BaseInterpreter):
params = get_params_for_function_signature(func)
sorted_params = order_function_parameters_by_optional(params)
parameter_signature = get_interpreter_parameter_signature(is_python_factory, sorted_params)
if func.function_name in INCLUDE_SIZE_HINT_FUNCTIONS:
parameter_signature = ", ".join([parameter_signature, "size_hint=0"])
output_parameters = get_output_params(func)
%>\
%if (len(func.function_name) + len(parameter_signature)) > 68:
Expand Down
Loading

0 comments on commit 91cea8e

Please sign in to comment.