PLC_ReadSymInfoByName
The function block "PLC_ReadSymInfoByName" allows additional information about the PLC symbolic variables (e.g. data type identification, index group, index offset, comment...) to be read using the symbol name. After successful execution, the data is available in the SymInfo data structure, whose type is SYMINFOSTRUCT. The symbolic variables are stored as individual entries in a symbol table. The size of each entry is variable and is not limited. It is necessary to provide a data buffer of the appropriate size to read an entry in the PLC so that it can be processed by the function block. Dynamic memory allocation in the PLC is not possible at run-time. In most cases a data buffer of 1000 bytes is sufficient. The symbol entry is copied into the data buffer during execution, decoded, and the required data is copied again into the SymInfo output variable. It is not possible to read or process the entry if the data buffer is too small. The size of the buffer depends heavily on the length of the symbol name and the length of the comment in the variable definition line. After successful execution it is possible to determine the buffer size that is in fact required from the SymInfo.symEntrySize output variable.
VAR_INPUT
VAR_INPUT
NETID :T_AmsNetId;
PORT :T_AmsPort;
SYMNAME :T_MaxString;
START :BOOL;
TMOUT :TIME := DEFAULT_ADS_TIMEOUT;
END_VAR
NETID: It is possible here to provide the AmsNetId of the TwinCAT computer on which the function to be executed. If it is to be run on the local computer, an empty string can be entered.
PORT: The port number of the PLC run-time system to which the symbolic variable belongs. The first PLC run-time system has the port number 801.
SYMNAME: The symbol name of the PLC variable whose information is to be read (max. 255 characters, including the complete path, e.g. 'MAIN.INIT_TASK.VARINT').
START: The function block is activated by a positive edge at this input.
TMOUT: States the length of the timeout that may not be exceeded by execution of the ADS command.
VAR_OUTPUT
VAR_OUTPUT
BUSY :BOOL;
ERR :BOOL;
ERRID :UDINT;
SymInfo :SYMINFOSTRUCT;
END_VAR
BUSY: When the function block is activated this output is set. It remains set until and acknowledgement is received.
ERR: If an ADS error should occur during the transfer of the command, then this output is set once the BUSY output is reset.
ERRID: Supplies the ADS error number when the ERR output is set.
SymInfo: A structure with additional information on the symbolic variable.
Example of a call in FBD
PROGRAM MAIN
VAR
PLC_ReadSymInfoByName1 : PLC_ReadSymInfoByName;
bStart AT%QX0.5 : BOOL; (*Starts FB execution*)
tmpBuffer : ARRAY[1..76] OF BYTE;
bBusy : BOOL;
bError : BOOL;
iErrorId : UDINT;
SymInfo : SYMINFOSTRUCT;(*Structure with symbol information*)
END_VAR
Online View:
The data obtained in this way has the following meanings:
symEntryLen = 16#43: The actual length of the entry in the symbol table is 67 bytes;
idxGroup = 16#F031: It is a variable from the PLC process image of the physical outputs;
idxOffset = 16#5: The variable is located at byte offset zero and bit offset 5;
byteSize = 16#1: The variable's value occupies one byte in memory;
adsDataType = ADST_BIT: The ADS data type ID;
symDataType = BOOL: The data type identification in the PLC;
symComment = 'STARTS FB EXECUTION': Comment that the user has added to the variable definition line.
Requirements
Development environment | Target system type | PLC libraries to include |
---|---|---|
TwinCAT v2.7.0 | PC or CX (x86) | Standard.Lib; PLCSystem.Lib; TcPLCAds.Lib; PLCHelper.Lib; TcPlcUtilities.Lib |
TwinCAT v2.8.0 | PC or CX (x86) | TcUtilities.Lib ( Standard.Lib; TcBase.Lib; TcSystem.Lib are included automatically ) |
TwinCAT v2.10.0 Build >= 1301 | CX (ARM) |