FB_RegQueryValue
The System registration is a hierarchical structured tree. A node in the tree is called key. Each Key again can contain SubKeys, and Values.
With the function block "FB_RegQueryValue" single key values can be read from the system registry from the branch with the predefined handle HKEY_LOCAL_MACHINE. If this was successfull, the cbData- data bytes will be copied in the buffer with the address pData .
With the function block any value types (e.g. REG_DWORD, REG_SZ) or unlimited binary data (REG_BINARY) can be read.
Comment:
Empty sSubKey and sValueName strings are not allowed!
VAR_INPUT
VAR_INPUT
sNetId :T_AmsNetId;
sSubKey :T_MaxString;
sValName :T_MaxString;
cbData :UDINT;
pData :UDINT;
bExecute :BOOL;
tTimeOut :TIME := DEFAULT_ADS_TIMEOUT;
END_VAR
sNetId: Here a string containing the network address of the TwinCAT Computer can be given, whose system registration should be read. The string can also be empty for the local computer.
sSubKey: String with SubKey name.
sValName: String with value name.
cbData: Number of value data bytes to be read.
pData: Address of a data buffer/variables to which the value data should be copied. The address can be ascertained from the ADR-Operator. The programmer himself is responsible for the dimension of the data buffer:.it must be possible to take cbData data bytes into the buffer.
bExecute: The command is executed with a positive edge at the input
tTimeOut: Maximum time allowed for the execution of the ADS command.
VAR_OUTPUT
VAR_OUTPUT
bBusy :BOOL;
bError :BOOL;
nErrId :UDINT;
cbRead :UDINT;
END_VAR
bBusy: When the function block is activated this output is set. It remains set until and acknowledgement is received.
bError: If an ADS error should occur during the execution of the command, then this output is set, after the bBusy output has been reset.
nErrId: When the bError output is set, this variable supplies the ADS error or the command-specific error code (table).
cbRead: Number of successfully read value data bytes.
Error codes | Error description |
---|---|
0x00 | no error |
0x01 | The key with the name sSubKey could not be opened/found. |
0x02 | The key value with the name sValName could not be opened/found. |
Examples:
The values AxisID and LogFilePath should be read from the system Registry.
PROGRAM MAIN
VAR
fbRegQueryValue : FB_RegQueryValue;
bRead : BOOL;
bBusy : BOOL;
bError : BOOL;
nErrId : UDINT;
cbRead : UDINT;
sValData : STRING;
nAxisID : DWORD;
END_VAR
Read REG_DWORD-Value:
The value 0x22 of the registry was read in the PLC variable nAxisId .
Read REG_SZ-Value :
The string 'c:\MyProject\Log' of the registry was read in the PLC variable sValData.
Requirements
Development environment | Target System | PLC libraries to include |
---|---|---|
TwinCAT v2.7.0 Build > 519 | PC or CX (x86) | Standard.Lib; PLCSystem.Lib; TcPLCAds.Lib; PLCHelper.Lib; TcPlcUtilities.Lib |
TwinCAT v2.8.0 Build > 723 | PC or CX (x86) | TcUtilities.Lib ( Standard.Lib; TcBase.Lib; TcSystem.Lib are included automatically ) |
TwinCAT v2.10.0 Build >= 1301 | CX (ARM) |