OPC服务器:启动停止暂停getData再次使用DYMOLA MATLAB

问题描述

我正在使用Dymola OPC服务器

DYMOLA具有许多可以使用SimControl.Run,​​SimControl.Stop等控制的标签

enter image description here

在这里我用MATLAB写的

hostInfo = opcserverinfo('localhost');
da = opcda('localhost','Dymosim.OPCServer.1');
connect(da);
fprintf("CONNECTED\n");
grp=addgroup(da,'Demo');
itmIDs={'ModelVariables.Tco','ModelVariables.der(Tco)'};
itm=additem(grp,itmIDs);
area=additem(grp,{'ModelVariables.Area'});
set(grp,'Updaterate',0.2,'RecordsToAcquire',50);
start(grp);
wait(grp);
[logIDs,Tco]=getdata(grp,'double'); // PREVIoUS ONE
Now I want to change/write  value to area so what I did is this
write(area,23);

现在我要重新记录或获取数据

NEWTco=read(itm,'device').Value; //using This I can read one instance
[NewlogIDs,NewTco]=getdata(grp,'double');// GIVES ERR

enter image description here

解决方法

写这个帮助我解决了这个问题

grp2=addgroup(da,'Demo2');
Run=additem(grp2,{'SimControl.Run'});
Status=additem(grp2,{'SimControl.Status'});
Stop=additem(grp2,{'SimControl.Stop'});
Pause=additem(grp2,{'SimControl.Pause'});

RunStatusBefore=read(Run,'device');
StatusBefore=read(Status,'device').Value;
StopStatusBefore=read(Stop,'device');
PauseStatusBefore=read(Pause,'device');

write(Initialize,1);  //INITITALIZE
write(Run,1);  // RUN
write(Stop,1);  // STOP
write(Pause,1);  // PAUSE