RobotStudio event

full c# source code in chapter 5 of PC SDK manual

Hi;



I am new to C# but expert in c++. I just need the full source code of the project described in chapter 5 of the PC SDK application manual to get a kick start to learn. Any one can help ?



Rgds



Fun Wey
FW

Comments



  • Hi Fun Wey,
     
    I'm guessing you are talking about this link -> ???
    If so then the point of that exercise is to do it yourself. So ABB doesn't have it anywhere online. So unless you can find someone who has already done the exercise and shares it then its faster and better to do it for yourself. It's mostly copy & paste anyway so for a coding expert it shouldn't be a biggie. Thumbs Up
     
    But you have a different walkthrough on PC SDK over in the Developer Center site with a download. Maybe that could help you get started as well?
     
  • This code should work:

    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 ABB.Robotics;
    using ABB.Robotics.Controllers;
    using ABB.Robotics.Controllers.Discovery;
    using ABB.Robotics.Controllers.RapidDomain;

    namespace Robot_SDK
    {
        public partial class Form1 : Form
        {
            private NetworkScanner scanner = null;
            private Controller controller = null;
            private Task[] tasks = null;
            private NetworkWatcher networkwatcher = null;

            public Form1()
            {
                InitializeComponent();
            }

            private void Form1_Load(object sender, EventArgs e)
            {
                this.scanner = new NetworkScanner();
                this.scanner.Scan();
                ControllerInfoCollection controllers = scanner.Controllers;
                ListViewItem item = null;
                
                foreach (ControllerInfo controllerInfo in controllers)
                {
                    item = new ListViewItem(controllerInfo.IPAddress.ToString());
                    item.SubItems.Add(controllerInfo.Id);
                    item.SubItems.Add(controllerInfo.Availability.ToString());
                    item.SubItems.Add(controllerInfo.IsVirtual.ToString());
                    item.SubItems.Add(controllerInfo.SystemName);
                    item.SubItems.Add(controllerInfo.Version.ToString());
                    item.SubItems.Add(controllerInfo.ControllerName);
                    this.listView1.Items.Add(item);   
                    item.Tag = controllerInfo;
                }
                // Networkwatcher (detecteert als controllers worden aangesloten of worden verwijdert)
                this.networkwatcher = new NetworkWatcher(scanner.Controllers);
                this.networkwatcher.Found += new EventHandler<NetworkWatcherEventArgs>(HandleFoundEvent);
                this.networkwatcher.Lost += new EventHandler<NetworkWatcherEventArgs>(HandleLostEvent);
                this.networkwatcher.EnableRaisingEvents = true;
            }

            private void Form1_FormClosed(object sender, FormClosedEventArgs e)
            {
                this.networkwatcher.Lost -= new EventHandler<NetworkWatcherEventArgs>(HandleLostEvent);
                this.networkwatcher.Found -= new EventHandler<NetworkWatcherEventArgs>(HandleFoundEvent);
            }

            void HandleFoundEvent(object sender, NetworkWatcherEventArgs e)
            {
                this.Invoke(new EventHandler<NetworkWatcherEventArgs>(AddControllerToListView),
                new Object[] { this, e });
            }

            void HandleLostEvent(object sender, NetworkWatcherEventArgs e)
            {
                this.Invoke(new EventHandler<NetworkWatcherEventArgs>(RemoveControllerFromListView), new Object[] { sender, e });
            }

            private void AddControllerToListView(object sender, NetworkWatcherEventArgs e)
            {
                ControllerInfo controllerInfo = e.Controller;
                ListViewItem item = new ListViewItem(controllerInfo.IPAddress.ToString());
                item.SubItems.Add(controllerInfo.Id);
                item.SubItems.Add(controllerInfo.Availability.ToString());
                item.SubItems.Add(controllerInfo.IsVirtual.ToString());
                item.SubItems.Add(controllerInfo.SystemName);
                item.SubItems.Add(controllerInfo.Version.ToString());
                item.SubItems.Add(controllerInfo.ControllerName);
                this.listView1.Items.Add(item);
                item.Tag = controllerInfo;
            }

            private void RemoveControllerFromListView(object sender, NetworkWatcherEventArgs e)
            {
                foreach (ListViewItem item in this.listView1.Items)
                {
                    if ((ControllerInfo)item.Tag == e.Controller)
                    {
                        this.listView1.Items.Remove(item);
                        break;
                    }
                }
            }

            private void listView1_DoubleClick(object sender, EventArgs e)
            {
                ListViewItem listView1 = this.listView1.SelectedItems[0];
                if (listView1.Tag != null)
                {
                    ControllerInfo controllerInfo = (ControllerInfo)listView1.Tag;
                    if (controllerInfo.Availability == Availability.Available) //columnHeader3.Available)
                    {      
                        if (this.controller != null)   
                        {
                            this.controller.Logoff(); this.controller.Dispose();
                            this.controller = null;
                        }
                        this.controller = ControllerFactory.CreateFrom(controllerInfo);
                        this.controller.Logon(UserInfo.DefaultUser);
                    }
                    else
                    {
                        MessageBox.Show("Selected controller not available.");
                    }
                }
            }

            private void button1_Click(object sender, EventArgs e)
            {
                try
                {
                    if (controller.OperatingMode == ControllerOperatingMode.Auto)
                    {
                        tasks = controller.Rapid.GetTasks();
                        using (Mastership m = Mastership.Request(controller.Rapid))
                        {
                            //Perform operation
                            tasks[0].Start();
                        }
                    }
                    else
                    {
                        MessageBox.Show("Automatic mode is required to start execution from a remote client.");
                    }
                }
                catch (System.InvalidOperationException ex)
                {
                    MessageBox.Show("Mastership is held by another client." + ex.Message);
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show("Unexpected error occurred: " + ex.Message);
                }
            }
         }
    }
     

    Luks
  • Hi Luks,

    This code will work with Real Robot Controller.

    Working with Virtual Controllers you can try this

    if (_currentController != null)
    {
        if (!_currentController.IsVirtual)
       {
          _currentController.Logoff();
        }
    _currentController.Dispose();
    _currentController = null;
    }


    if (!_currentController.IsVirtual)
    {
          if (_currentController.CurrentUser != UserInfo.DefaultUser)
          {
               _currentController.Logon(UserInfo.DefaultUser);
           }
    }

    In the above code "_currentController" is yours "this.controller"

    Hope it will work.
    Lingaa





  • Hi all.

    Several question, Lingaa.Where do you incorporate this code that you have written in the code that Luks to writing?.
    I'm also starting as Funwei, and do not quite understand what you say.
    Luks code is for use with real controllers, right?.
    Adding your code to the Luks, fits the real and virtual controllers, right?.

    Thanks in advance.

    Jesus. Wink


    jesus2012-10-18 01:26:00


  • I did this as a template when working with supportcases:
     
    Its a Visual Studio 2010 C# project with 5.14.03 components which is like the one in the example. But it has some other logic in it.
     
    I'll make a 5.15 version as soon as the main 5.15 release topic is finished by Product Management.


  • Thanks John.

    This will be a great help to start my project.

    Jesus. Clap
  • Hi Jesus,
    Ya my code will consider both virtual and real controllers.
    When I was working with virtual controllers the code controller.Logoff() is giving exemption. So I am detecting the controller is virtual or real.
    I have not yet tried my code with real controllers.
    John code is working fine with virtual too.

    Lingaa
  • Thanks for your answer.
     
    Jesus.