static void Main(string[] args) { // Constants const int AXIS_NUMBER = 0; // Specify which axis/motor to control. // Initialize RapidCode Objects MotionController controller = MotionController.CreateFromSoftware(/*@"C:\RSI\X.X.X\"*/); // Insert the path location of the RMP.rta (usually the RapidSetup folder) SampleAppsCS.HelperFunctions.CheckErrors(controller); // [Helper Function] Check that the controller has been initialized correctly. SampleAppsCS.HelperFunctions.StartTheNetwork(controller); // [Helper Function] Initialize the network. Axis axis = controller.AxisGet(AXIS_NUMBER); // Initialize the axis. SampleAppsCS.HelperFunctions.CheckErrors(axis); // [Helper Function] Check that the axis has been initialized correctly. try { // CHECK AXIS STATE RSIState state = axis.StateGet(); // StateGet will return RSIState enum name of the current state of the Axis or MultiAxis. (Ex: RSIStateERROR) RSISource source; // Declare a RSISource variable. switch (state) { case RSIState.RSIStateIDLE: case RSIState.RSIStateMOVING: PrintState(state); break; case RSIState.RSIStateERROR: case RSIState.RSIStateSTOPPING_ERROR: case RSIState.RSIStateSTOPPED: case RSIState.RSIStateSTOPPING: source = axis.SourceGet(); // SourceGet will return the RSISource enum name of the first status bit that is active. (Ex: RSISourceAMP_FAULT) PrintState(state); PrintSource(axis, source); break; default: Console.WriteLine(""); break; } // or USE STATUS BIT GET bool isAmpFault_Active = axis.StatusBitGet(RSIEventType.RSIEventTypeAMP_FAULT); // StatusBitGet returns the state of a status bit, true or false. bool isPositionErrorLimitActive = axis.StatusBitGet(RSIEventType.RSIEventTypeLIMIT_ERROR); bool isHWNegativeLimitActive = axis.StatusBitGet(RSIEventType.RSIEventTypeLIMIT_HW_NEG); bool isHWPostiveLimitActive = axis.StatusBitGet(RSIEventType.RSIEventTypeLIMIT_HW_POS); // This can be done for all RSIEventTypes Console.WriteLine("\nPress Any Key To Exit"); // Allow time to read Console. Console.ReadKey(); } catch (Exception e) { Console.WriteLine(e.Message); // If there are any exceptions/issues this will be printed out. } }
private static void PrintState(RSIState state) { Console.WriteLine("\nYour Axis is in state: " + state); }