PLC method call

Download: TwinCAT.ADS.NET_Samples.zip

The following program shows how a PLC method can be called from a .NET program via ADS. The following ficure shows that the method parameters ("params") can be transferred directly via ADS and the result ("result") is returned after execution.

PLC method call 1:

The methods are called after the execution of the PLC. The remaining computing time of the cycle is available.

Procedure

The following steps must be observed if you want to offer and call a method in the PLC:

  1. Add a method for a block.
  2. the method for the ADS access is offered via the following attribute:

{attribute 'TcRpcEnable'}

  1. Create a handle for the method for the following symbol with the syntax:

Function block_Name#Methods_Name

The method can then be called using the following ADS Read/Write command:

ADS Read/Write Parameter:

Index group: ADSIGRP_SYM_VALBYHND (0xF005)

Offset: Methods Handle (hMethod)

ReadData: ADS data with the return value of the method

WriteData: ADS data with the transfer

Constraints

If you call methods using ADS, you must note the following points:

                len : INT;
                {attribute 'TcRpcLengthIs' := 'len'}
                ptr : POINTER TO BYTE;              

Requirements

Runtime Environment

Target System

TwinCAT v3.1.0 Build 4016

PC or CX (x86, ARM)