Samples | System Step 2: Scanning the device for available I/Os Step 3: Iterating through XML and configuring address information of I/Os Step 4: Activating the configuration Of course, you can also always create an online configuration directly by using the ScanDevices functionality. There is an own sample which shows you exactly how to do that. Step 1 [optional]: Connecting to the target device If the physical controller is not located on the same machine as the Automation Interface code runs on, you can use the ITcSysManager::SetTargetNetId() method to connect to the remote device and then continue with the next steps. Step 2:
Scanning the device for available I/Os The "Scan Devices" functionality mentioned above can be triggered via Automation Interface by calling the ITcSmTreeItem::ProduceXml() method on the I/O devices node. 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} ", 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(); 6.3.5 Connecting to the Automation Interface via DTE | Connecting to the Automation Interface via DTE The Automation Interface is accessed via the DTE object in Visual Studio or TcXaeShell. DTE stands for Development Tools Environment. The DTE is the top-level automation object in the IDE: You can access the individual projects via dte.Solution.Projects , and the TwinCAT project provides the entry point ITcSysManager through its Object property.
This article shows you how to set up a connection to an instance that is already running and obtain the ITcSysManager interface. TE1000 202 Version: 1.7.0