Samples | ADS 6.4.2 Execute an ADS broadcast search | Execute an ADS broadcast search To trigger a TwinCAT Broadcast search and find unknown remote ADS devices, the ConsumeXml() and ProduceXml() methods from the ITcSmTreeItem interface may be used. General broadcast search Code Snippet (C#): string xmlString = " true TargetList> "; ITcSmTreeItem routes = sysMan.LookupTreeItem("TIRR"); routes.ConsumeXml(xmlString); string result = routes.ProduceXml(); Code Snippet (Powershell):
$xmlString = " true RoutePrj> " $routes = $systemManager.LookupTreeItem("TIRR") $routes.ConsumeXml($xmlString) $result = $routes.ProduceXml() The variable “result” now contains an XML representation of all found ADS devices on the network. To select a specific device from that list, regular .NET mechanisms for XML handling may be used. Code Snippet (C#):
XmlDocument xmlDocument = new XmlDocument(); xmlDocument.Load(result); string amsNetId = xmlDocument.SelectSingleNode("//TreeItem/RoutePrj/TargetList/Target/ IpAddr[text()=\"" + ipAddress + "\"]/../NetId").InnerText; string name = xmlDocument.SelectSingleNode("//TreeItem/RoutePrj/TargetList/Target/IpAddr[text()=\"" + ipAddress + "\"]/../Name").InnerText; Code Snippet (Powershell): $xmlDocument = [xml]$result $localAmsNetId = $xmlDocument.TreeItem.RoutePrj.Target This information might then be used to add a route to that ADS device, as described in a separate documentation article. Direct broadcast search Requires at least TwinCAT 3.1 Build 4020.10 or higher.
To execute a broadcast search with a given hostname or IP address, the following XML structures can be used in ConsumeXml(). XML - Search for Hostname: CX-12345 XML - Search for IP address: 172.17.60.153 A subsequent ProduceXml() will return the found host as follows: XML - Found host: TE1000 224 Version: 1.7.0