APIs, concepts, guides, and more
Error Logging

Utilize error logging to record and trace errors in RMP objects, aiding in debugging and ensuring efficient problem resolution during code execution.

🔹 What is Error Logging?

Error logs record RSIObjects errors that occur during the execution of code so you can target problems when debugging.

🔹 Error Logging Overview

All RSIObjects have error logs. This utility helps to trace errors when a program fails and aids in debugging.

Observe the below sample code to learn how to catch and display error logs.

📜 Sample Code

  • C#

    /* This sample demonstrates how to read RsiError objects from the error log.
    It shows how to turn off exceptions, perform operations that generate errors,
    and then read and display error messages from the error log.
    */
    using RSI.RapidCode; // RSI.RapidCode.dotNET;
    Console.WriteLine("📜 Error Logs");
    int exitCode = 0;
    // get rmp objects
    try
    {
    Helpers.CheckErrors(controller);
    Helpers.VerifyHardwareUsage(controller);
    Helpers.VerifyAxisCount(controller);
    Axis axis = controller.AxisGet(axisNumber: Constants.AXIS_0_INDEX);
    Helpers.CheckErrors(axis);
    // turn exceptions off (errors will be logged as RsiError objects)
    controller.ThrowExceptions(false);
    axis.ThrowExceptions(false);
    // cause an errors
    controller.RecorderStart(); // recorder count is zero
    axis.MoveVelocity(0.0, 0.0); // zero acceleration
    // print error count
    var controllerErrorCount = controller.ErrorLogCountGet();
    var axisErrorCount = axis.ErrorLogCountGet();
    Console.WriteLine($"Controller error count: {controllerErrorCount} (expected: 1)");
    Console.WriteLine($"Axis error count: {axisErrorCount} (expected: 1)");
    // print controller errors
    while(controller.ErrorLogCountGet() > 0)
    {
    // ErrorLogGet retrieves and removes the next error from the log
    RsiError error = controller.ErrorLogGet();
    Console.WriteLine($" Controller Error: {error.Message}");
    }
    // print axis errors
    while( axis.ErrorLogCountGet() > 0)
    {
    RsiError error = axis.ErrorLogGet();
    Console.WriteLine($" Axis Error: {error.Message}");
    }
    // print error count after reading logs
    Console.WriteLine($"Controller error count: {controller.ErrorLogCountGet()} (expected: 0)");
    Console.WriteLine($"Axis error count: {axis.ErrorLogCountGet()} (expected: 0)");
    // verify error count
    if (controllerErrorCount < 1 || axisErrorCount < 1)
    throw new Exception("❌ Error log did not record expected errors.");
    // cleanup
    Helpers.AbortMotionObject(axis);
    exitCode = Constants.EXIT_SUCCESS;
    }
    // handle errors as needed
    catch (Exception e)
    {
    Console.WriteLine($"❌ Error: {e.Message}");
    exitCode = Constants.EXIT_FAILURE;
    }
    finally
    {
    controller.Delete(); // dispose
    }
    return exitCode;
    Constants used in the C# sample apps.
    Definition _constants.cs:3
    const int EXIT_FAILURE
    Exit code for failed execution.
    Definition _constants.cs:69
    const int AXIS_0_INDEX
    Default: 0.
    Definition _constants.cs:20
    const int EXIT_SUCCESS
    Exit code for successful execution.
    Definition _constants.cs:68
    void MoveVelocity(double velocity)
    Represents a single axis of motion control. This class provides an interface for commanding motion,...
    Definition rsi.h:5921
    static MotionController * Get()
    Get an already running RMP EtherCAT controller.
    Represents the RMP soft motion controller. This class provides an interface to general controller con...
    Definition rsi.h:800
    void ThrowExceptions(bool state)
    Configure a class to throw exceptions.
    const RsiError *const ErrorLogGet()
    Get the next RsiError in the log.
    int32_t ErrorLogCountGet()
    Get the number of software errors in the error log.
    Represents the error details thrown as an exception by all RapidCode classes. This class contains an ...
    Definition rsi.h:111
    Helpers namespace provides utility functions for common tasks in RMP applications.
    Definition helpers.h:21