# Logon to Controller using PC SDK

**URL:** <https://tech-community.robotics.abb.com/t/logon-to-controller-using-pc-sdk/2514>\
**Category:** Developer Tools\
**Created:** [February 12, 2009, 2:00pm UTC](https://tech-community.robotics.abb.com/t/logon-to-controller-using-pc-sdk/2514 "2009-02-12T14:00:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lin](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/lin/32/2104_2.png) [@Lin](https://tech-community.robotics.abb.com/u/Lin)\
**Post date:** [February 12, 2009, 2:00pm UTC](https://tech-community.robotics.abb.com/t/logon-to-controller-using-pc-sdk/2514/1 "2009-02-12T14:00:26Z")

</div>

I am new to this development.

I used the code given in RAB tutorial and tried with visual C# express 2008.

The other features  
Display a controllers. Scanning a controller in local area. add to list view.

But double click the controller to logon is not working properly

My code is here:

private void Form1\_DoubleClick(object sender, EventArgs e)  
{  
ListViewItem item = this.listView1.SelectedItems[0];  
//UserInfo aUserInfo = new UserInfo(“DefaultUser”, “robotics”);

if (item.Tag != null)  
{  
ControllerInfo controllerInfo = (ControllerInfo)item.Tag;  
if (controllerInfo.Availability == Availability.Available)  
{  
if (this.controller != null)  
{  
this.controller.Logoff();  
this.controller.Dispose();  
this.controller = null;  
}  
this.controller = ControllerFactory.CreateFrom(controllerInfo);  
this.controller.Logon(UserInfo.DefaultUser);  
[//this.controller.Logon](https://this.controller.Logon)(aUserInfo);  
}  
else  
{  
MessageBox.Show(“Selected Controller is not Available”);  
}  
}  
}

I added the Listview1 - Events - Double Click property to “Form1\_DoubleClick”.

Shall i use this.controller.Logon(UserInfo.DefaultUser);  
or the one i commented.

What else i should do…

please help me to do this.

---

<div class="post-metadata">

**Author:** ![Lin](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/lin/32/2104_2.png) [@Lin](https://tech-community.robotics.abb.com/u/Lin)\
**Post date:** [February 12, 2009, 2:40pm UTC](https://tech-community.robotics.abb.com/t/logon-to-controller-using-pc-sdk/2514/2 "2009-02-12T14:40:15Z")

</div>

I am using the robot studio in the same machine where i am running the application. Will it work or not?

---

<div class="post-metadata">

**Author:** ![RussD](https://avatars.discourse-cdn.com/v4/letter/r/dec6dc/32.png) [@RussD](https://tech-community.robotics.abb.com/u/RussD)\
**Post date:** [February 12, 2009, 3:17pm UTC](https://tech-community.robotics.abb.com/t/logon-to-controller-using-pc-sdk/2514/3 "2009-02-12T15:17:07Z")

</div>

What error are you getting? UserInfo.DefaultUser should work fine. Are you sure you have an item selected in the listview first? Your code doesn’t do anything if the tag property is null, you should display another error if it is null. You should step through the code with the debugger to follow what is happening.

As an improvement, I would recommend using something other than a double-click of the listview as the means for for connecting. You could use a button’s click event to execute the same code and disable the button until you have selected/activated an item in the listview.

---

<div class="post-metadata">

**Author:** ![Ingela](https://avatars.discourse-cdn.com/v4/letter/i/53a042/32.png) [@Ingela](https://tech-community.robotics.abb.com/u/Ingela)\
**Post date:** [February 12, 2009, 3:18pm UTC](https://tech-community.robotics.abb.com/t/logon-to-controller-using-pc-sdk/2514/4 "2009-02-12T15:18:34Z")

</div>

Hello,

It should work. My code looks like this, and it works:

private void listView1\_DoubleClick(object sender, EventArgs e)

{

ListViewItem item = this.listView1.SelectedItems[0];

if (item.Tag != null)

{

ControllerInfo controllerInfo = (ControllerInfo)item.Tag;

if (controllerInfo.Availability == Availability.Available)

{

if (this.\_controller != null)

{

this.\_controller.Logoff();

this.\_controller.Dispose();

this.\_controller = null;

}

this.\_controller = ControllerFactory.CreateFrom(controllerInfo);

this.\_controller.Logon(UserInfo.DefaultUser);
