www.gusucode.com > opc 案例源码 matlab代码程序 > opc/display_opcdata.m
function display_opcdata(obj,event) %DISPLAY_OPCDATA Displays recently logged data in a figure window. % DISPLAY_OPCDATA is used by some of the OPC Toolbox examples. Every time % this function is called (usually from a DataChange callback) 100 records % are retrieved from memory using PEEKDATA and those records are plotted % in a figure window. Any Repeat quality data points are marked with a yellow % asterisk, and any Bad quality data points are marked with a red filled % circle. % % See also OPCDEMO_CUSTOMCALLBACK, PEEKDATA % Copyright 2004-2014 The MathWorks, Inc. % coded by OPTI-NUM solutions numRecords = min(obj.RecordsAvailable, 100); lastRecords = peekdata(obj,numRecords); [i, v, q, t] = opcstruct2array(lastRecords); plot(t, v); isBad = strncmp('Bad', q, 3); isRep = strncmp('Repeat', q, 6); hold on for k=1:length(i) h = plot(t(isBad(:,k),k), v(isBad(:,k),k), 'o'); set(h,'MarkerEdgeColor','k', 'MarkerFaceColor','r') h = plot(t(isRep(:,k),k), v(isRep(:,k),k), '*'); set(h,'MarkerEdgeColor',[0.75, 0.75, 0]); end axis tight; ylim([0, 200]); datetick('x','keeplimits'); eventTime = event.Data.LocalEventTime; title(sprintf('Event occurred at %s', ... datestr(eventTime, 13))); drawnow; % force an update of the figure window hold off;