OPC toolbox is invalid when I start the program
Show older comments
Hello. I'm using OPC toolbox to communicate my MATLAB program with PLC. I'm controlling several variables by PLC and then I'm sending them threw OPC to the MATLAB, where the whole simulation runs. The problem is, when the simulation starts, OPC toolbox starts to be invalid, but after few seconds, respectively it will read the first value of variable in PLC and then it will write that OPC toolbox is invalid. Here is my OPC configuration.
classdef MatlabPLC < handle
properties
WE;
opcData;
a; %OPC server
end
methods
function this = MatlabPLC()
this.WE = false;
if mpcchecktoolboxinstalled('opc')
opcreset
clear mpcopcPlatnStep;
clear mpcopcMPCstep;
try
this.a = opcda('192.168.0.101','Kepware.KEPServerEX.V6');
connect(this.a)
catch ME
disp('The Kepware.KEPServerEX.V6 must be running on the local machine.')
return
end
end
svetla = addgroup(this.a);
this.opcData.WE = additem(svetla,'SIEMENS.s7-1200.svetla.WE');
end
function delete(this)
%destruktor
disconnect(this.a);
end
% WEST - EAST (GETTER + SETTER)
function WE = getWE(this)
pom = read(this.opcData.WE);
this.WE = pom.Value;
WE = this.WE;
end
function setWE(this, WE)
this.WE = WE;
write(this.opcData.WE, this.WE);
end
end
end
variable WE is boolean. The problem begin, when I call getter(getWE) in my script. Then the OPC fall down. Does anyone know whats wrong? If there is a manual how to correctly connect MATLAB(not simulink) with PLC threw OPC, I will be very thankful.
Answers (0)
Categories
Find more on Industrial Communication Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!