Enabling and disabling I/O devices

To disable/enable a tree item in a configuration, an instance of the TwinCAT System Manager has to be created and the configuration has to be opened. The LookupTreeItem method of the ITcSysManager interface returns a ITcSmTreeItem interface pointer implemented by the tree item referenced by its pathname. This interface contains a Disabled property of the tree item.

Procedure

The Procedure to create the ITcSysManager interface (the 'sysMan' instance here) is described in the chapter Accessing TwinCAT Configurations. This interface has a LookupTreeItem method that returns a ITcSmTreeItem pointer to a specific tree item given by its pathname. To disable/enable the tree item "TIID^EtherCAT Master" the following code snippets can be used.

Sample (CSharp):

ITcSmTreeItem item = sysMan.LookupTreeItem("TIID^EtherCAT Master");
item.Disabled = DISABLED_STATE.SMDS_DISABLED;

Please note, that, for this sample, you need to add both a reference to "Microsoft Developer Environment 10.0" and "Beckhoff TCatSysManager Library 1.1" to your project.

Sample (PowerShell):

$DISABLED_STATE = @{"SMDS_NOT_DISABLED" = "0"; "SMDS_DISABLED" = "1"}
$item = $systemManager.LookupTreeItem("TIID^EtherCAT Master")
$item.Disabled = $DISABLED_STATE.SMDS_DISABLED

Sample (VBScript):

dim dte,sln,proj,sysMan 
set dte = CreateObject("VisualStudio.DTE.10.0")
set sln = dte.Solution
call sln.Open("C:\SolutionFolder\MySolution1.sln")
set proj = sln.Projects(1)
set sysMan = proj.Object
set item = sysMan.LookupTreeItem("TIID^EtherCAT Master")
item.Disabled = SMDS_DISABLED '(oder item.Disabled = SMDS_NOT_DISABLED um Strukturelement zu aktivieren)