From offline to online configurations
This article explains how to convert a TwinCAT configuration, which has been created 'offline', via TwinCAT Automation Interface to an online configuration. The term "offline" means that no physical I/Os are present at the time of configuration creation and therefore the real address information is not available, e.g. for an EtherCAT Master . The following topics are part of this article:
- General information
- Creating an offline configuration
- Switching to an online configuration
General information
When creating a TwinCAT configuration, there are two common scenarios:
- Scenario 1: this scenario is based on the real physical device, on which the TwinCAT configuration should run later. Therefore, all I/Os are online and already available and attached to the device.
- Scenario 2: this scenario could involve creating the configuration offline (that means without any I/Os attached to the engineering device) and later switch to an online configuration when the I/Os are available. This is the scenario which will be the primary focus of this article.
Both scenarios are possible via TwinCAT Automation Interface. However, as scenario 2 lacks some important information about some of the I/Os, e.g. their physical addresses, this scenario could be slightly more complex because you need to hand in the required (address) information later.
The familiar TwinCAT XAE functionality "Scan Devices" plays a significant role in this use-case because it scans for all available I/O devices and automatically attaches them to the configuration - together with all needed additional information, e.g. physical addresses.
On a physical controller, this functionality can also be called via Automation Interface and then returns an XML representation of all found I/O devices including their corresponding address information.
When a TwinCAT configuration should be activated on the controller, the required address information needs to be set for all I/O devices that are part of the configuration. This can be done by calling the "Scan Devices" functionality via Automation Interface and setting the address information for the I/O devices in the configuration. This will be explained in more detail now.
Creating an offline configuration
There are several articles which explain how to create an offline TwinCAT configuration. Please refer to our Product Description page to get an overview.
Switching to an online configuration
If you finally have created a TwinCAT configuration that should now be activated on the physical controller, the following steps need to be taken to ensure that all required address information is available before downloading the configuration:
- Step 1 [optional]: Connecting to the target device
- 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("<TreeItem><DeviceDef>{0}</DeviceDef></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();