www.gusucode.com > opc 案例源码 matlab代码程序 > opc/opcdemo_defaultcallback.m
%% Monitor Logging Progress with OPC Toolbox Callbacks % This example shows you how to use callbacks to monitor an OPC Data Access logging task. % % Use callbacks to log or report events in a logging task, to update graphical user interfaces to % show status of logging, or to graphically display logged data during the logging task. % % *PREREQUISITES:* % % * <docid:opc_examples.example-ex84291595> % Copyright 2004-2012 The MathWorks, Inc. % $Revision: 1.1.6.9 $ $Date: 2012/08/01 00:52:21 $ %% Step 1: Configure OPC Toolbox Objects % Create the client, connect, and create associated objects for a logging task. da = opcda('localhost','Matrikon.OPC.Simulation.1'); connect(da); grp = addgroup(da,'CallbackTest'); additem(grp,{'Random.Real8','Saw-toothed Waves.UInt2'}); %% Step 2: Configure the Logging Task Properties % Set the group to acquire 20 records at 0.5 second intervals. grp.RecordsToAcquire = 20; grp.UpdateRate = 0.5; disp(grp) %% Step 3: Configure the Callbacks % Use the default callback, <matlab:open('opccallback') opccallback>, to display the start event % (|StartFcn| property), the stop event (|StopFcn| property), and when each consecutive 5 records % have been acquired (|RecordsAcquiredFcn| and |RecordsAcquiredFcnCount| properties). grp.StartFcn = @opccallback; grp.StopFcn = @opccallback; grp.RecordsAcquiredFcn = @opccallback; grp.RecordsAcquiredFcnCount = 5; %% Step 4: Start the Logging Task % Start the logging task, and wait for it to complete. start(grp) wait(grp) %% Step 5: Clean Up OPC Toolbox objects % Disconnect the client from the server and remove OPC Toolbox(TM) objects from memory when you no % longer need them. Deleting the client object also deletes the group and item objects. disconnect(da) delete(da)