AddVariableEx

Adds a user-defined variable to a specified folder.

Syntax

KsError AddVariableEx(
     UserVariable* Variable,
     HANDLE Parent
);

Parameters

Variable: the variable you want to add. See the UserVariable structure.

Parent: the parent folder of UserVariable. Input NULL if you want to add variables to the root folder. Use AddVariableEx(&VAR1, DIR.Id) if you want to add variables to a specific folder.

Return value

If the function succeeds, it returns errNoError, otherwise an error code. For more information about the error code, see the KsError list.

Remarks

Usable EtherCAT states

ecatOffline, ecatInit, ecatBoot, ecatPreOP, ecatSafeOP, ecatOP

Example

Copy
    // Create directory
    UserVariable dir0 = { 0 };
    int size = 128;

    dir0.Type = KsLogDataType::logDirectory;
    dir0.Value = IntToPtr(size);
    swprintf_s(dir0.Name, L"DIR%d", 0);

    auto errorId = AddVariableEx(&dir0, nullptr);
    if (errorId != KsError::errNoError)
        RtPrintf("[ERROR] Create directory.0, ErrorId: 0x%x\n", errorId);

    // Add variable to directory
    std::vector<UserVariable> addedVars = std::vector<UserVariable>(size, { 0 });

    for (int i = 0; i < size; ++i)
    {
        addedVars[i].Type = KsLogDataType::logDouble;
        swprintf_s(addedVars[i].Name, L"VAR%d", i);

        errorId = AddVariableEx(&addedVars[i], dir0.Id);
        if (errorId != KsError::errNoError)
            RtPrintf("[ERROR] Add variable.%d, ErrorId: 0x%x\n", i, errorId);
    }

Requirements

  RT Win32
Minimum supported version 4.4 4.4
Header ksapi.h ksapi.h
Library KsApi_Rtss.lib KsApi.lib

See also

AddVariable

GetVariable

GetVariableEx

GetVariables

GetVariablesEx

RemoveVariable