www.gusucode.com > opc 案例源码 matlab代码程序 > opc/opcdemo_objects.m
%% Create and Configure OPC Toolbox Objects % This example shows you how to create and configure OPC Toolbox(TM) objects. % % *PREREQUISITES:* % % * <docid:opc_examples.example-ex84291595> % Copyright 2004-2014 The MathWorks, Inc. % $Revision: 1.1.6.8 $ $Date: 2012/08/01 00:52:26 $ %% Create Client Objects % Create a client using the |opcda| function. You need the host name and % the server ID for the OPC Server associated with this client. da = opcda('localhost','Matrikon.OPC.Simulation.1'); connect(da); %% Add Groups to the Client % Use the |addgroup| function to add groups to the client object. The % OPC Toolbox automatically assigns a name to the group, if you do not % specify one. grp1 = addgroup(da); %% % Group objects are used to manage collections of |daitem| objects. %% % To assign your own name to a group, the name must be unique for all the groups in a % client. Pass the name as an additional argument to |addgroup|. grp2 = addgroup(da,'MyGroup'); %% % Type the object name to view a summary of the group object. grp1 %% Add Item Objects to the Group % Add the item named |Random.Real8| to the group. itm1 = additem(grp1,'Random.Real8'); %% % If you want the value stored in MATLAB(R) to % have a specific data type, specify it as the third argument. itm2 = additem(grp1,'Random.UInt2','double'); %% % To view a summary of the object, type the name of the object. itm1 %% Create Object Vectors % References to multiple OPC Toolbox objects can be stored in object vectors. itmVec = [itm1,itm2] %% % Displaying the object vector shows information about each object in the vector. %% View and Change Object Properties % View a list of all properties supported by the object. get(da) %% % Obtain information about a specific property. clientName = da.Name %% % Get information about a property using the |propinfo| function. statusInfo = propinfo(da,'Status') %% % The information includes whether the property is read-only, and lists the valid % values for properties that have a predefined set of values. %% % Set the value of the |Timeout| property to 30 seconds. da.Timeout = 30 %% Clean Up % Delete objects that you are finished using from the OPC Toolbox engine. disconnect(da) delete(da) %% % Deleting the client object also deletes the group % and item objects associated with that client.