4

I am using a Dymola OPC server

DYMOLA HAS these many tags which can be controlled using SimControl.Run, SimControl.Stop ,etc enter image description here

here i wrote it in 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);

Now I want to Relog or getdata

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

enter image description here

Rohit gupta
  • 211
  • 3
  • 18
  • Please do say why voted down so I can make it good next time, – Rohit gupta Nov 12 '20 at 14:26
  • 1
    I don't know who downvoted, but running Dymosim from OMShell seems odd. And the model has no inputs, so it's not clear if you mean changing parameters using OPC or having actual inputs. – Hans Olsson Nov 12 '20 at 15:52
  • 1
    If I understand you want to change the initial conditions of the model? If so, the easiest would be to add additional parameters and then set them in an initial equation block or using start= – Scott G Nov 12 '20 at 22:06
  • Thanks a lot @HansOlsson after looking and reading more I get to this point and got stuck here , – Rohit gupta Nov 12 '20 at 23:31
  • Seems to be a bit unfortunate timing, but Dymola 2021x discontinued OPC support: https://www.3ds.com/fileadmin/PRODUCTS/CATIA/DYMOLA/PDF/Dymola-2021x-release-notes.pdf -> page 46, section 3.6.4 – Markus A. Dec 02 '20 at 07:21
  • thats a sad moment – Rohit gupta Dec 02 '20 at 10:46

1 Answers1

1

Writing this helped me to solve this issue

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
Rohit gupta
  • 211
  • 3
  • 18