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.
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:
- Add a method for a block.
- the method for the ADS access is offered via the following attribute:
{attribute 'TcRpcEnable'}
- 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:
- CPU time: If the methods require more processing time than is available, real-time overruns can occur.
- Breakpoints: Are not supported within the methods and can generate exceptions.
- Pointer: If a pointer points to an array of elements, the attribute TcRpcLengthIs can be used to specify the length.
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) |