CODESYS program access symbol configuration variable value

Posted May 29, 20201 min read

CODESYS program access symbol configuration variable value

Declare variables in the program

Suppose that two integer variables a and b are defined in the program.

PROGRAM POU
VAR
    a, b:INT;
END_VAR

The variable value is continuously increased by 1 in the program.

a:= a + 1;
b:= b + 1;

Add symbol configuration in the project

After compiling select variables a and b.
image.png

Add the necessary libraries in the library manager

image.png

Write a program to traverse the variable tree

PROGRAM POU_1
VAR
    ii:IIecVarAccess3;
    result:POINTER TO RTS_IEC_RESULT;
    ib, ic, id, ie:IBaseTreeNode;
    ii2:IIecVarAccess2;
    dest:array [0..3]of BYTE;
    x:DWORD;
    namea:POINTER TO STRING;
    addr:POINTER TO INT;

END_VAR


ii:= IecVarAccGetFirstInterface(result);
ib:= ii.VarAccBrowseGetRoot(result);
ic:= ii.VarAccBrowseDown(ib, result);
id:= ii.VarAccBrowseDown(ic, result);
ie:= ii.VarAccBrowseGetNext(id, result);
namea:= ii.VarAccGetNodeName(pNode:= ie, pResult:= result);
addr:= ii.VarAccGetAddress(ie, result);

Login to download and monitor variables

addr is the address of b, and the value it points to is the actual value of b
image.png

Related Posts