AddVariable

Adds a user-defined variable.

Syntax

KsError AddVariable(
     UserVariable* Variable
);

Parameters

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

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
// Add an user variable in the variable table
UserVariable addVariable = { 0, L"User Control Flag", NULL, logBool };
nRet = AddVariable(&addVariable);
bool *ctrlFlag = (bool*)addVariable.Value;

if (nRet == errNoError)
{
    // Access the user variable in you application
    *ctrlFlag = true;
}

// Remove the variable if you are not going to use it anymore
nRet = RemoveVariable(addVariable.Id);

Requirements

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

See also

GetVariable

GetVariables

RemoveVariable