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 get_last_error mechanism to IVI init methods. #648

Merged
merged 8 commits into from
Apr 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion examples/nidcpower/measure-record.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ def check_for_error(vi, status):
raise Exception(error_message_response.error_message)


def check_for_initialization_error(response):
"""Raise an exception if an error was returned from Initialize."""
if response.status < 0:
raise RuntimeError(f"Error: {response.error_message or response.status}")
if response.status > 0:
sys.stderr.write(f"Warning: {response.error_message or response.status}\n")


# Create the communication channel for the remote host and create connections to the NI-DCPower and
# session services.
channel = grpc.insecure_channel(f"{SERVER_ADDRESS}:{SERVER_PORT}")
Expand All @@ -85,7 +93,7 @@ def check_for_error(vi, status):
)
)
vi = initialize_with_channels_response.vi
check_for_error(vi, initialize_with_channels_response.status)
check_for_initialization_error(initialize_with_channels_response)

# Specify when the measure unit should acquire measurements.
configure_measure_when = client.SetAttributeViInt32(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,14 @@ def check_for_error(vi, status):
raise Exception(error_message_response.error_message)


def check_for_initialization_error(response):
"""Raise an exception if an error was returned from Initialize."""
if response.status < 0:
raise RuntimeError(f"Error: {response.error_message or response.status}")
if response.status > 0:
sys.stderr.write(f"Warning: {response.error_message or response.status}\n")


try:
# Open session to NI-Digital Pattern Driver with options
init_with_options_response = nidigital_client.InitWithOptions(
Expand All @@ -119,7 +127,7 @@ def check_for_error(vi, status):
)
)
vi = init_with_options_response.vi
check_for_error(vi, init_with_options_response.status)
check_for_initialization_error(init_with_options_response)

load_pin_map_response = nidigital_client.LoadPinMap(
nidigital_types.LoadPinMapRequest(
Expand Down
10 changes: 9 additions & 1 deletion examples/nidmm/continuous-acquire-graph-multiple-points.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ def check_for_error(vi, status):
raise Exception(error_message_response.error_message)


def check_for_initialization_error(response):
"""Raise an exception if an error was returned from Initialize."""
if response.status < 0:
raise RuntimeError(f"Error: {response.error_message or response.status}")
if response.status > 0:
sys.stderr.write(f"Warning: {response.error_message or response.status}\n")


try:
# Open session to NI-DMM with options
init_with_options_response = nidmm_client.InitWithOptions(
Expand All @@ -80,7 +88,7 @@ def check_for_error(vi, status):
)
)
vi = init_with_options_response.vi
check_for_error(vi, init_with_options_response.status)
check_for_initialization_error(init_with_options_response)

# Configure measurement
config_measurement_response = nidmm_client.ConfigureMeasurementDigits(
Expand Down
10 changes: 9 additions & 1 deletion examples/nifgen/basic-arbitrary-waveform.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ def check_for_error(vi, status):
raise Exception(error_message_response.error_message)


def check_for_initialization_error(response):
"""Raise an exception if an error was returned from Initialize."""
if response.status < 0:
raise RuntimeError(f"Error: {response.error_message or response.status}")
if response.status > 0:
sys.stderr.write(f"Warning: {response.error_message or response.status}\n")


try:
# Initalize NI-FGEN session
init_with_options_resp = nifgen_client.InitWithOptions(
Expand All @@ -79,7 +87,7 @@ def check_for_error(vi, status):
)
)
vi = init_with_options_resp.vi
check_for_error(vi, init_with_options_resp.status)
check_for_initialization_error(init_with_options_resp)

# Configure channels
config_channels_resp = nifgen_client.ConfigureChannels(
Expand Down
11 changes: 10 additions & 1 deletion examples/nirfsa/getting-started-iq.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,17 @@ def raise_if_error(response):
return response


def raise_if_initialization_error(response):
"""Raise an exception if an error was returned from Initialize."""
if response.status < 0:
raise RuntimeError(f"Error: {response.error_message or response.status}")
if response.status > 0:
sys.stderr.write(f"Warning: {response.error_message or response.status}\n")
return response


try:
init_response = raise_if_error(
init_response = raise_if_initialization_error(
client.InitWithOptions(
nirfsa_types.InitWithOptionsRequest(
session_name=SESSION_NAME, resource_name=RESOURCE, option_string=OPTIONS
Expand Down
11 changes: 10 additions & 1 deletion examples/nirfsa/getting-started-spectrum.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,17 @@ def raise_if_error(response):
return response


def raise_if_initialization_error(response):
"""Raise an exception if an error was returned from Initialize."""
if response.status < 0:
raise RuntimeError(f"Error: {response.error_message or response.status}")
if response.status > 0:
sys.stderr.write(f"Warning: {response.error_message or response.status}\n")
return response


try:
init_response = raise_if_error(
init_response = raise_if_initialization_error(
client.InitWithOptions(
nirfsa_types.InitWithOptionsRequest(
session_name=SESSION_NAME, resource_name=RESOURCE, option_string=OPTIONS
Expand Down
11 changes: 10 additions & 1 deletion examples/nirfsg/getting-started-single-tone-generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,22 @@ def raise_if_error(response):
raise Exception(f"Error: {response.error_string}")


def raise_if_initialization_error(response):
"""Raise an exception if an error was returned from Initialize."""
if response.status < 0:
raise RuntimeError(f"Error: {response.error_message or response.status}")
if response.status > 0:
sys.stderr.write(f"Warning: {response.error_message or response.status}\n")
return response


try:
response = client.InitWithOptions(
nirfsg_types.InitWithOptionsRequest(
session_name=SESSION_NAME, resource_name=RESOURCE, option_string=OPTIONS
)
)
raise_if_error(response)
raise_if_initialization_error(response)
vi = response.vi
raise_if_error(
client.ConfigureRF(nirfsg_types.ConfigureRFRequest(vi=vi, frequency=1e9, power_level=-5))
Expand Down
11 changes: 10 additions & 1 deletion examples/nirfsg/reference-clock.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,22 @@ def raise_if_error(response):
raise Exception(f"Error: {response.error_string}")


def raise_if_initialization_error(response):
"""Raise an exception if an error was returned from Initialize."""
if response.status < 0:
raise RuntimeError(f"Error: {response.error_message or response.status}")
if response.status > 0:
sys.stderr.write(f"Warning: {response.error_message or response.status}\n")
return response


try:
response = client.InitWithOptions(
nirfsg_types.InitWithOptionsRequest(
session_name=SESSION_NAME, resource_name=RESOURCE, option_string=OPTIONS
)
)
raise_if_error(response)
raise_if_initialization_error(response)
vi = response.vi
raise_if_error(
client.ConfigureRF(nirfsg_types.ConfigureRFRequest(vi=vi, frequency=1e9, power_level=-5))
Expand Down
10 changes: 9 additions & 1 deletion examples/niscope/fetch-continuous.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ def check_for_error(vi, status):
raise Exception(error_message_response.error_message)


def check_for_initialization_error(response):
"""Raise an exception if an error was returned from Initialize."""
if response.status < 0:
raise RuntimeError(f"Error: {response.error_message or response.status}")
if response.status > 0:
sys.stderr.write(f"Warning: {response.error_message or response.status}\n")


try:
# Open session to NI-SCOPE module with options.
init_with_options_response = client.InitWithOptions(
Expand All @@ -79,7 +87,7 @@ def check_for_error(vi, status):
)
)
vi = init_with_options_response.vi
check_for_error(vi, init_with_options_response.status)
check_for_initialization_error(init_with_options_response)

# Configure vertical.
voltage = 10.0
Expand Down
10 changes: 9 additions & 1 deletion examples/niscope/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ def check_for_error(vi, status):
raise Exception(error_message_response.error_message)


def check_for_initialization_error(response):
"""Raise an exception if an error was returned from Initialize."""
if response.status < 0:
raise RuntimeError(f"Error: {response.error_message or response.status}")
if response.status > 0:
sys.stderr.write(f"Warning: {response.error_message or response.status}\n")


try:
# Open session to NI-SCOPE module with options.
init_with_options_response = client.InitWithOptions(
Expand All @@ -76,7 +84,7 @@ def check_for_error(vi, status):
)
)
vi = init_with_options_response.vi
check_for_error(vi, init_with_options_response.status)
check_for_initialization_error(init_with_options_response)

# Configure vertical.
voltage = 10.0
Expand Down
10 changes: 9 additions & 1 deletion examples/niscope/graph-measurement.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ def check_for_error(vi, status):
raise Exception(error_message_response.error_message)


def check_for_initialization_error(response):
"""Raise an exception if an error was returned from Initialize."""
if response.status < 0:
raise RuntimeError(f"Error: {response.error_message or response.status}")
if response.status > 0:
sys.stderr.write(f"Warning: {response.error_message or response.status}\n")


# Create the communication channel for the remote host (in this case we are connecting to a local
# server) and create a connection to the NI-SCOPE service
channel = grpc.insecure_channel(f"{SERVER_ADDRESS}:{SERVER_PORT}")
Expand All @@ -80,7 +88,7 @@ def check_for_error(vi, status):
)
)
vi = init_result.vi
check_for_error(vi, init_result.status)
check_for_initialization_error(init_result)

# Configure Vertical
vertical_result = niscope_client.ConfigureVertical(
Expand Down
10 changes: 9 additions & 1 deletion examples/niscope/plot-read-waveform.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ def check_for_error(vi, status):
raise Exception(error_message_response.error_message)


def check_for_initialization_error(response):
"""Raise an exception if an error was returned from Initialize."""
if response.status < 0:
raise RuntimeError(f"Error: {response.error_message or response.status}")
if response.status > 0:
sys.stderr.write(f"Warning: {response.error_message or response.status}\n")


# Create the communcation channel for the remote host (in this case we are connecting to a local
# server) and create a connection to the niScope service
channel = grpc.insecure_channel(f"{SERVER_ADDRESS}:{SERVER_PORT}")
Expand All @@ -76,7 +84,7 @@ def check_for_error(vi, status):
)
)
vi = init_result.vi
check_for_error(vi, init_result.status)
check_for_initialization_error(init_result)

# Configure horizontal timing
config_result = niscope_client.ConfigureHorizontalTiming(
Expand Down
10 changes: 9 additions & 1 deletion examples/niswitch/controlling-an-individual-relay.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ def check_for_error(vi, status):
raise Exception(error_message_response.error_message)


def check_for_initialization_error(response):
"""Raise an exception if an error was returned from Initialize."""
if response.status < 0:
raise RuntimeError(f"Error: {response.error_message or response.status}")
if response.status > 0:
sys.stderr.write(f"Warning: {response.error_message or response.status}\n")


try:
# Open session to NI-SWITCH and set topology.
init_with_topology_response = niswitch_client.InitWithTopology(
Expand All @@ -82,7 +90,7 @@ def check_for_error(vi, status):
)
)
vi = init_with_topology_response.vi
check_for_error(vi, init_with_topology_response.status)
check_for_initialization_error(init_with_topology_response)
print("Topology set to : ", TOPOLOGY_STRING)

# Close the relay. Use values that are valid for the model being used.
Expand Down
10 changes: 9 additions & 1 deletion examples/niswitch/software-scanning.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ def check_for_error(vi, status):
raise Exception(error_message_response.error_message)


def check_for_initialization_error(response):
"""Raise an exception if an error was returned from Initialize."""
if response.status < 0:
raise RuntimeError(f"Error: {response.error_message or response.status}")
if response.status > 0:
sys.stderr.write(f"Warning: {response.error_message or response.status}\n")


try:
# Open session to NI-SWITCH and set topology.
init_with_topology_response = niswitch_client.InitWithTopology(
Expand All @@ -83,7 +91,7 @@ def check_for_error(vi, status):
)
)
vi = init_with_topology_response.vi
check_for_error(vi, init_with_topology_response.status)
check_for_initialization_error(init_with_topology_response)
print("Topology set to : ", TOPOLOGY_STRING)

# Configure the scan list.
Expand Down
2 changes: 2 additions & 0 deletions generated/nidcpower/nidcpower.proto
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,7 @@ message InitializeWithIndependentChannelsRequest {
message InitializeWithIndependentChannelsResponse {
int32 status = 1;
nidevice_grpc.Session vi = 2;
string error_message = 3;
}

message InitiateWithChannelsRequest {
Expand Down Expand Up @@ -1592,6 +1593,7 @@ message InitializeWithChannelsRequest {
message InitializeWithChannelsResponse {
int32 status = 1;
nidevice_grpc.Session vi = 2;
string error_message = 3;
}

message InitiateRequest {
Expand Down
9 changes: 9 additions & 0 deletions generated/nidcpower/nidcpower_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <iostream>
#include <atomic>
#include <vector>
#include "custom/ivi_errors.h"
#include <server/converters.h>

namespace nidcpower_grpc {
Expand Down Expand Up @@ -781,6 +782,10 @@ namespace nidcpower_grpc {
if (status_ok(status)) {
response->mutable_vi()->set_id(session_id);
}
else {
const auto error_message = get_last_error_message(library_);
response->set_error_message(error_message);
}
return ::grpc::Status::OK;
}
catch (nidevice_grpc::LibraryLoadException& ex) {
Expand Down Expand Up @@ -2866,6 +2871,10 @@ namespace nidcpower_grpc {
if (status_ok(status)) {
response->mutable_vi()->set_id(session_id);
}
else {
const auto error_message = get_last_error_message(library_);
response->set_error_message(error_message);
}
return ::grpc::Status::OK;
}
catch (nidevice_grpc::LibraryLoadException& ex) {
Expand Down
2 changes: 2 additions & 0 deletions generated/nidigitalpattern/nidigitalpattern.proto
Original file line number Diff line number Diff line change
Expand Up @@ -1324,6 +1324,7 @@ message InitRequest {
message InitResponse {
int32 status = 1;
nidevice_grpc.Session vi = 2;
string error_message = 3;
}

message InitWithOptionsRequest {
Expand All @@ -1337,6 +1338,7 @@ message InitWithOptionsRequest {
message InitWithOptionsResponse {
int32 status = 1;
nidevice_grpc.Session vi = 2;
string error_message = 3;
}

message InitiateRequest {
Expand Down
Loading