Infosys在阅读器中打开 / AI 翻译

Automation Interface · 0 次阅读

How to update the address information of I/O devices

Requirements

To update the address information of I/O devices in a configuration, an instance of the TwinCAT System Manager must be created, and a configuration must be opened. A call to the ProduceXml method of the "I/O devices" tree item retrieves the current address information of all installed I/O devices (internally by calling the scan devices function). This address information can be used to update a specific I/O device in the configuration.

Procedure

The ProgId "TCatSysManager.TcSysManager" can be used to create an instance of the System Manager that implements the ITcSysManager interface. This interface has a LookupTreeItem method that returns a ITcSmTreeItem pointer to the "I/O Devices" tree item (use the abbreviation "TIID"). 

Sample (vbscript):

Set tsm = CreateObject("TCatSysManager.TcSysManager")
Call tsm.OpenConfiguration("c:\test.wsm")
Set Item = tsm.LookupTreeItem("TIID")
Set xml = CreateObject("Msxml.DOMDocument")

The following call to Item.ProduceXml scans the installed I/O devices (among other things) and returns a XML string that contains these information that will be stored in the XML document by the method xml.loadXml.

Call xml.loadXml(Item.ProduceXml)

The following line sets a DOM node list object that contains all found devices as DOM nodes

Set devs = xml.selectNodes("TreeItem/DeviceGrpDef/FoundDevices/Device")
For i = 0 To devs.length - 1

If the ItemSubType of the device corresponds to the type of device to update...

    If devs(i).selectSingleNode("ItemSubType").nodeTypedValue = 48 Then
        ' 48 = IODEVICETYPE_FC7500

The AddressInfo node of that device will be extracted

        Set ainfo = devs(i).selectSingleNode("AddressInfo")

A ITcSmTreeItem pointer of that device in the configuration will be evaluated

        Set dev = tsm.LookupTreeItem("TIID^MyDev")

And finally the address info will be stored to the device

       Call dev.ConsumeXml(ainfo.xml)
       Call tsm.SaveConfiguration
       Exit For
    End If
Next