FB_ReadAdsSymByName

FB_ReadAdsSymByName 1:

The function block enables reading of any value from another controller using the symbol name.

On a positive edge at the bRead input the function block reads the value of the variable sVarName from the selected ADS device (e.g. PLC). The ADS device is indicated by the AMS-NetId (sNetId) and the AMS Port number (nPort). The value is written into the variable to which nDestAddr points.

The internal mode of operation of the function block can be changed with the aid of the eComMode input:

  • eComMode := eAdsComModeSecureCom: Following each read procedure the handle of the PLC variable is released again. This mode should be used when values are exchanged very slowly.
  • eComMode := eAdsComModeFastCom: As long as the sVarName, sNetID and nPort inputs do not change, the handle of the PLC variable will not be released after each read procedure. This mode should be used when values are exchanged very frequently.

VAR_INPUT

VAR_INPUT
    bRead            :  BOOL;
    sNetId           :  T_AmsNetId;
    nPort            :  T_AmsPort := 851;
    sVarName         :  STRING (255);
    nDestAddr        :  PVOID;
    nLen             :  UDINT;
    tTimeout         :  TIME := DEFAULT_ADS_TIMEOUT;
    eComMode         :  E_AdsComMode := eAdsComModeSecureCom;
END_VAR

bRead: The function block reads the content of the variables sVarName of the selected ADS devices and writes it to the variable to which the pointer nDestAddr points.

sNetId: AMS-NetId of the ADS device from which the value is to be read. (Type T_AmsNetId)

nPort: AMS Port number of the ADS device from which the value is to be read. (Type T_AmsPort)

sVarName: Symbol name of the variable to be read on the selected ADS device (max. 255 characters).

nDestAddr: Address of the variable into which the read value is written.

nLen: Length of the variable to be read in bytes.

tTimeout: Time until processing is aborted.

eComMode: Enum used to specify whether the handle of the PLC variable is released again after each read procedure.

VAR_OUTPUT

VAR_OUTPUT
    bBusy     :  BOOL;
    bError    :  BOOL;
    nErrorId  :  UDINT;
END_VAR

bBusy: The transmission is active.

bError: An error occurred during the transmission.

nErrorId: ADS error number if an error has occurred.

Requirements

Development environment

required TC3 PLC library

TwinCAT v3.1.0

Tc2_DataExchange