admin 发表于 2020-6-17 10:10:37

CODESYS中通过程序访问符号配置变量值

在程序中声明变量假设在程序中定义了两个整型变量a,b。PROGRAM POU
VAR   
   a,b:INT;
END_VAR程序中不断对变量值加1。
a:=a+1;
b:=b+1;


在工程中添加符号配置编译后选中变量a和b。
在库管理器中添加必要的库编写程序遍历变量树
PROGRAM POU_1
VAR   
   ii:IIecVarAccess3;   
   result:POINTER TO RTS_IEC_RESULT;   
   ib,ic,id,ie:IBaseTreeNode;   
   ii2:IIecVarAccess2;   
   dest:array 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);

登录下载,监控变量addr为b的地址,其指向的值为b的实际值









页: [1]
查看完整版本: CODESYS中通过程序访问符号配置变量值