How to add routes to a remote ADS device

Adding ADS routes via the Automation Interface can be achieved by using the ConsumeXml() method. However, it is important to understand the underlying XML structure before adding routes to a remote target.

XML structure

The following snippet is a sample XML structure for adding routes to a remote target.

How to add routes to a remote ADS device 1:

Please note that you can either specify the IP address or the hostname of the remote target.

<TreeItem>
    <ItemName>Route Settings</ItemName>
    <PathName>TIRR</PathName>
    <RoutePrj>
        <TargetList>
            <!-- Triggers Broadcast search -->
            <BroadcastSearch>true</BroadcastSearch>
        </TargetList>
        <AddRoute>
            <!-- Description of the route on the remote device, can be any name -->
            <RemoteName>RouteName</RemoteName>
            <!-- AdsNetID of the remote device -->
            <RemoteNetId>1.2.3.4.5.6</RemoteNetId>
            <!-- IP Address of the remote target -->
            <RemoteIpAddr>1.2.3.4</RemoteIpAddr>
            <!-- or -->
            <!-- Hostname of the remote target -->
            <RemoteHostName>hostName</RemoteHostName>
            <!-- Username used to connect to remote device -->
            <UserName>userName</UserName>
            <!-- Password used to connect to remote device -->
            <Password>password</Password>
            <!-- Encrypt password -->
            <NoEncryption></NoEncryption>
            <!-- Description of the route on the local device, can be any name-->
            <LocalName>LocalName</LocalName>
        </AddRoute>
        <!-- Use for adding a project route -->
        <AddProjectRoute>
            <!-- Description of the route on the local device, can be any name-->
            <Name>RouteName</Name>
            <!-- AdsNetID of the remote device -->
            <NetId>1.2.3.4.5.6</NetId>
            <!-- Hostname of the remote target -->
            <HostName>hostName</HostName>
            <!-- or -->
            <!-- IP Address of the remote target -->
            <IpAddr>1.2.3.4</IpAddr>
        </AddProjectRoute>
    </RoutePrj>
</TreeItem>

Sample (C#):

The following code snippet can also be downloaded in our sample section (Sample 13). It consumes the following XML structure on the node "Route Settings":

<TreeItem>
    <ItemName>Route Settings</ItemName>
    <PathName>TIRR</PathName>
    <RoutePrj>
        <TargetList>
            <BroadcastSearch>true</BroadcastSearch>
        </TargetList>
        <AddRoute>
            <RemoteName>RouteName</RemoteName>
            <RemoteNetId>10.1.128.217.1.1</RemoteNetId>
            <RemoteIpAddr>10.1.128.217</RemoteIpAddr>
            <UserName>Administrator</UserName>
            <Password>1</Password>
            <NoEncryption/>
            <LocalName>LocalName</LocalName>
        </AddRoute>
    </RoutePrj>
</TreeItem>

Please adapt the NetIds and IP addresses to your needs.

class Program
{
   private static string_tsmPath="C:\\Temp\\Sample.tsm";
   private static TcSysManager _sysManager;
   
   static voidMain(string[]args)
   {
        _sysManager = new TcSysManager();
        _sysManager.NewConfiguration();
       
       string xmlString="<TreeItem><ItemName>Route Settings</ItemName><PathName>TIRR</PathName><RoutePrj><TargetList><BroadcastSearch>true</BroadcastSearch></TargetList><AddRoute><RemoteName>RouteName</RemoteName><RemoteNetId>10.1.128.217.1.1</RemoteNetId><RemoteIpAddr>10.1.128.217</RemoteIpAddr><UserName>Administrator</UserName><Password>1</Password><NoEncryption></NoEncryption></AddRoute></RoutePrj></TreeItem>";
        ITcSmTreeItem routesNode=_sysManager.LookupTreeItem("TIRR");
        routesNode.ConsumeXml(xmlString);
       
        _sysManager.SaveConfiguration(_tsmPath);
   }
}

See Also

How to... section, ITcSysManager, LookupTreeItem, ITcSmTreeItem, ConsumeXml