TcAdsClient.InvokeRpcMethod Method (String, String, .Object.)

Invokes the RPC method.

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

Syntax

C#

public Object InvokeRpcMethod(
    string symbolPath,
    string methodName,
    Object[] parameters
)

VB

Public Function InvokeRpcMethod ( 
    symbolPath As String,
    methodName As String,
    parameters As Object()
) As Object

Parameters

symbolPath

Type: System.String
The symbol path.

methodName

Type: System.String
Name of the method.

parameters

Type: .System.Object.
The parameters.

Return Value

Type: Object
System.Object.

Implements

ITcAdsRpcInvoke.InvokeRpcMethod(String, String, .Object.)

Exceptions

Exception

Condition

NotImplementedException

Examples

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

Dynamic Tree Mode

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

InvokeRpcMethod Overload

TwinCAT.Ads Namespace