NetworkWatcher doesn't lunch events
Jorge
✭✭
Hello, I',m starting witn Pc SDk for Rw5.13, and I'm doing the samples that you can find on manual.
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
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
0
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 fireDoes 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 Kegley0
Categories
- All Categories
- 5.5K RobotStudio
- 396 UpFeed
- 18 Tutorials
- 13 RobotApps
- 297 PowerPacs
- 405 RobotStudio S4
- 1.8K Developer Tools
- 250 ScreenMaker
- 2.8K Robot Controller
- 316 IRC5
- 61 OmniCore
- 7 RCS (Realistic Controller Simulation)
- 799 RAPID Programming
- AppStudio
- 3 RobotStudio AR Viewer
- 18 Wizard Easy Programming
- 105 Collaborative Robots
- 5 Job listings