AdsClient.InvokeRpcMethod Method (String, String, .Object., .AnyTypeSpecifier., AnyTypeSpecifier, .Object..)

Invokes the specified RPC Method

Namespace:  TwinCAT.Ads
Assembly:  TwinCAT.Ads (in TwinCAT.Ads.dll) Version: 5.0.294+Branch.releases-5.0.Sha.90bb9a1b43b6095934fddca3e72bc0ea15da1c14

Syntax

C#

public Object InvokeRpcMethod(
    string symbolPath,
    string methodName,
    Object[] inParameters,
    AnyTypeSpecifier[] outSpecifiers,
    AnyTypeSpecifier retSpecifier,
    out Object[] outParameters
)

Parameters

symbolPath

Type: System.String
The symbol path.

methodName

Type: System.String
The method name.

inParameters

Type: .System.Object.
The parameters.

outSpecifiers

Type: .TwinCAT.TypeSystem.AnyTypeSpecifier.
The out specifiers (specifiying the out types) or NULL.

retSpecifier

Type: TwinCAT.TypeSystem.AnyTypeSpecifier
The ret specifier (specifiying the return value) or NULL.

outParameters

Type: .System.Object..
The out parameters.

Return Value

Type: Object
The return value of the Method (as object).

Implements

IAdsRpcInvoke.InvokeRpcMethod(String, String, .Object., .AnyTypeSpecifier., AnyTypeSpecifier, .Object..)

Remarks

The RpcMethod optionally support In-Parameters, Out-Parameters and Return values. Therefore the parameters inParameters, outParameters, outSpecifiers, retSpecifier are allowed to be empty or NULL. In case of using primitive datatypes, the type specifier parameters (outSpecifiers and retSpecifier) are not necessary and should not be set.

Examples

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

Dynamic Tree Mode

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

    using (AdsClient client = new AdsClient())
    {
        //client.Synchronize = false;

        // Connect to the target device
        client.Connect(address);

        SymbolLoaderSettings settings = new SymbolLoaderSettings(SymbolsLoadMode.VirtualTree);
        ISymbolLoader loader = SymbolLoaderFactory.Create(client, settings);

        // Get the Symbols (Dynamic Symbols)

        IRpcStructInstance main = (IRpcStructInstance)loader.Symbols["MAIN"]; // Gets the MAIN Instance of the PLC Program

        // 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)main.InvokeRpcMethod("M_Add", new object[] {(short) 3, (short) 4});

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

        //Browsing RpcMethods
        foreach(IRpcMethod method in main.RpcMethods)
        {
        string methodName = method.Name;

        foreach(IRpcMethodParameter parameter in method.Parameters)
        {
            string parameterName = parameter.Name;
            string parameterType = parameter.TypeName;
        }
        }
    }
    }
}

Reference

AdsClient Class

InvokeRpcMethod Overload

TwinCAT.Ads Namespace