1""" Helper functions for RapidCode Python samples.
4from _imports
import RapidCode, RAPIDCODE_DIR, constants, platform
6def get_creation_parameters():
9 creation_params: RapidCode.CreationParameters = RapidCode.CreationParameters()
10 creation_params.RmpPath = RAPIDCODE_DIR
11 creation_params.NicPrimary = constants.RMP_NIC_PRIMARY
13 if platform.system() ==
"Windows":
14 creation_params.NodeName = constants.RMP_NODE_NAME
15 elif platform.system() ==
"Linux":
16 creation_params.CpuAffinity = constants.RMP_CPU_AFFINITY
18 raise Exception(
"Unsupported platform")
20 return creation_params
22def check_errors(rsi_object):
26 error_string_builder =
""
27 i = rsi_object.ErrorLogCountGet()
28 while rsi_object.ErrorLogCountGet() > 0:
29 error:RapidCode.RsiError = rsi_object.ErrorLogGet()
30 error_type =
"WARNING" if error.isWarning
else "ERROR"
31 error_string_builder += f
"{error_type}: {error.text}\n"
32 if len(error_string_builder) > 0:
33 print(error_string_builder)
34 if "ERROR" in error_string_builder:
35 raise Exception(error_string_builder)
36 return "ERROR" in error_string_builder, error_string_builder
38def start_the_network(controller):
42 if controller.NetworkStateGet() != RapidCode.RSINetworkState_RSINetworkStateOPERATIONAL:
43 print(
"Starting Network..")
44 controller.NetworkStart()
46 if controller.NetworkStateGet() != RapidCode.RSINetworkState_RSINetworkStateOPERATIONAL:
47 messages_to_read = controller.NetworkLogMessageCountGet()
49 for i
in range(messages_to_read):
50 print(controller.NetworkLogMessageGet(i))
51 print(
"Expected OPERATIONAL state but the network did not get there.")
54 print(
"Network Started")