Skip to content

Commit

Permalink
Merge pull request #35 from ni/v0_1_7_get_set_trigger_settings
Browse files Browse the repository at this point in the history
Add functions to get and set the trigger settings in the logging specification document and support of a timeout when opening a project.
  • Loading branch information
ccaltagi committed Oct 16, 2023
2 parents 86da9f1 + 357297b commit 446fd90
Show file tree
Hide file tree
Showing 19 changed files with 1,103 additions and 14 deletions.
46 changes: 46 additions & 0 deletions examples/Basic/get_trigger_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import os
import sys

from flexlogger.automation import Application
from flexlogger.automation import StartTriggerCondition
from flexlogger.automation import StopTriggerCondition


def main(project_path):
"""Launch FlexLogger, open a project, and get the trigger settings."""
with Application.launch() as app:
project = app.open_project(path=project_path)
logging_specification = project.open_logging_specification_document()

# Get and print the start trigger settings
start_trigger_condition, start_trigger_settings = logging_specification.get_start_trigger_settings()
print("Start Trigger Condition: " + str(start_trigger_condition))
if start_trigger_condition == StartTriggerCondition.CHANNEL_VALUE_CHANGE:
print("Channel Value Change Condition :")
print(start_trigger_settings)
elif start_trigger_condition == StartTriggerCondition.ABSOLUTE_TIME:
print("Start Time: " + start_trigger_settings.strftime("%x, %X"))

# Get and print the stop trigger settings
stop_trigger_condition, stop_trigger_settings = logging_specification.get_stop_trigger_settings()
print("Stop Trigger Condition: " + str(stop_trigger_condition))
if stop_trigger_condition == StopTriggerCondition.CHANNEL_VALUE_CHANGE:
print("Channel Value Change Condition :")
print(stop_trigger_settings)
elif stop_trigger_condition == StopTriggerCondition.TEST_TIME_ELAPSED:
print("Time Elapsed: " + stop_trigger_settings)

print("Press Enter to close the project...")
input()
project.close()

return 0


if __name__ == "__main__":
argv = sys.argv
if len(argv) < 2:
print("Usage: %s <path of project to open>" % os.path.basename(__file__))
sys.exit()
project_path_arg = argv[1]
sys.exit(main(project_path_arg))
2 changes: 1 addition & 1 deletion examples/Basic/launch_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def main(project_path):
# goes out of scope, the application will be closed. To prevent this,
# call app.disconnect() before the scope ends.
with Application.launch() as app:
project = app.open_project(path=project_path)
project = app.open_project(path=project_path, timeout=180)
print("Press Enter to close project...")
input()
project.close()
Expand Down
36 changes: 36 additions & 0 deletions examples/Basic/set_time_trigger_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import os
import sys

from datetime import datetime
from datetime import timedelta
from flexlogger.automation import Application


def main(project_path):
"""Launch FlexLogger, open a project, and set the trigger settings."""
with Application.launch() as app:
project = app.open_project(path=project_path)
logging_specification = project.open_logging_specification_document()

# Set the start trigger settings.
# test_start_time is treated as UTC unless a timezone is explicitly specified
test_start_time = datetime.utcnow()
logging_specification.set_start_trigger_settings_to_absolute_time(test_start_time)
# Set the stop trigger settings
duration = timedelta(seconds=100)
logging_specification.set_stop_trigger_settings_to_duration(duration)

print("Press Enter to close the project...")
input()
project.close()

return 0


if __name__ == "__main__":
argv = sys.argv
if len(argv) < 2:
print("Usage: %s <path of project to open>" % os.path.basename(__file__))
sys.exit()
project_path_arg = argv[1]
sys.exit(main(project_path_arg))
44 changes: 44 additions & 0 deletions examples/Basic/set_value_change_trigger_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import os
import sys

from flexlogger.automation import Application
from flexlogger.automation import ValueChangeCondition
from flexlogger.automation import ValueChangeType


def main(project_path):
"""Launch FlexLogger, open a project, and set the trigger settings."""
with Application.launch() as app:
project = app.open_project(path=project_path)
logging_specification = project.open_logging_specification_document()

start_value_change_condition = ValueChangeCondition()
start_value_change_condition.value_change_type = ValueChangeType.ENTER_RANGE
start_value_change_condition.channel_name = 'Replace this string with the channel name to monitor.'
start_value_change_condition.min_value = 1.0
start_value_change_condition.max_value = 2.0
start_value_change_condition.time = 0.0

stop_value_change_condition = ValueChangeCondition()
stop_value_change_condition.value_change_type = ValueChangeType.FALL_BELOW_VALUE
stop_value_change_condition.channel_name = 'Replace this string with the channel name to monitor.'
stop_value_change_condition.threshold = 1.0
stop_value_change_condition.time = 0.0

logging_specification.set_start_trigger_settings_to_value_change(start_value_change_condition)
logging_specification.set_stop_trigger_settings_to_value_change(stop_value_change_condition)

print("Press Enter to close the project...")
input()
project.close()

return 0


if __name__ == "__main__":
argv = sys.argv
if len(argv) < 2:
print("Usage: %s <path of project to open>" % os.path.basename(__file__))
sys.exit()
project_path_arg = argv[1]
sys.exit(main(project_path_arg))
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@

package national_instruments.flex_logger.automation.protocols;

import "ConfigurationBasedSoftware/FlexLogger/Automation/FlexLogger.Automation.Protocols/StartTriggerCondition.proto";
import "ConfigurationBasedSoftware/FlexLogger/Automation/FlexLogger.Automation.Protocols/StopTriggerCondition.proto";
import "ConfigurationBasedSoftware/FlexLogger/Automation/FlexLogger.Automation.Protocols/ValueChangeType.proto";
import "DiagramSdk/Automation/DiagramSdk.Automation.Protocols/Identifiers.proto";
import "google/protobuf/duration.proto";
import "google/protobuf/empty.proto";
import "google/protobuf/timestamp.proto";

// Service interface for a server side logging specification document.
service LoggingSpecificationDocument {
Expand Down Expand Up @@ -33,6 +38,26 @@ service LoggingSpecificationDocument {
rpc GetResolvedLogFileBasePath(GetResolvedLogFileBasePathRequest) returns (GetResolvedLogFileBasePathResponse) {}
// RPC call to get the resolved log file name
rpc GetResolvedLogFileName(GetResolvedLogFileNameRequest) returns (GetResolvedLogFileNameResponse) {}
// RPC call to get the start trigger settings
rpc GetStartTriggerSettings(GetStartTriggerSettingsRequest) returns (GetStartTriggerSettingsResponse) {}
// RPC call to get the stop trigger settings
rpc GetStopTriggerSettings(GetStopTriggerSettingsRequest) returns (GetStopTriggerSettingsResponse) {}
// RPC call to set the start trigger settings to Test Start
rpc SetTestStartTriggerSettings(SetTestStartTriggerSettingsRequest) returns (google.protobuf.Empty) {}
// RPC call to set the start trigger settings to Channel value change
rpc SetValueChangeStartTriggerSettings(SetValueChangeStartTriggerSettingsRequest) returns (google.protobuf.Empty) {}
// RPC call to set the start trigger settings to Absolute time
rpc SetTimeStartTriggerSettings(SetTimeStartTriggerSettingsRequest) returns (google.protobuf.Empty) {}
// RPC call to set the stop trigger settings to Test stop
rpc SetTestStopTriggerSettings(SetTestStopTriggerSettingsRequest) returns (google.protobuf.Empty) {}
// RPC call to set the stop trigger settings to Channel value change
rpc SetValueChangeStopTriggerSettings(SetValueChangeStopTriggerSettingsRequest) returns (google.protobuf.Empty) {}
// RPC call to set the stop trigger settings to Test time elapsed
rpc SetTimeStopTriggerSettings(SetTimeStopTriggerSettingsRequest) returns (google.protobuf.Empty) {}
// RPC call to get the retrigerring configuration
rpc IsRetriggeringEnabled(IsRetriggeringEnabledRequest) returns (IsRetriggeringEnabledResponse) {}
// RPC call to set the retrigerring configuration
rpc SetRetriggering(SetRetriggeringRequest) returns (google.protobuf.Empty) {}
}

// Request object for getting the log file base path
Expand Down Expand Up @@ -192,3 +217,114 @@ message GetResolvedLogFileNameResponse {
string resolved_log_file_name = 1;
}

// Request object for getting the start trigger settings
message GetStartTriggerSettingsRequest {
// The id for the logging specification document
national_instruments.diagram_sdk.automation.protocols.ElementIdentifier document_identifier = 1;
}

// Response object for a getting the start trigger settings
message GetStartTriggerSettingsResponse {
// The start trigger condition
StartTriggerCondition start_trigger_condition = 1;
// The start trigger settings
string start_trigger_settings = 2;
}

// Request object for getting the stop trigger settings
message GetStopTriggerSettingsRequest {
// The id for the logging specification document
national_instruments.diagram_sdk.automation.protocols.ElementIdentifier document_identifier = 1;
}

// Response object for getting the stop trigger settings
message GetStopTriggerSettingsResponse {
// The stop trigger condition
StopTriggerCondition stop_trigger_condition = 1;
// The stop trigger settings
string stop_trigger_settings = 2;
}

// Request object for SetTestStartTriggerSettings
message SetTestStartTriggerSettingsRequest {
// The id for the logging specification document
national_instruments.diagram_sdk.automation.protocols.ElementIdentifier document_identifier = 1;
}

// Request object for SetValueChangeStartTriggerSettings
message SetValueChangeStartTriggerSettingsRequest {
// The id for the logging specification document
national_instruments.diagram_sdk.automation.protocols.ElementIdentifier document_identifier = 1;
// The channel name
string channel_name = 2;
// The value change condition
ValueChangeType value_change_type = 3;
// The threshold
double threshold = 4;
// The min value
double min_value = 5;
// The max value
double max_value = 6;
// The leading time to include in seconds
double leading_time = 7;
}

// Request object for SetTimeStartTriggerSettings
message SetTimeStartTriggerSettingsRequest {
// The id for the logging specification document
national_instruments.diagram_sdk.automation.protocols.ElementIdentifier document_identifier = 1;
// The time to start the test
google.protobuf.Timestamp time = 2;
}

// Request object for SetTestStopTriggerSettings
message SetTestStopTriggerSettingsRequest {
// The id for the logging specification document
national_instruments.diagram_sdk.automation.protocols.ElementIdentifier document_identifier = 1;
}

// Request object for SetValueChangeStopTriggerSettings
message SetValueChangeStopTriggerSettingsRequest {
// The id for the logging specification document
national_instruments.diagram_sdk.automation.protocols.ElementIdentifier document_identifier = 1;
// The channel name
string channel_name = 2;
// The value change condition
ValueChangeType value_change_type = 3;
// The threshold
double threshold = 4;
// The min value
double min_value = 5;
// The max value
double max_value = 6;
// The leading time to include in seconds
double trailing_time = 7;
}

// Request object for SetTimeStopTriggerSettings
message SetTimeStopTriggerSettingsRequest {
// The id for the logging specification document
national_instruments.diagram_sdk.automation.protocols.ElementIdentifier document_identifier = 1;
// The duration
google.protobuf.Duration duration = 2;
}

// Request object for IsRetriggeringEnabled
message IsRetriggeringEnabledRequest {
// The id for the logging specification document
national_instruments.diagram_sdk.automation.protocols.ElementIdentifier document_identifier = 1;
}

// Response object for IsRetriggeringEnabled
message IsRetriggeringEnabledResponse {
// The retriggering configuration
bool is_retriggering_enabled = 1;
}

// Request object for SetRetriggering
message SetRetriggeringRequest {
// The id for the logging specification document
national_instruments.diagram_sdk.automation.protocols.ElementIdentifier document_identifier = 1;
// The triggering configuration
bool is_retriggering_enabled = 2;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
syntax = "proto3";

package national_instruments.flex_logger.automation.protocols;

enum StartTriggerCondition {
START_TRIGGER_CONDITION_TEST_START = 0;
START_TRIGGER_CONDITION_CHANNEL_VALUE_CHANGE = 1;
START_TRIGGER_CONDITION_TIME = 2;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
syntax = "proto3";

package national_instruments.flex_logger.automation.protocols;

enum StopTriggerCondition {
STOP_TRIGGER_CONDITION_TEST_STOP = 0;
STOP_TRIGGER_CONDITION_CHANNEL_VALUE_CHANGE = 1;
STOP_TRIGGER_CONDITION_TIME_ELAPSED = 2;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
syntax = "proto3";

package national_instruments.flex_logger.automation.protocols;

enum ValueChangeType {
TYPE_NONE = 0;
TYPE_RISE_ABOVE_VALUE = 1;
TYPE_RISE_ABOVE_VALUE_INCLUSIVE = 2;
TYPE_FALL_BELOW_VALUE = 3;
TYPE_FALL_BELOW_VALUE_INCLUSIVE = 4;
TYPE_ENTER_RANGE = 5;
TYPE_LEAVE_RANGE = 6;
}
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ grpcio
importlib
prettytable
psutil
python-dateutil
# This package only works correctly on Windows,
# but add this specifier to allow installing it on
# Linux, which is helpful for pypi builds and readthedocs.
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def _get_version(name: str) -> str:
script_dir = os.path.dirname(os.path.realpath(__file__))
script_dir = os.path.join(script_dir, name)
if not os.path.exists(os.path.join(script_dir, "VERSION")):
version = "0.1.6"
version = "0.1.7"
else:
with open(os.path.join(script_dir, "VERSION"), "r") as version_file:
version = version_file.read().rstrip()
Expand Down Expand Up @@ -99,6 +99,7 @@ def _build_protobuf_paths() -> List[str]:
"pywin32; platform_system=='Windows'",
"console-menu",
"PrettyTable",
"python-dateutil",
],
setup_requires=["grpcio", "grpcio-tools"],
tests_require=["pytest", "mypy", "npTDMS", "pytest-timeout", "psutil"],
Expand Down
4 changes: 4 additions & 0 deletions src/flexlogger/automation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@
from ._event_type import EventType
from ._events import FlexLoggerEventHandler
from ._severity_level import SeverityLevel
from ._start_trigger_condition import StartTriggerCondition
from ._stop_trigger_condition import StopTriggerCondition
from ._value_change_condition import ValueChangeCondition
from ._value_change_type import ValueChangeType

0 comments on commit 446fd90

Please sign in to comment.