FB_RegSetValue

FB_RegSetValue 1:

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_RegSetValue" single key values, or new SubKey names and Values can be written resp. generated in a branch with the predefined handle HKEY_LOCAL_MACHINE. Any value types (e.g. REG_DWORD, REG_SZ) or maximum 500 byte binary data (REG_BINARY) can be written in the system registry. If a key value doesn´t exist yet, a new one will be created automatically.

Comment:

Empty sSubKey and sValueName strings are not allowed!

 VAR_INPUT

VAR_INPUT
    sNetId      :T_AmsNetId;   
    sSubKey     :T_MaxString; 
    sValName    :T_MaxString;
    eValType    :E_RegValueType;
    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 written. The string can also be empty for the local computer.

sSubKey: String with SubKey  name.

sValName: String with value name.

eValType: Data type format of  of the registration data to be written e.g. REG_DWORD or REG_SZ. 

cbData: Number of value data bytes to be written (at string variables inclusive the terminal zero).

pD ata:  Address of a data buffer/PLC variables, which contains the value data. 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 from 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;
    cbWrite     :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). 

cbWrite: Number of successfully written 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.

 

Example:

A Subkey SOFTWARE\MyCompany\MyProject' witt the key name 'LogFileName' , the type REG_SZ and the value 'c:\MyProject\Log'' should be created and set in the branch with the predefined handle HKEY_LOCAL_MACHINE.

PROGRAM MAIN
VAR
    fbRegSetValue   : FB_RegSetValue;
    bBusy           : BOOL;
    bError          : BOOL;
    nErrId          : UDINT;
    cbWrite         : UDINT;
    bWrite          : BOOL;
    sNewValue               : STRING := 'c:\MyProject\Log';
END_VAR

FB_RegSetValue 2:

FB_RegSetValue 3:

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)