Controller connection C#

Hi guys,

I'm working on my app in c#.
I found sample code for controller communication, but sample was written in Visual Studio in Windows Application Project.
I would like to change this code for WPF project. I made some modifications, but I have some issue to get data from controller.
Below sample code c# Windows Application Project.
*****************************************************************************************************************************************************
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;

using System.Text;
using System.Windows.Forms;
using ABB.Robotics.Controllers;
using ABB.Robotics.Controllers.Discovery;

namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }



        private void Form1_Load(object sender, EventArgs e)
        {
              NetworkScanner scanner = new NetworkScanner();
              scanner.Scan();
              ControllerInfoCollection controllers = scanner.Controllers;
              foreach (ControllerInfo controller in controllers)
              {
                  ListViewItem item = new ListViewItem(controller.SystemName);
                  item.SubItems.Add(controller.IPAddress.ToString());
                  item.SubItems.Add(controller.Version.ToString());
                  item.SubItems.Add(controller.IsVirtual.ToString());
                  item.Tag = controller;
                  this.listView1.Items.Add(item);
                 
              }

        }

        private void listView1_DoubleClick(object sender, EventArgs e)
        {
            ListViewItem itemView = listView1.SelectedItems[0];

            if (itemView.Tag != null)
            {
                ControllerInfo controllerInfo = (ControllerInfo)itemView.Tag;

                Controller ctr1 = ControllerFactory.CreateFrom(controllerInfo);
                ctr1.Logon(UserInfo.DefaultUser);

                ListViewItem item = new ListViewItem(ctr1.RobotWare.ToString() +
                    " " + ctr1.State.ToString() + " " + ctr1.OperatingMode.ToString());
                this.listView2.Items.Add(item);

                ctr1.Logoff();
                ctr1.Dispose();
            }
           


        }

    }
}
*******************************************************************************************************************************
And here my modification for WPF Project. At this moment I have problem with modification this function : private void listView1_DoubleClick(object sender, EventArgs e).
How to do this ?

namespace controller_setup1
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        public class User
        {
            public string Name { get; set; }

            public string Adress { get; set; }

            public string Version { get; set; }

            public string Virtual { get; set; }

           
        }

        public class Info
        {
            public string Data {get; set;}
        }



        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            NetworkScanner scanner = new NetworkScanner();
            scanner.Scan();
            ControllerInfoCollection controllers = scanner.Controllers;

            foreach (ControllerInfo controller in controllers)
            {
                List<User> items = new List<User>();
                items.Add(new User()
                {
                    Name = controller.SystemName,
                    Adress = controller.IPAddress.ToString(),
                    Version = controller.Version.ToString(),
                    Virtual = controller.IsVirtual.ToString()
                });
               
                listView1.ItemsSource = items;

            }

        }

        private void listView1_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
 

        }
    }
}
******************************************************************************************************************************


Comments

  • carlosmtz2000carlosmtz2000 United States ✭✭

    Hi,

    Are you using the same controller to test against and the same SDK?

    Do you have troubles with getting the data or presenting the data? If it is getting the data, the code should be the same: CreateConnection - Logon - GetData - LoggOff.

    BR/Carlos

    Carlos Martinez
    ABB
  • apoxapox Germany ✭✭
    edited June 2015
    How about this public MainWindow() { InitializeComponent(); } private void MainWindow_OnLoaded(object sender, RoutedEventArgs e) { NetworkScanner scanner = new NetworkScanner(); scanner.Scan(); ControllerInfoCollection controllers = scanner.Controllers; listView1.ItemsSource = controllers; } private void ListView1_OnMouseDoubleClick(object sender, MouseButtonEventArgs e) { ListView listView = sender as ListView; ControllerInfo info = listView.SelectedValue as ControllerInfo; }
Sign In or Register to comment.