VarTools

Version Information

This documentation is for version 0.11.2 of the VarTools library.

Description

Helper library for getting and setting variable values. To use the functions within this library the variables must be declared in a .var file as opposed to inline.

Library Specific Structures

VarVariable_typ

Name Data Type Description
name String [ ] Name of the structure
value String [ ] value of the structure in a string
address UDINT Address of structure
dataType Var_TYPE_enum datatype of structure based off VAR_TYPE_enum structure
length UDINT length of value
dimension UINT

VAR_TYPE_enum

Number Name Description
0 VAR_TYPE_STRUCT Structure
1 VAR_TYPE_BOOL Variable of type Boolean
2 VAR_TYPE_SINT Variable of type Signed Integer
3 VAR_TYPE_INT Variable of type Integer
4 VAR_TYPE_DINT Variable of type Double Integer
5 VAR_TYPE_USINT Variable of type Unsigned Integer
6 VAR_TYPE_UINT Variable of type Unsigned Integer
7 VAR_TYPE_UDINT Variable of type usigned Double Integer
8 VAR_TYPE_REAL Variable of type Real
9 VAR_TYPE_STRING Variable of type String
10 VAR_TYPE_ULINT Variable of type Unsigned Long Integer
11 VAR_TYPE_DATE_AND_TIME Variable of type Time and Date
12 VAR_TYPE_TIME Variable of type Time
13 VAR_TYPE_DATE Variable of type Date
14 VAR_TYPE_LREAL Variable of type Long Real
15 VAR_TYPE_ARRAY_OF_STRUCT Array of structures
16 VAR_TYPE_TIME_OF_DAY Variable of type Time of Day
17 VAR_TYPE_BYTE Variable of type Byte
18 VAR_TYPE_WORD Variable of type Word
19 VAR_TYPE_DWORD Variable of type Double Word
20 VAR_TYPE_LWORD Variable of type of Long Word
21 VAR_TYPE_WSTRING Variable type of
23 VAR_TYPE_LINT Variable of type Long Integer
999 VAR_TYPE_Undefined Variable type is undefined

VAR_ERR_enum

Number Name Description
14713 VAR_ERR_PVITEM_ENUM
50000 VAR_ERR_INVALIDINPUT Invalid input to function
50001 VAR_ERR_INVALIDVALUE Invalid set value
50002 VAR_ERR_UNSUPPORTEDTYPE Type of variable is not supported by this library
50003 VAR_ERR_INVALIDTYPE Invalid variable type
50004 VAR_ERR_TOO_MANY_ITEMS Too many items in structure
50005 VAR_ERR

Functions

varGetInfo

The function varGetInfo() is used to complete the varVariable-typ structure for a given process variable. The variable must have either name or address AND dataType filled out or the function will not work. If the address is 0 and the name is not specified the function will be called in an infinite loop. Please note this function will change the input structure

Parameters

Direction Name Variable Type Description
In/Out pVarVariable Pointer to varVariable-typ Pointer to the variable structure
Return status UINT Returns 0 on success

Example

testVariable := 27;

varVariable.name := 'myTask:testVariable';
pVarVariable := ADR(varVariable);

status :=  varGetInfo( pVarVariable );
//varVariable.name = 'myTask:testVariable'
// varVariable.value = '27'
// varVariable.address = 
// varVariable.dataType = 3
// varVariable.length = 2
// varVariable.dimension = 1 look it up

After the function call, the varVariable structure will be completely filled out and status will be 0.

Example

varVariable.address = 0;
pVarVariable := ADR(varVariable);
// varVariable.address = 0
// varVariable.dataType = Undefined

After the function call, the function will be called repeatedly and will return status of 0.

varGetValue

The function VarGetValue() is used to get the value within a process variable and sets the value property in the structure as a string. If address in pVarVariable is 0 the function will call varGetInfo(). varGetValue() takes one pointer to a varVariable_typ and sets the value member and returns 0 on successful completion.

Parameters

fix input name

Direction Name Variable Type Description
In pVarVariable Pointer to varVariable_typ Pointer to the structure of varVariable_typ
Return status UINT Returns 0 on successful completion of function

Example

find the function that gets task name and use it in an example

St_name();

show this somewhere else

testVariable := 27;

varVariable.name := 'myTask:testVariable';
pVarVariable := ADR(varVariable);

status :=  varGetValue( pVarVariable );
//varVariable.name = 'myTask:testVariable'
// varVariable.value = '27'

After the function call, the varVariable structure will have a value of type string filled into varVariable.value and status will equal 0.

varGetRealValue

The function varGetRealValue() is used to get the value property of the varVariable_typ structure as a REAL. This function takes two inputs the first is a pointer to the varVariable_typ structure with the REAL value as a string, the second is pointer to the REAL variable converted string will be stored. If there is no address assigned to the varVariable_typ structure the function will first call varGetInfo() before proceeding to further steps.

Parameters

Direction Name Variable Type Description
In pVarVariable Pointer to varVariable_typ Pointer to the structure of varVariable_typ
Out pValue Pointer to REAL Pointer to the value to be returned
Return status UINT Returns 0 on success

Example

value := 0;
pValue := ADR(value);
varVariable.value := '23777567';
pVarVariable := ADR(varVariable);

varGetRealValue(pVarVairable, pValue);

After the function call, value will be have 23777567 varVariable.value will be untouched and return 0 on successful completion of function.

varSetValue

The function varSetValue() is used to set the value of a process variable from the value property of a varVariable_typ structure. This function takes one variable that contains a pointer to the varVariable_typ structure. If there is no address assigned to the varVariable_typ structure the function will first call varGetInfo() before proceeding to further steps.

Parameters

Direction Name Variable Type Description
In pVarVariable Pointer to varVariable_typ Pointer to the structure of varVariable_typ
Return status UINT Returns 0 on successful completion of function

Example

testVar := 0;
varVariable.name := 'myTask:testVar';
varVariable.value := '909';
pVarVariable := ADR(varVariable);

status := varSetValue(pVarVariable);

After the function call, varVariable.value will remain unchanged, testVar will be 909 status will be 0.

varGetVariableList

The function varGetVariableList() is used to get a list of all local and global variables with a given name specified in pVariableName. This function takes two inputs. The first is a pointer to a STRING and the second is a pointer to a string array. The list will be returned in alphabetical order. Capitalization will matter for searching purposes. Please note global variables must start with a ‘g’ to be found.

Parameters

Direction Name Variable Type Description
In pVariableName Pointer to varVariable_typ Pointer to a String containing name of variable to search for
Out pList String[VAR_STRLEN_NAME][0..VAR_MAI_VARLIST] Pointer to an array size VAR_MAI_VARLIST+1 (50) of Strings length VAR_STRLEN_NAME (120)
Return numVarFound UINT Returns number of variables found

Example

variableName := 'Configuration';
pList := ADR(list);

numVarFound := varGetVariableList( &variableName , pList);
//list[0] := 'myTask:Configuration';
//list[1] := 'gConfiguration';

After the function call, varVariable will be unchanged, list will contain strings of all local and global variables matching ‘Configuration’ and numVarFound will be 2;

varVariableWatch

The function block varVariableWatch() is used to monitor a variable’s value property. The main difference between this function block and varGetValue is that it will monitor the name property for changes.

Parameters

Direction Name Variable Type Description
In pVarVariable Pointer to a varVariable_typ Point to varVariable
Out status UINT 0 on successful completion of function

Example

varVariable.name := 'exampleVar';
varVariableWatchInst.pVariable := ADR(varVariable);

varVariableWatchInst();

After the function call the uses will be able to see name, value.

varPopulateMemberNames

This is a utility function primarily used by the ATN library. It takes in as its first parameter the name of an existing global structure, and populates all of that structure’s children with string values equal to the names of their variables. The second parameter is an optional prefix length that will strip out the first n characters of the string when assigning the final value to the PV.

Parameters

Direction Name Variable Type Description
In PVName STRING Name of the structure to target
In prefix USINT Length of prefix string to strip out
Out status BOOL 0 on successful completion of function

Example


varPopulateMemberNames('gCommandsApi', 0);

variableBrowser

The function block varVarVariableBrowser() is used to cyclically monitor the value within a varVariable_typ structure. This function allows for monitoring and updating members of an Array or Structure, which is not supported by varGetValue() or varSetValue(). This function block has three inputs pVariable which points at the varVariable_type address, the index of the varVariable_type to be manipulated, and a BOOL that allows for moving up levels within a structure. Parameters

Direction Name Variable Type Description
In VariableName String Name of the varVariableType
In MemberIndex INT Index of varVariabe_type.value
In Back BOOL Boolean for moving up a level in a structure
Out CurrentVariable String Name of varVariable_typ currently being evaluated
Out MemberName String Name of index currently being evaluated
Out MemberValue String Vale with in the member as a String
Out MemberInfo varVariable_typ[0..(NumberMembers - 1)] An Array of all member’s variable information
Out NumberMembers UINT Number of members in Array or Structure
Out info UINT Current variable information

Example

exampleArray[0] := 'test_1';
exampleArray[1] := 'test_2';


VariableWatchInst.pVariable := 'exampleArray';
VariableWatchInst.MemberIndex := UserInput; //-1
VariableWatchInst.Back := UserOption; //false

VariableWatchInst();

After this function call the user would see:

  • VariableWatchInst.CurrentVariable = ’exampleArray’
  • VariableWatchInst.MemberName = [’exampleArray[0]’, ’exampleArray[1]’]
  • VariableWatchInst.MemberValue = [’test_1’, ’test_2']
  • VariableWatchInst.MemberInfo = [{ name: “exampleArray[0]”, value: ’test_1' }, { name: “exampleArray[1]”, value: ’test_2' } ]
  • VariableWatchInst.NumberMembers = 2
  • VariableWatchInst.info = {name: “exampleArray”, value: ‘’, dimension: 1}
// Example continued
VariableWatchInst.MemberIndex := UserInput; //1

VariableWatchInst();

After this function call the user would see:

  • inst.CurrentVariable = ’exampleArray[0]’
  • inst.MemberName = ''
  • inst.MemberValue = ''
  • inst.MemberInfo = ''
  • inst.NumberMembers = 0
  • inst.info = {name: “exampleArray[1]”, value: ’test_2’, dimension: 1}