Beckhoff Automation GmbH & Co. KG — 8.13 How to scan devices and boxes

How to Addition and parametrization of the devices to be used Scanning and insertion of boxes for each device Procedure The procedure to create the ITcSysManager [ } 30] interface (the ' systemManager' instance here) is described in the chapter Accessing TwinCAT Configurations. [ } 17] This interface has a LookupTreeItem [ } 35] method that returns a ITcSmTreeItem [ } 37] pointer to a specific tree item given by its pathname, in this case the shortcut "TIID" which references the I/O devices node. Code snippet (C#):

ITcSysManager3 systemManager = null; // How to create the System Manager instance and how to open co nfiguration is shown in Concepts chapter public void ScanDevicesAndBoxes() { systemManager.SetTargetNetId("1.2.3.4.5.6"); // Setting of the target NetId. ITcSmTreeItem ioDevicesItem = systemManager.LookupTreeItem("TIID"); // Get The IO Devices Node // Scan Devices (Be sure that the target system is in Config mode!) string scannedXml = ioDevicesItem.ProduceXml(false); // Produce Xml implicitly starts the ScanD evices on this node.

XmlDocument xmlDoc = newXmlDocument(); xmlDoc.LoadXml(scannedXml); // Loads the Xml data into an XML Document XmlNodeList xmlDeviceList = xmlDoc.SelectNodes("TreeItem/DeviceGrpDef/FoundDevices/Device"); List devices = newList (); int deviceCount = 0; // Add all found devices to configuration foreach (XmlNode node in xmlDeviceList) { // Add a selection or subrange of devices int itemSubType = int.Parse(node.SelectSingleNode("ItemSubType").InnerText); string typeName = node.SelectSingleNode("ItemSubTypeName").InnerText; XmlNode xmlAddress = node.SelectSingleNode("AddressInfo"); ITcSmTreeItem device = ioDevicesItem.CreateChild(string.Format("Device_{0}",+ +deviceCount),itemSubType,string.Empty,null); string xml = string.Format(" {0} TreeItem>",xmlAddress.OuterXml); device.ConsumeXml(xml); // Consume Xml Parameters (here the Address of the Device) devices.Add(device); } // Scan all added devices for attached boxes foreach (ITcSmTreeItem device in devices) { string xml = " 1 TreeItem>"; // Using the "ScanBoxes XML-Method" try { device.ConsumeXml(xml); // Consume starts the ScanBoxes and inserts every found box/ terminal into the configuration } catch (Exception ex) { Console.WriteLine("Warning:

{0}",ex.Message); } foreach (ITcSmTreeItem box in device) { Console.WriteLine(box.Name); } } } Code snippet (IronPython): import xml.etree.ElementTree as ET # Create the System Manage instance “sysMan” first Automation Interface 78 Version: 1.2