RobotStudio event

Logon to Controller using PC SDK

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(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.

Lingaa

Comments

  • I am using the robot studio in the same machine where i am running the application. Will it work or not?
    Lingaa
  • 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.
    Russell Drown
  • 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);
    Best regards,

    Ingela Brorsson
    Software Engineer
    ABB Robotics, Sweden