# Connecting C# and Rapid Mastership problem.

**URL:** <https://tech-community.robotics.abb.com/t/connecting-c-and-rapid-mastership-problem/5719>\
**Category:** Developer Tools\
**Created:** [September 23, 2013, 8:17am UTC](https://tech-community.robotics.abb.com/t/connecting-c-and-rapid-mastership-problem/5719 "2013-09-23T08:17:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gabel](https://avatars.discourse-cdn.com/v4/letter/g/54ee81/32.png) [@Gabel](https://tech-community.robotics.abb.com/u/Gabel)\
**Post date:** [September 23, 2013, 8:17am UTC](https://tech-community.robotics.abb.com/t/connecting-c-and-rapid-mastership-problem/5719/1 "2013-09-23T08:17:07Z")

</div>

Hello, im working on getting some basic communicion between C# and Rapid. But im having some truble whit the Mastership class. Note in the code “This is where my problem is”, im getting “An unhandled exception of type ‘ABB.Robotics.GenericControllerException’ occurred in ABB.Robotics.Adapters.IRC5.dll”.  
Im working in microsoft visual studio professional 2012.

Here is my code:

using System;  
using ABB.Robotics;  
using ABB.Robotics.Controllers;  
using ABB.Robotics.Controllers.Discovery;  
using ABB.Robotics.Controllers.RapidDomain;

class Program{

static void Main(string args){

NetworkScanner scanner = new NetworkScanner();  
scanner.Scan();

ControllerInfoCollection controllers = scanner.Controllers;

foreach (ControllerInfo controllerInfo in controllers){  
Console.WriteLine(“IPAddress: " + controllerInfo.IPAddress.ToString()+”\n");  
Console.WriteLine("System Name : " + controllerInfo.SystemName + “\n”);  
Console.WriteLine("Controller Name: " + controllerInfo.ControllerName + “\n”);  
}  
Console.WriteLine("Connected to ip: " + scanner.Controllers[0].IPAddress.ToString());

Controller \_controller = new Controller(scanner.Controllers[0].SystemId);  
\_controller.Logon(UserInfo.DefaultUser);  
//int i;  
//for (i = 0; i \< 10; i++)  
//{  
// Console.WriteLine(\_controller.MotionSystem.ActiveMechanicalUnit.GetPosition().ToString() + “\n” + "i= " + i);  
// // System.Threading.Thread.Sleep(500);  
//}  
Bool boolRunning;  
RapidData rd = \_controller.Rapid.GetRapidData(“T\_ROB1”, “Module1”, “running”);

if (rd.Value is ABB.Robotics.Controllers.RapidDomain.Bool)  
{  
boolRunning = (ABB.Robotics.Controllers.RapidDomain.Bool)rd.Value;  
//assign the value of the RAPID data to a local variable  
bool boolValue = boolRunning.Value;  
Console.WriteLine("The RAPID bool is: " + boolValue);

//Assign new value to .Net variable  
boolRunning.Value = false;  
//Request mastership of Rapid before writing to the controller  
//Mastership master = Mastership.Request(\_controller.Rapid);  
Mastership m = Mastership.Request(\_controller.Rapid); //This is where my problem is  
Console.WriteLine(m.IsMaster.ToString());  
//Change: controller is repaced by aController  
rd.Value = boolRunning;  
//Release mastership as soon as possible  
m.Dispose();  
}

Console.ReadLine();  
}  
}

---

<div class="post-metadata">

**Author:** ![joman](https://avatars.discourse-cdn.com/v4/letter/j/2bfe46/32.png) [@joman](https://tech-community.robotics.abb.com/u/joman)\
**Post date:** [September 24, 2013, 11:11am UTC](https://tech-community.robotics.abb.com/t/connecting-c-and-rapid-mastership-problem/5719/2 "2013-09-24T11:11:13Z")

</div>

Could you catch the exception and see if there is any more information to be seen from it?

---

<div class="post-metadata">

**Author:** ![Gabel](https://avatars.discourse-cdn.com/v4/letter/g/54ee81/32.png) [@Gabel](https://tech-community.robotics.abb.com/u/Gabel)\
**Post date:** [October 9, 2013, 11:12am UTC](https://tech-community.robotics.abb.com/t/connecting-c-and-rapid-mastership-problem/5719/3 "2013-10-09T11:12:56Z")

</div>

The problem was that mastership was given to someone else, rebooted the VC and it was fine.
