How to execute a broadcast search
Requirements
To find unknown remote ADS devices, a broadcast search needs to be executed. This can be done by making use of the ConsumeXml() and ProduceXml() methods of the TwinCAT Automation Interface. |
Sample (C#):
class Program
{
private static string _tsmPath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "\\Templates\\Sample.tsm";
private static TcSysManager _sysManager;
static void Main(string[] args)
{
_sysManager = new TcSysManager();
_sysManager.NewConfiguration();
/* ==============================================
* XML String as shown above
* ============================================== */
string xmlString = "<TreeItem><RoutePrj><TargetList><BroadcastSearch>true</BroadcastSearch></TargetList></RoutePrj></TreeItem>";
/* ==============================================
* Lookup System Manager node "SYSTEM^Route Settings" using Shortcut "TIRR" and consume XML string
* ============================================== */
ITcSmTreeItem routesNode = _sysManager.LookupTreeItem("TIRR");
routesNode.ConsumeXml(xmlString);
/* ==============================================
* Calling ProduceXml() on the same node executes the broadcast search and returns its results
* ============================================== */
string result = routesNode.ProduceXml();
Console.WriteLine(result);
/* ==============================================
* Save configuration
* ============================================== */
sysManager.SaveConfiguration(_tsmPath);
}
}