Please read our Legal Disclaimer before executing any steps on this article.
Overview
In ORiN2 SDK, DCOM (Distributed Component Object Model) of Microsoft Corporation is adopted as a distributed object technology. The DCOM based CAO can be used from various program languages such as C++, JAVA, and Visual Basic.
This article is meant to help to gather information on resources that can help you get started with interfacing with the CAO Engine in C# (Visual Studio IDE). This article is not intended to aid you with programming in C# nor how to use Visual Studio IDE.
Tools and Parts needed
- ORiN 2 SDK Install
- Visual Studio IDE
- PC running Windows OS
NOTE: The following sample code is provided "AS IS" under the MIT License. Programming support service of C# is out of warranty. Please note that we do not provide any programming support service beyond basic setup and troubleshooting.
Video Tutorial
Previous Steps...
Please make sure that you have reviewed the ORiN2 - Overview article and that your RC controller is properly setup. You can use the CAOTester to make sure that your PC is ready to communicate with the controller.
Set up your controller to accept messages from your PC. | ORiN 2 - Robot Controller Setup (RC8 / RC8A / COBOTTA) |
Test communication using CAO Tester application | ORiN 2 - Operation check using CAOTester (CAO Engine) |
Configuring the Project to Point to the ORiN Library (CaoRCW) |
Programming References
At this point, you should be ready to begin programming your application to interface with your robot controller. When connecting to the controller, you will need to specify the ORiN provider you are trying to use to establish communication. The provider differs based on the robot controller you are using. RC5, RC7, and RC7M controllers use the NetwoRC provider. RC8, RC8A, and COBOTTA controllers us the RC8 provider.
NetwoRC provider directory
C:\ORiN2\CAO\ProviderLib\DENSO\NetwoRC
RC8 provider directory
C:\ORiN2\CAO\ProviderLib\DENSO\RC8
NOTE: Please consult the Owner's manual for information on how to program your DENSO Robot or details on specific robot commands.
Programming using the Provider
The following samples are for performing various basic but essential operations. The samples are for connecting using the RC8 Provider.
For more information you can reference Section 4 RC8 Programming Using the Provider from the RC8 Provider User's Guide PDF document.
RC8 Provider User Guide Samples in C#
This document intends to give you a better experience when trying to implement a command in the provider. We have "translated" the original VB6 samples in Section 5.0 from the RC8 provider guide into C# language. Click here to download a copy. |
Variable Sample
This sample code will read or write to the string global variable "S15" on the robot controller. For more information, reference Section 4.1 RC8 controller variable access. |
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using ORiN2.interop.CAO; namespace RC8_with_ORiN_VS2010 { public partial class Variable : Form { private CaoEngine g_eng; //CaoEngine object variable private CaoController g_ctrl; //CaoController object variable private CaoVariable g_val; //CaoVariable object variable public Variable() { InitializeComponent(); } private void Command1_Click(object sender, EventArgs e) { Text1.Text = Convert.ToString(g_val.Value); //Read Variable } private void Command2_Click(object sender, EventArgs e) { g_val.Value = Convert.ToString(Text2.Text); } private void Variable_Load(object sender, EventArgs e) { g_eng = new CaoEngine(); //CaoEngine object creation //Connect RC: IP setting depends on your RC setting. g_ctrl = g_eng.Workspaces.Item(0).AddController("RC8", "CaoProv.DENSO.RC8", "", "Server=192.168.0.1"); //Variable name "S15" g_val = g_ctrl.AddVariable("S15", ""); } private void Variable_FormClosed(object sender, FormClosedEventArgs e) { //Delete variable object g_ctrl.Variables.Clear(); System.Runtime.InteropServices.Marshal.ReleaseComObject(g_val); g_val = null; //Delete controller object g_eng.Workspaces.Item(0).Controllers.Remove(g_ctrl.Index); System.Runtime.InteropServices.Marshal.ReleaseComObject(g_ctrl); g_ctrl = null; //Delete engine object System.Runtime.InteropServices.Marshal.ReleaseComObject(g_eng); g_eng = null; } } }
Task Sample
This sample code will start or stop a robot program (Pro1.pcs), also known as tasks.
For more information, reference Section 4.2 Task controller with RC8 controller. |
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using ORiN2.interop.CAO; namespace RC8_with_ORiN_VS2010 { public partial class Task : Form { private CaoEngine g_eng; //CaoEngine object variable private CaoController g_ctrl; //CaoController object variable private CaoTask g_task; //CaoTask object variable private CaoTask g_task2; public Task() { InitializeComponent(); } private void Command1_Click(object sender, EventArgs e) { g_task.Start(1, ""); //Start Task } private void Command2_Click(object sender, EventArgs e) { g_task.Stop(4, ""); //Stop Task } private void Task_Load(object sender, EventArgs e) { g_eng = new CaoEngine(); //CaoEngine object creation //Connect RC: IP setting depends on your RC setting. g_ctrl = g_eng.Workspaces.Item(0).AddController("RC8", "CaoProv.DENSO.RC8", "", "Server=192.168.0.1"); g_task = g_ctrl.AddTask("PRO1", ""); //Task name PRO1 g_task2 = g_ctrl.AddTask("Test1", ""); } private void Task_FormClosed(object sender, FormClosedEventArgs e) { //Delete task object g_ctrl.Tasks.Clear(); System.Runtime.InteropServices.Marshal.ReleaseComObject(g_task); g_task = null; //Delete controller object g_eng.Workspaces.Item(0).Controllers.Remove(g_ctrl.Index); System.Runtime.InteropServices.Marshal.ReleaseComObject(g_ctrl); g_ctrl = null; //Delete engine object System.Runtime.InteropServices.Marshal.ReleaseComObject(g_eng); g_eng = null; } } }
Robot Motion Sample
This sample code will turn the motor ON or OFF. When the Start Robot button is pressed, the robot will Move to position P10 and then to position P11.
For more information, reference Section 4.3 Robot control with RC8 controller. |
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using ORiN2.interop.CAO; namespace RC8_with_ORiN_VS2010 { public partial class Robot : Form { private CaoEngine g_eng; //CaoEngine object variable private CaoController g_ctrl; //CaoController object variable private CaoRobot g_robot; //CaoRobot object variable private CaoVariable g_robotVar; //CaoVariable from CaoRobot object private bool g_haltFlag; public Robot() { InitializeComponent(); } private void Command1_Click(object sender, EventArgs e) { if (g_robotVar.Value == false) //Start motor if arm is stationary g_robot.Execute("Motor", new object[] { 1, 0 }); //Start Motor } private void Command2_Click(object sender, EventArgs e) { if (g_robotVar.Value == false) //Stop motor if arm is stationary g_robot.Execute("Motor", new object[] { 0, 0 }); } private void Command3_Click(object sender, EventArgs e) { g_robot.Halt(""); //Stop Robot g_haltFlag = true; //Record robot stop } private void Command4_Click(object sender, EventArgs e) { if (g_robotVar.Value == true) return; g_haltFlag = false; g_robot.Move(1, "@P P10", "NEXT"); //Run Robot //Do not start next motion until previous motion is completed do { Application.DoEvents(); } while (g_robotVar.Value == false); //Do not start next motion if robot has stopped if (g_haltFlag == true) return; //Run Robot g_robot.Move(1, "@P P11", "NEXT"); } private void Robot_Load(object sender, EventArgs e) { g_eng = new CaoEngine(); //CaoEngine object creation //Connect RC: IP setting depends on your RC setting. g_ctrl = g_eng.Workspaces.Item(0).AddController("RC8", "CaoProv.DENSO.RC8", "", "Server=192.168.0.1"); //Create CaoRobot object g_robot = g_ctrl.AddRobot("Arm"); //Argument used to check arm running status g_robotVar = g_robot.AddVariable("@BUSY_STATUS"); g_robot.Execute("Takearm"); //Get arm control authority //Start Motor Command1_Click(sender,e); } private void Robot_FormClosed(object sender, FormClosedEventArgs e) { //Stop Motor Command2_Click(sender, e); //Release arm control authority g_robot.Execute("Givearm"); //Release arm control authority //Delete robot variable object g_robot.Variables.Clear(); System.Runtime.InteropServices.Marshal.ReleaseComObject(g_robotVar); g_robotVar = null; //Delete robot arm object g_ctrl.Robots.Clear(); System.Runtime.InteropServices.Marshal.ReleaseComObject(g_robot); g_robot = null; //Delete controller object g_eng.Workspaces.Item(0).Controllers.Remove(g_ctrl.Index); System.Runtime.InteropServices.Marshal.ReleaseComObject(g_ctrl); g_ctrl = null; //Delete engine object System.Runtime.InteropServices.Marshal.ReleaseComObject(g_eng); g_eng = null; } } }
More samples...
You can find C# samples in your install of the ORiN 2 SDK. Here are some recommendations:
RC8 Provider Samples
Sample Name | Directory Path |
---|---|
Joystick Sample | C:\ORiN2\CAO\ProviderLib\DENSO\RC8\Samples\Joystick\C# |
Robot | C:\ORiN2\CAO\ProviderLib\DENSO\RC8\Samples\Robot\C# |
Robot (Simple) | C:\ORiN2\CAO\ProviderLib\DENSO\RC8\Samples\Simple\Robot\C# |
Task (Simple) | C:\ORiN2\CAO\ProviderLib\DENSO\RC8\Samples\Simple\Task\C# |
Variable (Simple) | C:\ORiN2\CAO\ProviderLib\DENSO\RC8\Samples\Simple\Variable\C# |
Task | C:\ORiN2\CAO\ProviderLib\DENSO\RC8\Samples\Task\C# |
NetwoRC Provider Samples
Sample Name | Directory Path |
---|---|
Task | C:\ORiN2\CAO\ProviderLib\DENSO\NetwoRC\Samples\Task\C# |
Owner's Manual Reference
Was this article helpful?
That’s Great!
Thank you for your feedback
Sorry! We couldn't be helpful
Thank you for your feedback
Feedback sent
We appreciate your effort and will try to fix the article