MATLAB - GUI and OPC server

纵饮孤独 提交于 2021-02-05 09:25:07

问题


I want to design a graphical user interface in MATLAB that can read data continuously using the MATLAB's object linking and embedding for process control (OPC) toolbox. How can I implement this?

I have designed the graphical user interface, but I'm not able to read the data into the graphical user interface.


回答1:


Take a look at this submission of mine from the MATLAB Central File Exchange. It gives a full example of how to read and write data from an OPC server, and how to create and compile a GUI interface with this functionality as well.

The submission used to have recorded webinar associated with it - unfortunately that seems to have been taken down as it was a bit old. Nevertheless, there's a demonstration script included in the files that walks through the entire process, and I think should give you a good idea of what's going on.

Hope that helps!




回答2:


just do this

type opctool inside MATLAB

  • click create new host

  • select Localhost

  • Click add client

  • click add group and add item

  • Now you can see the actual name of variable you want to call like SimControl.Run, SimControl.Stop , ..etc

  • Now you have to code it like this in MATLAB

             %====================================VARIABLE VALUE===============================
             volume_val=app.VolumeVEditField.Value;
             area_val=app.AreaAEditField.Value;
    
    
    
             %====================================CONNECTION====================================
             global hostInfo ;
             hostInfo = opcserverinfo('localhost');
             global da;
             da = opcda('localhost','Dymosim.OPCServer.1');
             connect(da);
             pause(2);
    
    
             %====================================INITIAL VARIABLE=============================
             grp=addgroup(da,'Demo');
             grp2=addgroup(da,'Demo2');
             Initialize=additem(grp2,{'SimControl.Initialize'});
             Run=additem(grp2,{'SimControl.Run'});
             Status=additem(grp2,{'SimControl.Status'});
             Stop=additem(grp2,{'SimControl.Stop'});
             Pause=additem(grp2,{'SimControl.Pause'});
             %=================================================================================
             write(Initialize,1);
    
             %you can use write(area,area_val) 
    
  • Then you can use deploytool to create app



来源:https://stackoverflow.com/questions/19953430/matlab-gui-and-opc-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!