beckhoff TE1000 TwinCAT 3 — 6.7.2 Using GetModulePara in C#

Samples | TcCOM Keep in mind that the TaskObjectId is displayed in hexadecimal format in TwinCAT XAE. Code snippet (C#): ITcModuleInstance2 tempControllerMi = (ITcModuleInstance2) tempController; tempControllerMi.SetModuleContext(0, 33619984); You can determine the TaskObjectId from 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 Variables from a TcCOM module instance can be linked to PLC/IO or other TcCOM modules using the standard mechanisms of the Automation Interface, such as ITcSysManager::LinkVariables().

6.7.2 Using GetModulePara in C# | Using GetModulePara in C# A TcCOM object makes its parameters available through the ITcModuleInstance interface. Each parameter is addressed via a numeric **parameter ID (PID)**, which is derived from the module's TMC description. This article shows how to read parameter values using the Automation Interface in C# and correctly convert them to the appropriate .NET type. The key issue is that GetModulePara returns the data as raw, untyped bytes. Without knowing the parameter type, these bytes cannot be interpreted meaningfully. The following three rules show how to obtain the correct value depending on the situation.

Requirements This requires an open TwinCAT project containing a TcCOM object whose Tree Item already exists. In the samples, treeItem is the object obtained via LookupTreeItem , which is cast to ITcModuleInstance : var mi = (ITcModuleInstance)treeItem; The pid used (e.g., 0x050300B1 ) is the parameter ID from the module's TMC description. What GetModulePara returns GetModulePara returns a VARIANT that contains a byte array with VT_ARRAY | VT_UI1 . These are raw bytes in little-endian format, without any type information. In C#, this VARIANT returned as a byte[] . TE1000 278 Version: 1.7.0