APIs, concepts, guides, and more
error-logs.cs
/* 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");
// get rmp objects
try
{
Helpers.CheckErrors(controller);
Axis axis = controller.AxisGet(axisNumber: 0);
// 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
}
// handle errors as needed
finally
{
controller.Delete(); // dispose
}
static void AbortMotionObject(RapidCodeMotion motionObject)
Aborts motion on the given RapidCodeMotion object (Axis or MultiAxis), waits for motion to stop,...
Definition _helpers.cs:186
static void CheckErrors(RapidCodeObject rsiObject)
Checks for errors in the given RapidCodeObject and throws an exception if any non-warning errors are ...
Definition _helpers.cs:15
Helpers class provides static methods for common tasks in RMP applications.
Definition _helpers.cs:5
void MoveVelocity(double velocity)
Represents a single axis of motion control. This class provides an interface for commanding motion,...
Definition rsi.h:5862
Axis * AxisGet(int32_t axisNumber)
AxisGet returns a pointer to an Axis object and initializes its internals.
void RecorderStart()
Start recording data.
static MotionController * Get()
Get an already running RMP EtherCAT controller.
void Delete(void)
Delete the MotionController and all its objects.
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