3. Add Sample App to Your Project

You should only continue if you have successfully created a C#/C++ Project

What files do I need to setup my C# project?

➡️ 32-bit

RapidCode.NET.dll → [32bit] - .NET Framework 4.5 DLL

RSI.System.dll → [32bit] - (only if using the Axis XML API)

❗ NOTE
 is not needed, but some users might want to save Axis configurations that are not stored in the motion controller such as user units. 

➡️ 64-bit

RapidCode64.NET.dll → [64bit] - .NET Framework 4.5 DLL

RSI.System64.dll → [64bit] - (only if using the Axis XML API)

❗ NOTE
 is not needed, but some users might want to save Axis configurations that are not stored in the motion controller such as user units. 

What files do I need to setup my C++ project?

➡️ 32-bit

rsi.h → Primary Header file.

RapidCode.lib → [32bit] - Import Library.

RapidCode.dll → [32bit] - C++ dll.

➡️ 64-bit

rsi.h → Primary Header file.

RapidCode64.lib → [64bit] - Import Library.

RapidCode64.dll → [64bit] - C++ dll.

Steps to Add a RapidCode API Sample App

C# Project for RapidCode 10.x.x

1. In Solution Explorer (open on View Tab or hit ctrl+alt+L) right click on the name of your project, then click on Add, then click on Class for the Visual C# Items section.

2. Change the Name of your class to the name of the Sample App that you want to use and hit Add.

For example, if you would like to use our Absolute Motion sample app, then the name of your class will be AbsoluteMotion.cs.

2.1 After you click Add, you should be seeing something like this:

3. Add the RapidCode.NET.dll as a reference to your project.

3.1 On the top menu click on Project, then click on Add Reference…

3.2 Once the Reference Manager window opens, browse for the RapidCode.NET.dll file in your RapidSetup Folder, and click OK. (Make sure the checkbox is checked)

3.3 Verify that the RapidCode.NET.dll library has been added to your References.

4. Select your platform

32 bit --- RapidCode.NET.dll --- x86

64bit --- RapidCode64.NET.dll --- x64

4.1 Open the platform Configuration Manager

4.2 Select the appropriate platform. If not available select <New...>

5. Set the working directory

5.1 Go to the Debug section of the project properties and select all configurations. Set the platform to match that of your .dll file. Set the working directory to the location you installed RMP.

5.2 Set build path:

6. Replace the contents of AbsoluteMotion.cs with the following code.

using System;
using RSI.RapidCode.dotNET;         // Import our RapidCode Library.
namespace SampleAppsCS
{
    class AbsoluteMotion
    {
        static void Main(string[] args)
        {
            // RapidCode Objects
            MotionController controller;                // Declare what controller is.
            Axis axis;                                  // Declare waht axis is.
            
            // Constants
            const int AXIS_NUMBER       = 0;            // Specify which axis/motor to control.
            const int POSITION          = 10;           // Specify the position to travel to.
            const int USER_UNITS        = 1048576;      // Specify your counts per unit / user units.           (the motor used in this sample app has 1048576 encoder pulses per revolution)       
            const int VELOCITY          = 1;            // Specify your velocity.       -   units: Units/Sec    (it will do 1048576 counts/1 revolution every 1 second.) 
            const int ACCELERATION      = 10;           // Specify your acceleration.   -   units: Units/Sec^2
            const int DECELERATION      = 10;           // Specify your deceleration.   -   units: Units/Sec^2
            
            // Initialize RapidCode Objects
            controller   = MotionController.CreateFromSoftware("C:\\RSI\\X.X.X\\");                   // Insert the path location of the RMP.rta (usually the RapidSetup folder) (This sample app used RMP 7.1.1).
            SampleAppsCS.HelperFunctions.CheckErrors(controller);                                   // [Helper Function] Check that the controller has been initialize correctly.
            SampleAppsCS.HelperFunctions.StartTheNetwork(controller);                               // [Helper Function] Initialize the network.
            
            //controller.AxisCountSet(1);                                                           // Uncomment if using Phantom Axes.
            axis = controller.AxisGet(AXIS_NUMBER);                                                 // Initialize Axis Class. (Use RapidSetup Tool to see what is your axis number)
            SampleAppsCS.HelperFunctions.CheckErrors(axis);                                         // [Helper Function] Check that the axis has been initialize correctly.
            
            try
            { 
                axis.UserUnitsSet(USER_UNITS);                                                      // Specify the counts per Unit.
                axis.ErrorLimitTriggerValueSet(1);                                                  // Specify the position error limit trigger. (Learn more about this on our support page)
                axis.PositionSet(0);                                                                // Make sure motor starts at position 0 everytime.
                axis.Abort();                                                                       // If there is any motion happening, abort it.
                axis.ClearFaults();                                                                 // Clear faults and enable axis.
                axis.AmpEnableSet(true);                                                            // Enable the motor.
                Console.WriteLine("Absolute Move\n\n");
                Console.WriteLine("Trapezoidal Profile: In Motion...\n");
                //axis.ErrorLimitActionSet(RSIAction.RSIActionNONE);                                // Uncomment when using Phantom Axes.
                
                axis.MoveTrapezoidal(POSITION, VELOCITY, ACCELERATION, DECELERATION);               // Command simple trapezoidal motion.
                axis.MotionDoneWait();                                                              // Wait for motion to be done.
                Console.WriteLine("Trapezoidal Profile: Completed\n\n");                            // If motion is completed this will be printed out.
                
                axis.AmpEnableSet(false);                                                           // Disable the motor.
                Console.WriteLine("\nTest Complete\n");
                
                // Keep the console window open until a key is pressed.
                Console.ReadKey();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);                                                       // If there are any exceptions/issues this will be printed out.
            }
        }
    }
}

You will notice that all of our sample apps use the HelperFunctions class. The HelperFunction class is not included with our API, but we have made that code available in our topic pages and in our API docs so you can copy and paste it into your project and reuse it.

More motion samples can be found here.

7. Make sure that INtime is running and that your motor/axis has been set up correctly in RapidSetup.

8. If the axis has been set up correctly, hit the F5 key to run the project.

Last updated