beckhoff TE1000 TwinCAT 3 — 6.7.1 Creating and handling TcCOM modules

Samples | TcCOM Setting the CreateSymbol flag for parameters The CreateSymbol (CS) flag for parameters of a TcCOM module can be set via its XML description. The following code snippet shows how to enable the CS flag for the “CallBy” parameter. Code snippet (C#): bool activateCS = true; // First step: Read all Parameters of TcCOM module instance string tempControllerXml = tempController.ProduceXml(); XmlDocument tempControllerDoc = new XmlDocument(); tempControllerDoc.LoadXml(tempControllerXml); XmlNode sourceParameters = tempControllerDoc.SelectSingleNode("TreeItem/TcModuleInstance/Module/ Parameters"); // Second step:

Build target XML (for later ConsumeXml()) XmlDocument targetDoc = new XmlDocument(); XmlElement treeItemElement = targetDoc.CreateElement("TreeItem"); XmlElement moduleInstanceElement = targetDoc.CreateElement("TcModuleInstance"); XmlElement moduleElement = targetDoc.CreateElement("Module"); XmlElement parametersElement = (XmlElement) targetDoc.ImportNode(sourceParameters, true); moduleElement.AppendChild(parametersElement); moduleInstanceElement.AppendChild(moduleElement); treeItemElement.AppendChild(moduleInstanceElement); targetDoc.AppendChild(treeItemElement); // Third step:

Look for specific parameter (in this case "CallBy") and read its CreateSymbol attribute XmlNode destModule = targetDoc.SelectSingleNode("TreeItem/TcModuleInstance/Module"); XmlNode callByParameter = destParameters.SelectSingleNode("Parameters/Parameter[Name='CallBy']"); XmlAttribute createSymbol = callByParameter.Attributes["CreateSymbol"]; createSymbol.Value = "true"; // Fifth step: Write prepared XML to configuration via ConsumeXml() string targetXml = targetDoc.OuterXml; tempController.ConsumeXml(targetXml); Code snippet (PowerShell):

$tempControllerXml = [Xml]$tempController.ProduceXml() $sourceParameters = $tempControllerXml.TreeItem.TcModuleInstance.Module.Parameters [System.XML.XmlDocument] $targetDoc = New-Object System.XML.XmlDocument [System.XML.XmlElement] $treeItemElement = $targetDoc.CreateElement("TreeItem") [System.XML.XmlElement] $moduleInstanceElement = $targetDoc.CreateElement("TcModuleInstance") [System.XML.XmlElement] $moduleElement = $targetDoc.CreateElement("Module") [System.XML.XmlElement] $parametersElement = $targetDoc.ImportNode($sourceParameters, $true) $moduleElement.AppendChild($parametersElement) $moduleInstanceElement.AppendChild($moduleElement) $treeItemElement.AppendChild($moduleInstanceElement) $targetDoc.AppendChild($treeItemElement) $destModule = $targetDoc.TreeItem.TcModuleInstance.Module $callByParameter = $destmodule.SelectSingleNode("Parameters/Parameter[Name='CallBy']") $callByParameter.CreateSymbol = "true" $targetXml = $targetDoc.OuterXml $tempController.ConsumeXml($targetXml) Setting the CreateSymbol flag for data areas The CreateSymbol (CS) flag for data areas of a TcCOM module can be set via its XML description.

The following code snippet shows how to enable the CS flag for the “Input” data area. It should be noted that this procedure is very similar to the one used for parameters. Code snippet (C#): bool activateCS = true; // First step: Read all Data Areas of a TcCOM module instance string tempControllerXml = tempController.ProduceXml(); XmlDocument tempControllerDoc = new XmlDocument(); tempControllerDoc.LoadXml(tempControllerXml); XmlNode sourceDataAreas = tempControllerDoc.SelectSingleNode("TreeItem/TcModuleInstance/Module/ DataAreas"); // Second step: Build target XML (for later ConsumeXml()) TE1000 276 Version: 1.7.0