Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add additional metadata to NIDAQmx errors #918

Merged
merged 13 commits into from
May 18, 2023
64 changes: 32 additions & 32 deletions generated/nidaqmx/nidaqmx_service.cpp

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions generated/nidaqmx/nidaqmx_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,8 @@ class NiDAQmxService final : public NiDAQmx::WithCallbackMethod_RegisterSignalEv
NiDAQmxLibraryInterface* library_;
ResourceRepositorySharedPtr session_repository_;
::grpc::Status ConvertApiErrorStatusForTaskHandle(::grpc::ServerContext* context, int32_t status, TaskHandle task);
::grpc::Status ConvertApiErrorStatusWithReadParametersForTaskHandle(::grpc::ServerContext* context, int32_t status, int32_t samps_per_chan_read, TaskHandle task);
::grpc::Status ConvertApiErrorStatusWithWriteParametersForTaskHandle(::grpc::ServerContext* context, int32_t status, int32_t samps_per_chan_written, TaskHandle task);
Sakthi-SM marked this conversation as resolved.
Show resolved Hide resolved

NiDAQmxFeatureToggles feature_toggles_;
};
Expand Down
18 changes: 18 additions & 0 deletions source/codegen/common_helpers.py
Sakthi-SM marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@
PascalTokenSubstitution("Uint", "UInt")
]

READ_ERROR_PARAMETERS = [
"samps_read", "samps_per_chan_read"
]

WRITE_ERROR_PARAMETERS = [
"samps_per_chan_written", "num_samps_per_chan", "num_samps_per_chan_written"
]


def is_output_parameter(parameter):
"""Whether the parameter is an output parameter."""
Expand Down Expand Up @@ -1186,3 +1194,13 @@ def get_params_needing_initialization(parameters: List[dict]) -> List[dict]:
* Outputs that are calculated/populated after the API call.
"""
return [p for p in parameters if not (is_return_value(p) or is_get_last_error_output_param(p))]


def get_parameter_for_error_generation(params, is_read_method):
for param in params:
if param["direction"] == "out":
if is_read_method and _camel_to_snake(param["name"]) in READ_ERROR_PARAMETERS:
return _camel_to_snake(param["name"])
elif not is_read_method and _camel_to_snake(param["name"]) in WRITE_ERROR_PARAMETERS:
return _camel_to_snake(param["name"])
return None
12 changes: 10 additions & 2 deletions source/codegen/metadata/nidaqmx/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
from .functions import functions
from .functions_addon import functions_validation_suppressions
from .functions_addon import functions_validation_suppressions, functions_override_metadata
from .attributes import attributes
from .enums import enums
from .enums_addon import enums_validation_suppressions
from .config import config

copy_functions = functions.copy()
def update_functions():
for function_name, function_data in functions_override_metadata.items():
copy_functions[function_name] = {**copy_functions[function_name], **functions_override_metadata[function_name]}
return copy_functions

all_functions = update_functions()

metadata = {
"functions" : functions,
"functions" : all_functions,
"functions_validation_suppressions": functions_validation_suppressions,
"attributes" : attributes,
"enums" : enums,
Expand Down
135 changes: 135 additions & 0 deletions source/codegen/metadata/nidaqmx/functions_addon.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,139 @@
functions_override_metadata = {
'ReadAnalogF64': {
'python_codegen_method': 'CustomCode_Read',
},
'ReadAnalogScalarF64': {
'python_codegen_method': 'CustomCode_Read_Scalar',
},
Sakthi-SM marked this conversation as resolved.
Show resolved Hide resolved
'ReadBinaryI16': {
'python_codegen_method': 'CustomCode_Read',
},
'ReadBinaryI32': {
'python_codegen_method': 'CustomCode_Read',
},
'ReadBinaryU16': {
'python_codegen_method': 'CustomCode_Read',
},
'ReadBinaryU32': {
'python_codegen_method': 'CustomCode_Read',
},
'ReadCounterF64': {
'python_codegen_method': 'CustomCode_Read',
},
'ReadCounterF64Ex': {
'python_codegen_method': 'CustomCode_Read',
},
'ReadCounterScalarF64': {
'python_codegen_method': 'CustomCode_Read_Scalar',
},
'ReadCounterScalarU32': {
'python_codegen_method': 'CustomCode_Read_Scalar',
},
'ReadCounterU32': {
'python_codegen_method': 'CustomCode_Read',
},
'ReadCounterU32Ex': {
'python_codegen_method': 'CustomCode_Read',
},
'ReadCtrFreq': {
'python_codegen_method': 'CustomCode_Read',
},
'ReadCtrFreqScalar': {
'python_codegen_method': 'CustomCode_Read_Scalar',
},
'ReadCtrTicks': {
'python_codegen_method': 'CustomCode_Read',
},
'ReadCtrTicksScalar': {
'python_codegen_method': 'CustomCode_Read_Scalar',
},
'ReadCtrTime': {
'python_codegen_method': 'CustomCode_Read',
},
'ReadCtrTimeScalar': {
'python_codegen_method': 'CustomCode_Read_Scalar',
},
'ReadDigitalLines': {
'python_codegen_method': 'CustomCode_Read',
},
'ReadDigitalScalarU32': {
'python_codegen_method': 'CustomCode_Read_Scalar',
},
'ReadDigitalU16': {
'python_codegen_method': 'CustomCode_Read',
},
'ReadDigitalU32': {
'python_codegen_method': 'CustomCode_Read',
},
'ReadDigitalU8': {
'python_codegen_method': 'CustomCode_Read',
},
'ReadPowerScalarF64': {
'python_codegen_method': 'CustomCode_Read_Scalar',
},
'WriteAnalogF64': {
'python_codegen_method': 'CustomCode_Write',
},
'WriteAnalogScalarF64': {
'python_codegen_method': 'CustomCode_Write_Scalar',
},
'WriteBinaryI16': {
'python_codegen_method': 'CustomCode_Write',
},
'WriteBinaryI32': {
'python_codegen_method': 'CustomCode_Write',
},
'WriteBinaryU16': {
'python_codegen_method': 'CustomCode_Write',
},
'WriteBinaryU32': {
'python_codegen_method': 'CustomCode_Write',
},
'WriteCtrFreq': {
'python_codegen_method': 'CustomCode_Write',
},
'WriteCtrFreqScalar': {
'python_codegen_method': 'CustomCode_Write_Scalar',
},
'WriteCtrTicks': {
'python_codegen_method': 'CustomCode_Write',
},
'WriteCtrTicksScalar': {
'python_codegen_method': 'CustomCode_Write_Scalar',
},
'WriteCtrTime': {
'python_codegen_method': 'CustomCode_Write',
},
'WriteCtrTimeScalar': {
'python_codegen_method': 'CustomCode_Write_Scalar',
},
'WriteDigitalLines': {
'python_codegen_method': 'CustomCode_Write',
},
'WriteDigitalScalarU32': {
'python_codegen_method': 'CustomCode_Write_Scalar',
},
'WriteDigitalU16': {
'python_codegen_method': 'CustomCode_Write',
},
'WriteDigitalU32': {
'python_codegen_method': 'CustomCode_Write',
},
'WriteDigitalU8': {
'python_codegen_method': 'CustomCode_Write',
},
'ReadPowerBinaryI16':{
'python_codegen_method': 'CustomCode_Read',
},
'ReadPowerF64':{
'python_codegen_method': 'CustomCode_Read',
},
'ReadRaw':{
'python_codegen_method': 'CustomCode_Read',
},
'WriteRaw':{
'python_codegen_method': 'CustomCode_Write',
}
}

functions_validation_suppressions = {
Expand Down
1 change: 1 addition & 0 deletions source/codegen/metadata_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ class RULES:
Optional("adaptor_parameter"): dict,
Optional("is_python_factory"): bool,
Optional("python_description"): str,
Optional("python_codegen_method"): str,
}
)

Expand Down
4 changes: 4 additions & 0 deletions source/codegen/templates/service.h.mako
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ private:
cpp_handle_type = resource_handle_type[0].upper() + resource_handle_type[1:]
%>\
::grpc::Status ConvertApiErrorStatusFor${cpp_handle_type}(::grpc::ServerContext* context, int32_t status, ${resource_handle_type} ${config["session_handle_parameter_name"]});
% if config["c_function_prefix"] == "DAQmx":
::grpc::Status ConvertApiErrorStatusWithReadParametersFor${cpp_handle_type}(::grpc::ServerContext* context, int32_t status, int32_t samps_per_chan_read, ${resource_handle_type} ${config["session_handle_parameter_name"]});
::grpc::Status ConvertApiErrorStatusWithWriteParametersFor${cpp_handle_type}(::grpc::ServerContext* context, int32_t status, int32_t samps_per_chan_written, ${resource_handle_type} ${config["session_handle_parameter_name"]});
%endif
% endfor
% if common_helpers.has_viboolean_array_param(functions):
void Copy(const std::vector<ViBoolean>& input, google::protobuf::RepeatedField<bool>* output);
Expand Down
7 changes: 6 additions & 1 deletion source/codegen/templates/service_helpers.mako
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,7 @@ ${set_response_values(normal_outputs, init_method)}\
config = data['config']
input_parameters = [p for p in parameters if common_helpers.is_input_parameter(p)]
resource_handle_types = service_helpers.get_resource_handle_types(config)
method_type = function_data.get("python_codegen_method", None)
%>\
<%block filter="common_helpers.indent(indent_level)">\
<%
Expand All @@ -768,7 +769,11 @@ ${set_response_values(normal_outputs, init_method)}\
break
cpp_handle_type = handle_type[0].upper() + handle_type[1:]
method_call = ""
if function_data.get('exclude_from_get_last_error', False):
if method_type == "CustomCode_Read":
method_call = f'return ConvertApiErrorStatusWithReadParametersFor{cpp_handle_type}(context, status, {common_helpers.get_parameter_for_error_generation(parameters, True)}, {session});'
elif method_type == "CustomCode_Write":
method_call = f'return ConvertApiErrorStatusWithWriteParametersFor{cpp_handle_type}(context, status, {common_helpers.get_parameter_for_error_generation(parameters, False)}, {session});'
elif function_data.get('exclude_from_get_last_error', False):
method_call = f'return nidevice_grpc::ApiErrorToStatus(context, status);'
else:
method_call = f'return ConvertApiErrorStatusFor{cpp_handle_type}(context, status, {session});'
Expand Down
12 changes: 12 additions & 0 deletions source/custom/nidaqmx_service.custom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,16 @@ ::grpc::Status NiDAQmxService::ConvertApiErrorStatusForTaskHandle(::grpc::Server
return nidevice_grpc::ApiErrorAndDescriptionToStatus(context, status, description);
}

::grpc::Status NiDAQmxService::ConvertApiErrorStatusWithReadParametersForTaskHandle(::grpc::ServerContext* context, int32_t status, int32_t samps_per_chan_read , TaskHandle task)
Sakthi-SM marked this conversation as resolved.
Show resolved Hide resolved
{
context->AddTrailingMetadata("ni-samps-per-chan-read", std::to_string(samps_per_chan_read));
return ConvertApiErrorStatusForTaskHandle(context, status, task);
}

::grpc::Status NiDAQmxService::ConvertApiErrorStatusWithWriteParametersForTaskHandle(::grpc::ServerContext* context, int32_t status, int32_t samps_per_chan_written , TaskHandle task)
{
context->AddTrailingMetadata("ni-samps-per-chan-written", std::to_string(samps_per_chan_written));
return ConvertApiErrorStatusForTaskHandle(context, status, task);
}

} // namespace nidaqmx_grpc