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.
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.
C++ Project for RapidCode 10.x.x
1. Set up the project properties.
1.1 Right-click the project in the solution explorer and select "Properties".
1.2 In the drop-down menu in the top left set the Configuration to "All Configurations"
1.3 In the General section set the Output Directory to the install location of RapidSetup.
In this case C:\RSI\10.x.x
1.4 In the C/C++ > General section add the RapidSetup install directory to the Additional Include Directories. Do not overwrite (AdditionalIncludeDirectories).
C:\RSI\10.x.x;%(AdditionalIncludeDirectories)
1.5 In the C/C++ > Preprocessor add RSIAPP;
Do not overwrite <different options>
Depending on your setup you may want to change the set Precompiled Headers to "Not Using Precompiled Headers"
1.6 In the Linker > General section add the RapidSetup install location and the Additional Library Directories to the install location of Rapid Setup.
C:\RSI\10.x.x;%(AdditionalLibraryDirectories)
1.7 In the Linker > General section add RapidCode.lib
2. Add the desired sample app.
2.1 In Solution Explorer (open on View Tab or hit ctrl+alt+L) right click on the Source Files, then click on Add, then click on 'New Item ...'
2.3 Change the Name of your file 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.cpp.
2.4 After you click Add, you will see an empty .cpp file. Paste the desired sample app into the file.
The AbsoluteMotion.cpp sample app above can also be found here.
3. Add a header file for your sample app.
3.1 Right-click Header Files in the Solution Explorer. Then Add a New Item.
3.2 Name the .h file the same as the sample app you added. In this case "AbsolueMotion.h"
3.3 Add the function for your sample app to the header file. In this case AbsoluteMotinMain();
3.4 Include the new header file and a call to your sample app function in your main .cpp file.
#include "AbsoluteMotion.h"
AbsoluteMotionMain();
4. Add the missing helper functions.
4.1 Create a second header file called "HelperFunctions.h"
4.2 Paste the helper functions into this file.
The HelperFunctions.h can also be found here.
5. Make sure that INtime is running and that your motor/axis has been set up correctly in RapidSetup.
6. If the axis has been set up correctly, hit the F5 key to run the project.
C# Project for RapidCode 8.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.
Almost every topic that we provide includes a sample application, your class name should be equal to the name of the sample app you want to use.
2.1 After you click Add, you should be seeing something like this:
3. Add the RSIQDNET4.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 RSIQDNET4.dll file in your RapidSetup Folder, and click OK. (Make sure the checkbox is checked)
3.3 Verify that the RSIQDNET4 library has been added to your References.
4. Set the working directory
4.1 Go to the Debug section. In the drop down select all configurations. Set platform to match that of your .dll file. Set the working directory to the location you installed RMP.
5. Select your platform
32 bit -> RSIQDNET4.dll -> x86
64bit ->RSIQDNET64.dll -> x64
5.1 Open the platform Configuration Manager
5.2 Select the appropriate platform. If not available select <New...>
6. Replace the contents of AbsoluteMotion.cs with the following code.
using System;
using RSI.RapidCode.dotNET; // Import our RapidCode Library.
using RSI.RapidCode.dotNET.Enums;
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 our API docs so you can copy and paste it in your project and reuse it.
The AbsoluteMotion.cs sample app above can also 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.
C++ Project for RapidCode 8.x.x
1. Set up the project properties.
1.1 Right-click the project in the solution explorer and select "Properties".
1.2 In the drop-down menu in the top left set the Configuration to "All Configurations"
1.3 In the General section set the Output Directory to the install location of Rapid Setup. In this case C:\RSI\8.1.5
1.4 In the C/C++ -> General section add the Rapid Setup install directory to the Additional Include Directories. Do not overwrite (AdditionalIncludeDirectories).
C:\RSI\8.1.5;%(AdditionalIncludeDirectories)
1.5 In the C/C++ -> Preprocessor add RSIAPP;
Do not overwrite <different options>
Depending on your setup you may want to change the set Precompiled Headers to "Not Using Precompiled Headers"
1.6 In the Linker -> General section add the Rapid Setup install location and the Additional Library Directories to the install location of Rapid Setup.
C:\RSI\8.1.5;%(AdditionalLibraryDirectories)
1.7 In the Linker -> General section add RSIQVC64.lib
for 64 bit and RSIQVC.lib
for 32 bit
2. Add the desired sample app.
2.1 In Solution Explorer (open on View Tab or hit ctrl+alt+L) right click on the Source Files, then click on Add, then click on New Item .
2.3 Change the Name of your file 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.cpp.
2.4 After you click Add, you will see an empty .cpp file. Paste the desired sample app into the file.
The AbsoluteMotion.cpp sample app above can also be found here.
3. Add a header file for your sample app.
3.1 Right-click Header Files in the Solution Explorer. Then Add a New Item.
3.2 Name the .h file the same as the sample app you added. In this case "AbsolueMotion.h"
3.3 Add the function for your sample app to the header file. In this case AbsoluteMotinMain();
3.4 Include the new header file and a call to your sample app function in your main .cpp file.
#include "AbsoluteMotion.h"
AbsoluteMotionMain();
4. Add the missing helper functions.
4.1 Create a second header file called "HelperFunctions.h"
4.2 Paste the helper functions into this file.
The HelperFunctions.h can also be found here.
5. Make sure that INtime is running and that your motor/axis has been set up correctly in RapidSetup.
6. If the axis has been set up correctly, hit the F5 key to run the project.
Last updated