ITcSmTreeItem::CreateChildITcSmTreeItem
Creates a child itemon a parent node. The childis being specified by it'ssubtype.
HRESULT CreateChild(BSTRbstrName,long nSubType, BSTRbstrBefore, VARIANT vInfo,ITcSmTreeItem**pipItem);
The following example demonstrates this behavior in better detail.
In this example, an EK1100 coupler is being added to an EtherCAT Master device (Device 1) in TwinCAT XAE. In Automation Interface, this could be done with the CreateChild() method. The parent node (Device 1 EtherCAT) has the item type '2' (TREEITEMTYPE_DEVICE). The sub type specifies the child item and therefore the EK1100, which is sub type '9099' (BOXTYPE_EXXXXX).
Parameters
bstrName | [in] Item name of the new child item. |
nSubType | [in]Sub type of the new child item. The usable sub type depends on theitem type(the category)of theparenttree item. For example, a PLC Functionblock may only be added to the item type PLCFOLDER and not to a DEVICE. |
bstrBefore | [in, defaultvalue("")] If set, the parameter contains the name of another child item before that the new item should be inserted. |
vInfo | [in, optional] An optional parameter with additional creation information, whichdepends on the sub type.The different dependencies are listed in the table below. |
pipItem | [out, retval] Points to the location of a ITcSmTreeItem interface pointer that receives the result. |
Return Values
S_OK | function returns successfully. |
E_POINTER | the location of the returning pointer is invalid |
TSM_E_INVALIDITEMSUBTYPE (0x98510003) | the given sub type is invalid. |
TSM_E_ITEMNOTFOUND (0x98510001) | The item bstrBefore was not found. |
Optional vInfo parameter
Depending on theitem subtypeof the new child item,someadditional informationmay berequiredto create the child item. This information can be provided via the vInfo parameter.
Child: Item sub type | vInfo parameter(s) |
---|---|
E-Bus box / terminal / module (item sub type 9099) | Contains the Identity Object (CoE 1018h, VendorId, ProductCode and optional RevisionNo and SerialNo) of the EtherCAT box. The type of the variant must be an array of LONG (VT_I4|VT_ARRAY, 2-4 elements). Alternatively contains a BSTR of the following formats (with %X = value in hex notation, e.g. "V00000002_P044c2c52_R00000000"):
Especially for Beckhoff E-Bus terminals / modules, please read the corresponding E-Bus article. |
Interbus box. (item sub type 2002) | Contains the IdentCode and LengthCode of the Interbus box. The type of the variant must be an unsigned short (VT_I2), the low byte contains the IdentCode the high byte the LengthCode. |
AX2000 (item sub type 5007) | Optionally contains a bool value (VT_BOOL) and if set an additional variable for the `Following Error`will be created. |
DeviceNET (item sub type 5203) | Optionally contains the file path to an EDS file (VT_BSTR). |
BK3000 and all other PROFIBUS box types | Optionally contains the file path to an GSD file (VT_BSTR). |
Variable | Optionally contains the bit address of the new variable. The type of the variant can be a SHORT or a LONG (VT_I2 or VT_I4). |
PLC POU Functionblock (item sub type 604) | Contains IEC language type as Integer, as defined by IECLANGUAGETYPES. |
PLC POU Function (item sub type 603) | Contains a string[2] array, which hols the following values:
|