FB_RegQueryValue

FB_RegQueryValue 1:

The system registry is a hierarchically structured tree. A node in the tree is referred to as a key. Each key may contain subkeys and data values. The function block "FB_RegQueryValue" can be used to read individual system registry values from the branch with the predefined handle HKEY_LOCAL_MACHINE. If successful cbData data bytes are copied into the buffer with the address pData. The function block can be used to read any value types (e.g. REG_DWORD, REG_SZ) or binary data with unlimited byte length (REG_BINARY).

Comment:

The sSubKey and sValueName strings may not be empty!

FB_RegQueryValue 2:

HKEY_LOCAL_MACHINE\SOFTWARE\ for 64 bit operating systems

In a 64 bit Windows operating system all registry entries of and for 32 bit applications are not stored under HKEY_LOCAL_MACHINE\SOFTWARE\ but under HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\.
The function blocks FB_RegQueryValue and FB_RegSetValue work automatically below the WOW6432Node folder like any 32 bit application when a registry entry below the SOFTWARE folder is selected. The redirection is performed automatically by the operating system.

FB_RegQueryValue 3: Inputs

VAR_INPUT
    sNetId    : T_AmsNetId; 
    sSubKey   : T_MaxString;
    sValName  : T_MaxString;
    cbData    : UDINT;
    pData     : POINTER TO BYTE;
    bExecute  : BOOL;
    tTimeOut  : TIME := DEFAULT_ADS_TIMEOUT;
END_VAR

Name

Type

Description

sNetId

T_AmsNetID

A string with the network address of the TwinCAT computer whose system registry is to be read can be specified here. For the local computer an empty string may be specified.

sSubKey

T_MaxString

String with the subkey name

sValName

T_MaxString

String with the value name

cbData

UDINT

The number of value data bytes to be read.

pData

BYTE

Address of a data buffer/variable into which the value data are to be copied. The address can be determined with the ADR operator. The programmer is responsible for dimensioning the data buffer such that it can accommodate cbData data bytes.

bExecute

BOOL

The function block is enabled by a positive edge at this input.

tTimeout

TIME 

States the length of the timeout that may not be exceeded by execution of the ADS command.

FB_RegQueryValue 4: Outputs

VAR_OUTPUT
    bBusy  : BOOL;
    bError : BOOL;
    nErrId : UDINT;
    cbRead : UDINT;
END_VAR

Name

Type

Description

bBusy

BOOL

When the function block is enabled, this output is set and remains set until a feedback is received.

bError

BOOL

If an error occurs during the transmission of the command, this output is set after the bBusy output is reset.

nErrId

UDINT

Returns the ADS error number or the command-specific error code (table) when the bError output is set.

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.

Name

Type

Description

cbRead

UDINT

The number of value data bytes successfully read.

Examples:

The values AxisID and LogFilePath are to be read from the system registry.

FB_RegQueryValue 5:
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:

FB_RegQueryValue 6:

The value 0x22 of the registry was read in the PLC variable nAxisId .

Read REG_SZ-Value :

FB_RegQueryValue 7:

The string 'c:\MyProject\Log' of the registry was read in the PLC variable sValData.

Requirements

Development environment

Target platform

PLC libraries to be integrated (category group)

TwinCAT v3.1.0

PC or CX (WES7/Win7/Win10: TC RT x86/x64, WEC6/7: TC RT x86, WEC7: TC CE7 ARMV7, TC/BSD: TC RT x64, TC OS ARMT2)

Tc2_Utilities (System)