APIs, concepts, guides, and more
Helper Functions

Helper Functions for checking logged creation errors, starting the network, etc.

Warning
This is a sample program to assist in the integration of the RMP motion controller with your application. It may not contain all of the logic and safety features that your application requires. We recommend that you wire an external hardware emergency stop (e-stop) button for safety when using our code sample apps. Doing so will help ensure the safety of you and those around you and will prevent potential injury or damage.

The sample apps assume that the system (network, axes, I/O) are configured prior to running the code featured in the sample app. See the Configuration page for more information.


In this page:


📜 Helper Functions

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():
# create a motion controller and return it.
# If any errors are found, raise an exception with the error log as the message.
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):
# 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.
# returns a tuple containing a boolean indicating whether the error log contained any errors and the error log string.
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):
# 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.
if controller.NetworkStateGet() != RapidCode.RSINetworkState_RSINetworkStateOPERATIONAL: # Check if network is started already.
print("Starting Network..")
controller.NetworkStart() # If not. Initialize The Network. (This can also be done from RapidSetup Tool)
if controller.NetworkStateGet() != RapidCode.RSINetworkState_RSINetworkStateOPERATIONAL: # Check if network is started again.
messages_to_read = controller.NetworkLogMessageCountGet() # Some kind of error starting the network, read the network log messages
for i in range(messages_to_read):
print(controller.NetworkLogMessageGet(i)) # Print all the messages to help figure out the problem
print("Expected OPERATIONAL state but the network did not get there.")
# raise Exception(Expected OPERATIONAL state but the network did not get there.) # Uncomment if you want your application to exit when the network isn't operational. (Comment when using phantom axis)
else: # Else, of network is operational.
print("Network Started")