beckhoff TwinCAT 3 — 16.4 Creating and handling TcCOM modules

Appendix | Creating and handling TcCOM modules ... Let’s assume that we already own a TcCOM module that is registered in and detectable by TwinCAT. We now would like to add this TcCOM module, which has the GUID {8F5FDCFF- EE4B-4EE5-80B1-25EB23BD1B45} to our TwinCAT configuration. This can be done by the following way: Code Snippet (C#): Dictionary tcomModuleTable = new Dictionary (); tcomModuleTable.Add("TempContr",Guid.Parse("{8f5fdcff-ee4b-4ee5-80b1-25eb23bd1b45}")); ITcSmTreeItem tempController = tcComObjects.CreateChild("Test", 0, "", tcomModuleTable["TempContr"]); Code Snippet (Powershell):

$tcomModuleTable = @{} $tcomModuleTable.Add("TempContr", "{8f5fdcff-ee4b-4ee5-80b1-25eb23bd1b45}") $tempController = $tcComObjects.CreateChild("Test", 0, "", $tcomModuleTable["TempContr"]) Please note that the vInfo parameter of the method ItcSmTreeItem::CreateChild() contains the GUID of the TcCOM module which is used to identify the module in the list of all registered TcCOM modules in that system. This name can be used to add a TcCOM module to a TwinCAT configuration via the ITcSmTreeItem::CreateChild() method. The name can be determined in TwinCAT XAE via the TMC Editor. This can be done by the following way: Code Snippet (C#):

ITcSmTreeItem tempController = tcComObjects.CreateChild("Test", 1, "", "NewModule"); Code Snippet (Powershell): $tempController = $tcComObjects.CreateChild("Test", 0, "", "NewModule") Iterating through added TcCOM modules To iterate through all added TcCOM module instances, you may use the ITcModuleManager2 interface. The following code snippet demonstrates how to use this interface. Code Snippet (C#):

ITcSysManager3 sysManager3 = sysManager as ITcSysManager3; ITcModuleManager3 moduleManager = sysManager3.GetModuleManager() as ITcModuleManager3; foreach (ITcModuleInstance2 moduleInstance in moduleManager) { string moduleType = moduleInstance.ModuleTypeName; string instanceName = moduleInstance.ModuleInstanceName; Guid classId = moduleInstance.ClassID; TwinCAT 3 334 Version: 1.19.1