beckhoff TwinCAT 3 — 16.5 Third-party components

Appendix | Third-party components // Fifth step: Write prepared XML to configuration via ConsumeXml() $targetXml = $targetDoc.OuterXml $tempController.ConsumeXml($targetXml) Setting Context (Tasks) Every TcCOM module instance needs to be run in a specific context (task). This can be done via the ITcModuleInstance2::SetModuleContext() method. This method awaits two parameters: ContextId and TaskObjectId. Both are equivalent to the corresponding parameters in TwinCAT XAE: Please note that the TaskObjectId is shown in hex in TwinCAT XAE. Code Snippet (C#):

ITcModuleInstance2 tempControllerMi = (ITcModuleInstance2) tempController; tempControllerMi.SetModuleContext(0, 33619984); You can determine the TaskObjectId via the XML description of the corresponding task, for example: Code Snippet (C#):

ITcSmTreeItem someTask = systemManager.LookupTreeItem("TIRT^SomeTask"); string someTaskXml = someTask.ProduceXml(); XmlDocument someTaskDoc = new XmlDocument(); someTaskDoc.LoadXml(someTaskXml); XmlNode taskObjectIdNode = someTaskDoc.SelectSingleNode("TreeItem/ObjectId"); string taskObjectIdStr = taskObjectId.InnerText; uint taskObjectId = uint.Parse(taskObjectIdStr, NumberStyles.HexNumber); Linking variables Linking variables of a TcCOM module instance to PLC/IO or other TcCOM modules can be done by using regular Automation Interface mechanisms, e.g. ITcSysManager::LinkVariables(). 16.5 Third-party components | Third-party components This software contains third-party components.

Please refer to the license file provided in the following folder for further information: C:\Program Files(x86)\Beckhoff\LegalTwinCAT-XAE-CppPlatformWizard C:\Program Files(x86)\Beckhoff\LegalTwinCAT-XAE-PublicSDK TwinCAT 3 337 Version: 1.19.1