Calling RpcMethods and accessing PLC Properties
RpcMethods can be directly called type safe on the value dynamically read by a symbolic Read-TcValue. The RpcMethod In-/ and Out-/ Parameters are automatically marshalled to/from they .NET counterparts – so that the access is easy and transparently.
Accessing the RPC Methods needs to open an ADS Session and loading the symbolic information. Here we open a new session to the local PLC.
The ‘rpcSymbol’ object now contains the Symbol of the FB instance ‘fbRcp’.
This FB has a RpcMethod ‘AddValues’ with 2 INT parameters and a Property ‘PropInt’ defined (on the PLC side).
Information about these defined symbol instance can be browsed.
PS> $rpcSymbol
InstancePath Category DataType Size Static Persistant IG IO
------------ -------- -------- ---- ------ ---------- -- --
MAIN.fbRpc Struct FB_RpcPou 1152 False False 4040 10DEE8
Beneath Properties and Methods of the Instance base class, the ‘rpcSymbol’ contains dynamically generated access properties and methods.
PS> $rpcSymbol | Get-Member
TypeName: TwinCAT.TypeSystem.DynamicStructInstance
…
Name MemberType Definition
---- ---------- ----------
AddValues Dynamic dynamic AddValues
AddValuesAsync Dynamic dynamic AddValuesAsync
PropInt Dynamic dynamic PropInt
….
Accessing the Rpc Method metadata of the symbol:
The method can be called transparently in Powershell
The same is true for the dynamic property