Forum Migration Notice
We're transitioning to a more modern community platform by the end of this year. Learn about the upcoming changes and what to expect.

NetworkWatcher doesn't lunch events

Hello, I',m starting witn Pc SDk for Rw5.13, and I'm doing the samples that you can find on manual.
 

So I did the sample until the networkwatcher. My application compiles with no problem. But the networkwatch never lunchs the event OnFound (found controller). I testing it on Virtual controller (RobotStudio 5.13).

 

Here is my code:


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);
listView1.Items.Add(item);
}
this.networkwacther = new NetworkWatcher(controllers);
networkwacther.Found +=
new EventHandler<NetworkWatcherEventArgs>(HandleFoundEvent);
networkwacther.Lost +=
new EventHandler<NetworkWatcherEventArgs>(networkwacther_Lost);
}

private void HandleFoundEvent (object sender, NetworkWatcherEventArgs e)
{

//throw new Exception("The method or operation is not implemented.");

 
//I put a stop here
Invoke(
new EventHandler<NetworkWatcherEventArgs>(AddControllerToListView), new Object[] { this, e });
}
 
What's happen?.
 
Thanks
/Jorge

 
Jorge Turiel

Comments

  • I built similiar code,.. but I used a "real" robot.. and the "found" worked.... BUT, it took almost a whole minute(or more) for the "found" event to fire...
     

    it took about 30-45 seconds for the "lost" event to fire

     

    Does anyone know Why?, it takes so long for the lost and/or found events to fire?

    ...anyone no how to speed this up ?.

     

     

    code below

     

     


    public void StartNetwatcher()
    {
    try
    {
    this.watcher = new NetworkWatcher(scanner.Controllers);
    this.watcher.Found += new EventHandler<NetworkWatcherEventArgs>(HandleFoundEvent);
    this.watcher.Lost += new EventHandler<NetworkWatcherEventArgs>(HandleLostEvent);
    this.watcher.EnableRaisingEvents = true;
    }
    catch { }
    }
    public void StopNetwatcher()
    {
    try
    {
    this.watcher.EnableRaisingEvents = false;
    this.watcher.Found -= new EventHandler<NetworkWatcherEventArgs>(HandleFoundEvent);
    this.watcher.Lost -= new EventHandler<NetworkWatcherEventArgs>(HandleLostEvent);
    this.watcher.Dispose();
    this.watcher = null;
    }
    catch { }
    }
    void HandleFoundEvent(object sender, NetworkWatcherEventArgs e)
    {
    this.Invoke(new EventHandler<NetworkWatcherEventArgs>(ControllerFound), new Object[] { this, e });
    }
    void HandleLostEvent(object sender, NetworkWatcherEventArgs e)
    {
    this.Invoke(new EventHandler<NetworkWatcherEventArgs>(ControllerLost), new Object[] { this, e });
    }
    a__
    a__
    a__
    private void ControllerFound(object sender, NetworkWatcherEventArgs e)
    {
    ControllerInfo controllerInfo = e.Controller;
    if (e.Controller.IPAddress.ToString() == this.RobotIPaddress)
    {
    this.Startup();
    }
    }


    private void ControllerLost(object sender, NetworkWatcherEventArgs e)
    {
    ControllerInfo controllerInfo = e.Controller;
    if (e.Controller.IPAddress.ToString() == this.RobotIPaddress)
    {
    this.ShutDown();
    }
    }
    Mike Kegley