Helper Functions for checking logged creation errors, starting the network, etc.
Learn how to use helper functions for checking logged creation errors, starting the network, etc.
""" Helper functions for RapidCode Python samples.
"""
from _imports import RapidCode, RAPIDCODE_DIR, constants, platform
def get_creation_parameters():
creation_params: RapidCode.CreationParameters = RapidCode.CreationParameters()
creation_params.RmpPath = RAPIDCODE_DIR
creation_params.NicPrimary = constants.RMP_NIC_PRIMARY
if platform.system() == "Windows":
creation_params.NodeName = constants.RMP_NODE_NAME
elif platform.system() == "Linux":
creation_params.CpuAffinity = constants.RMP_CPU_AFFINITY
else:
raise Exception("Unsupported platform")
return creation_params
def check_errors(rsi_object):
error_string_builder = ""
i = rsi_object.ErrorLogCountGet()
while rsi_object.ErrorLogCountGet() > 0:
error:RapidCode.RsiError = rsi_object.ErrorLogGet()
error_type = "WARNING" if error.isWarning else "ERROR"
error_string_builder += f"{error_type}: {error.text}\n"
if len(error_string_builder) > 0:
print(error_string_builder)
if "ERROR" in error_string_builder:
raise Exception(error_string_builder)
return "ERROR" in error_string_builder, error_string_builder
def start_the_network(controller):
if controller.NetworkStateGet() != RapidCode.RSINetworkState_RSINetworkStateOPERATIONAL:
print("Starting Network..")
controller.NetworkStart()
if controller.NetworkStateGet() != RapidCode.RSINetworkState_RSINetworkStateOPERATIONAL:
messages_to_read = controller.NetworkLogMessageCountGet()
for i in range(messages_to_read):
print(controller.NetworkLogMessageGet(i))
print("Expected OPERATIONAL state but the network did not get there.")
else:
print("Network Started")