本人准毕业生一枚,毕业设计中用到了WinCC与MATLAB的OPC通讯。在MATLAB 里编好了程序,程序分为三部分:MATLAB读取OPC服务器程序、MATLAB将数据写入OPC服务器程序以及回调函数中的显示变量变化的显示子程序。想问下。这三部分程序中前两个是要放在一个M文件中么??初步程序如下,为什么到了"writeasync(Item2,y_2);% //写入数据"就显示错误???求各位大侠不吝赐教啊,感激不尽
%MATLAB读取OPC服务器程序
Server=opcda('localhost','opcserver.wincc');%创建OPC 数据访问服务器
connect(Server);
group=addgroup(Server);
Item1=additem(group,'cyd'); %创建项,cyd 为WINCC 中变量
set(group,'updaterate',20); %设置更新周期
set(group,'RecordsAcquiredfcncount',2);
set(group,'Recordstoacquire',60);
set(group,'datachangeFcn',@mydisplay); %设置数据变化触发的显示子程序,@mydisplay为回调函数
start(group);
group;
%MATLAB将数据写入OPC服务器
Server=opcda('localhost','opcserver.wincc');
connect(Server);
group=addgroup(Server);
Item2=additem(group, 'PVN');
Item3=additem(group, 'PVN1');
readasync(Item1);
(省略由Item1计算得到item2 iten3的程序)
writeasync(Item2,y_2);% //写入数据
writeasync(Item3,y_1);