Beckhoff Automation GmbH & Co. KG — 5.2.2 From offline to online configurations

Configuration Code Snippet (C#): ITcSmTreeItem ioDevices = systemManager.LookupTreeItem("TIID"); string foundDevices = ioDevices.ProduceXml(); Step 3: Iterating through XML and configuring address information of I/Os In this example we want to update the address information of an EtherCAT device which is already part of our offline configuration. The ProduceXml() in step 2 has already returned the available I/O devices on the system, which is now available in the variable 'foundDevices'. We will identify the EtherCAT device in this XML via its item sub type (111) and then update the address information of the EtherCAT Master in our configuration. Code Snippet (C#):

XmlDocument doc = new XmlDocument(); doc.LoadXml(foundDevices); XmlNodeList devices = doc.SelectNodes("TreeItem/DeviceGrpDef/FoundDevices/Device"); foreach (XmlNode device in devices) { xmlNode typeNode = device.SelectSingleNode("ItemSubType"); int subType = int.Parse(typeNode.InnerText); if (subType == 111) { XmlNode addressInfo = device.SelectSingleNode("AddressInfo"); ITcSmTreeItem deviceToUpdate = systemManager.LookupTreeItem("TIID^EtherCAT Master"); string xmlAddress = string.Format(" {0} TreeItem>", addressInfo.OuterXml); deviceToUpdate.ConsumeXml(xmlAddress); } } Step 4: Activating the configuration The last step only involves activating the configuration on the target device.

Simply use the ITcSysManager::ActivateConfiguration() method to do that. Code Snippet (C#): sysManager.ActivateConfiguration(); Automation Interface 29 Version: 1.2