Hello!
I have taken a look at the issue of controllers not being discovered correctly.
The reason it behaves this way is because the discovery of controllers is not really managed by the PC SDK application you are writing, but instead by a service called RobNetScanHost.exe. This service is started whenever you Scan using a NetworkScanner for example. It takes a while for this service to actually discover and get information from all controllers on the network.
RobotStudio also uses this service, meaning that if you have had RobotStudio running for a while beforehand, the service will already have been running for a while.
One quite simple way to work around this is by calling NetworkScanner.Scan() and then wait for a few seconds using a Stopwatch or by Sleeping the Thread. You can then call Scan again and get more discovered controllers.
Another way to deal with it is by knowing which controllers you actually are looking for. As you discussed before, this can be done using Guids. If you take your time and let the scan find all controllers on the network you are interested in, you can then save the Guid of these controllers in a text file for example. This text file can then be read by a program and used with NetworkScanner.TryFind().
I have attached a Visual Studio Project file with a simple example of how this can be implemented. It has worked well on our system and managed to find all our controllers consistently and quickly even after just having rebooted my computer (meaning that the service hasn’t had a lot of time to look for controllers).
Simply run SaveControllers() and then LoadControllers().
Below is also the raw code:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using ABB.Robotics.Controllers;
using ABB.Robotics.Controllers.Discovery;
namespace GuidControllerScan
{
class Program
{
private static readonly int WAIT_TIME = 1000;
private static readonly int RETRIES = 2;
private static readonly string PATH_GUID = “C:\TestGuid\guid.txt”;
static void Main(string args)
{
//SaveControllers();
LoadControllers();
Console.ReadKey();
}
// Save the scanned controllers to the Guid file
public static void SaveControllers()
{
ControllerInfo cInf = ScanControllerInfo();
Guid guid = cInf.Select(e => new Guid(e.SystemId.ToString())).ToArray();
WriteGuidLog(guid, PATH_GUID);
}
// Load the controllers from the saved Guid file
public static void LoadControllers()
{
Guid guid = ReadGuidLog(PATH_GUID);
ControllerInfo cInf = GetControllers(guid);
}
/// Attempts to get the controllers from an array of Guid
public static ControllerInfo GetControllers(Guid guidArray)
{
Console.WriteLine($“Scanning for {guidArray.Length} Guid…”);
NetworkScanner networkScanner = new NetworkScanner();
List controllerInfoList = new List();
for (int i = 0; i < guidArray.Length; i++)
if (networkScanner.TryFind(guidArray[i], WAIT_TIME, RETRIES, out ControllerInfo info))
controllerInfoList.Add(info);
Console.WriteLine($“Found {controllerInfoList.Count} ControllerInfo.”);
return controllerInfoList.ToArray();
}
/// Save the Guid as a text file
private static void WriteGuidLog(Guid guidArray, string filePath)
{
Console.WriteLine($“Writing Guid log {filePath}”);
FileInfo info = new FileInfo(filePath);
if (info.Exists)
info.Delete();
else
info.Directory.Create();
File.WriteAllLines(filePath, guidArray.Select(e => e.ToString()).ToArray());
Console.WriteLine($“Finished writing Guid log {filePath}”);
}
/// Read Guid from a text file
private static Guid ReadGuidLog(string filePath)
{
Console.WriteLine($“Reading Guid log {filePath}”);
return File.ReadAllLines(filePath).Select(e => new Guid(e)).ToArray();
}
/// Scan the network for controllers
private static ControllerInfo ScanControllerInfo()
{
Console.WriteLine($“Scanning for controllers…”);
NetworkScanner scanner = new NetworkScanner();
scanner.Scan();
// Wait a while for the scan to find more controllers if needed.
System.Threading.Thread.Sleep(4000);
scanner.Scan();
Console.WriteLine($“Found {scanner.GetControllers().Length} controllers.”);
return scanner.GetControllers();
}
}
}
GuidControllerScan.zip (593 KB)