TcAdsClient.CreateSymbolInfoLoader Method

TcAdsClient.CreateSymbolInfoLoader Method 1:

Obsolete

This API is now obsolete.

Creates a new instance of the TcAdsSymbolInfoLoader class (Symbol Browser V1, obsolete).

Namespace:  TwinCAT.Ads
Assembly:  TwinCAT.Ads (in TwinCAT.Ads.dll) Version: 4.3.0.0

Syntax

C#

[ObsoleteAttribute("For new code use the SymbolLoaderFactory.Create method instead!", 
    false)]
public TcAdsSymbolInfoLoader CreateSymbolInfoLoader()

VB

<ObsoleteAttribute("For new code use the SymbolLoaderFactory.Create method instead!", 
    false)>
Public Function CreateSymbolInfoLoader As TcAdsSymbolInfoLoader

Return Value

Type: TcAdsSymbolInfoLoader
Instance of the TcAdsSymbolInfoLoader class.

Remarks

This is the traditional way of accessing symbol information from the target device that is still supported here for backward compatibility. For new implementations please consider to use the new symbol browsing capabilities accessed by the SymbolLoaderFactory class (Create(IConnection, ISymbolLoaderSettings) method).

Examples

Create SymbolLoader V1 object

using System;
using System.Diagnostics;
using TwinCAT.Ads;
using TwinCAT.TypeSystem;

namespace Sample
{
    class SymbolBrowserProgramV1
    {
    /// <summary>
    /// Defines the entry point of the application.
    /// </summary>
    /// <param name="args">The arguments.</param>
    static void Main(string[] args)
    {
        ConsoleLogger logger = new ConsoleLogger();
        //logger.Active = false;

        Console.WriteLine("");
        Console.WriteLine("Press [Enter] for Start:");
        Console.ReadLine();

        Stopwatch stopper = new Stopwatch();

        //Parse the AmsAddress from command-line arguments
        AmsAddress address = ArgParser.Parse(args);
        stopper.Start();

        // Create the ADS Client
        using (TcAdsClient client = new TcAdsClient())
        {
        // Establish Connection
        client.Connect(address);

        // Create Symbol / DataType Loader
#pragma warning disable 0618
        TcAdsSymbolInfoLoader loader = client.CreateSymbolInfoLoader();
#pragma warning restore 0618

        // Determine List of used DataTypes.
        ReadOnlyTcAdsDataTypeCollection dataTypes = loader.GetDataTypes(false);

        // Determine List of contained symbols
        TcAdsSymbolInfoCollection symbols = loader.GetSymbols(false);

        // Dump Datatypes from Target Device
        Console.WriteLine(string.Format("Dumping '{0}' DataTypes:", dataTypes.Count));

        // Iterate through types and Dump Content
        foreach (ITcAdsDataType dataType in dataTypes)
        {
            logger.DumpType(dataType);
        }

        // Dump Symbols from target device
        Console.WriteLine("Dumping '{0}' Symbols:", symbols.Count);

        // Iterates through symbols and Dump Content
        foreach (ITcAdsSymbol5 symbol in symbols)
        {
            logger.DumpSymbol(symbol,0);
        }

        stopper.Stop();
        TimeSpan elapsed = stopper.Elapsed;
        Console.WriteLine("");
        Console.WriteLine("Browsing complete tree: {0},({1} DataTypes, {2} Symbols)", elapsed, logger.DataTypesCount, logger.SymbolsCount);

        Console.WriteLine("Press [Enter] for leave:");
        Console.ReadLine();
        }
    }
    }
}

Examples

The following sample shows how to call (Remote Procedures / Methods) within the PLC directly from the TcAdsClient class.

RPC Call Example

namespace Sample
{
    using System;
    using System.Diagnostics;
    using TwinCAT.Ads;
    using TwinCAT.TypeSystem;

    class RpcCallV1Program
    {
    /// <summary>
    /// Defines the entry point of the application.
    /// </summary>
    /// <param name="args">The arguments.</param>
    static void Main(string[] args)
    {
        //Parse the AmsAddress from command-line arguments
        AmsAddress address = ArgParser.Parse(args);

        // Create the ADS Client
        using (TcAdsClient client = new TcAdsClient())
        {
        // Establish Connection
        client.Connect(address);

        // Call a Method that has the following signature (within MAIN Program)

        /*  {attribute 'TcRpcEnable'}
            METHOD PUBLIC M_Add : INT
            VAR_INPUT
            i1 : INT := 0;
            i2 : INT := 0;
            END_VAR 
        */

        short result = (short)client.InvokeRpcMethod("MAIN", "M_Add", new object[] {(short)1, (short)4});

        // Call a Method that has no parameter and returns VOID
        client.InvokeRpcMethod("MAIN", "M_Method1", new object[] {});
        }
    }
    }
}

Reference

TcAdsClient Class

TwinCAT.Ads Namespace