19from pathlib
import Path
27def check_errors(rsi_object):
29 Check for errors in the given rsi_object and print any errors that are found. If the error log contains any errors (not just warnings), raises an exception with the error log as the message.
30 Returns a tuple containing a boolean indicating whether the error log contained any errors and the error log string.
32 error_string_builder =
""
33 i = rsi_object.ErrorLogCountGet()
34 while rsi_object.ErrorLogCountGet() > 0:
35 error:RapidCode.RsiError = rsi_object.ErrorLogGet()
36 error_type =
"WARNING" if error.isWarning
else "ERROR"
37 error_string_builder += f
"{error_type}: {error.text}\n"
38 if len(error_string_builder) > 0:
39 print(error_string_builder)
40 if "ERROR" in error_string_builder:
41 raise Exception(error_string_builder)
42 return "ERROR" in error_string_builder, error_string_builder
44def start_the_network(controller):
46 Attempts to start the network using the given MotionController object. If the network fails to start, it reads and prints any log messages that may be helpful in determining the cause of the problem, and then raises an RsiError exception.
48 if controller.network_state_get() != RapidCode.RSINetworkState.RSINetworkStateOPERATIONAL:
49 print(
"Starting Network..")
50 controller.network_start()
52 if controller.network_state_get() != RapidCode.RSINetworkState.RSINetworkStateOPERATIONAL:
53 messages_to_read = controller.network_log_message_count_get()
55 for i
in range(messages_to_read):
56 print(controller.network_log_message_get(i))
57 print(
"Expected OPERATIONAL state but the network did not get there.")
60 print(
"Network Started")
62def find_rapid_code_directory(start_directory=os.path.dirname(os.path.abspath(__file__))):
64 Attempts find the install directory of RapidCode.
66 start_path=Path(start_directory)
67 likely_rapidcode_path_1 = start_path
68 likely_rapidcode_path_2 = start_path.parent.parent.absolute()
69 likely_rapidcode_path_3 = start_path.parent.parent.parent.absolute() /
"Release"
70 likely_rapidcode_path_4 = start_path.parent.parent.absolute()
75 file_name =
"RapidCode.py"
76 if file_name
in os.listdir(likely_rapidcode_path_1):
77 rapidcode_dir = likely_rapidcode_path_1
78 elif(file_name
in os.listdir(likely_rapidcode_path_2)):
79 rapidcode_dir=likely_rapidcode_path_2
80 elif(file_name
in os.listdir(likely_rapidcode_path_3)):
81 rapidcode_dir=likely_rapidcode_path_3
82 elif(file_name
in os.listdir(likely_rapidcode_path_4)):
83 rapidcode_dir=likely_rapidcode_path_4
85 raise Exception(
"RapidCode search path exhausted.")
87 raise Exception(
"Could not find RapidCode Directory. Try entering the path manually likely C:/RSI/X.X.X")
89 return str(rapidcode_dir)