This example shows you how to examine the OPC Toolbox event log after a logging task.
|On this page…|
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,'Triangle Waves.Real8');
Configure the group to log only 10 records, then start the task and wait for it to complete.
grp.RecordsToAcquire = 10; start(grp) wait(grp)
Access the EventLog property of the client object.
events = da.EventLog
events = 1x2 struct array with fields: Type Data
The execution of the group logging task generated two events: start, and stop. The value of the EventLog property is a 1-by-2 array of event structures.
List the events that are recorded in the EventLog property, by examining the contents of the Type field.
ans = 'Start' 'Stop'
Access the Data field to get information about the stop event.
stopdata = events(2).Data
stopdata = LocalEventTime: [2012 3 28 2 9 0.8350] GroupName: 'CallbackTest' RecordsAcquired: 10
Calculate the time between the stop event and the start event.
waitDuration = datenum(events(2).Data.LocalEventTime) - ... datenum(events(1).Data.LocalEventTime); waitSeconds = waitDuration * 24 * 60 * 60
waitSeconds = 5.5780
Note: waitSeconds is not necessarily the time between the first and last sample in the logged data set. The LocalEventTime property is the time that MATLAB processed the event received from the server; there may be some delay between the server sending the notification and MATLAB processing it. You should consult the TimeStamp property of the logged data for accurate time information related to the data.
Disconnect the client from the server and remove OPC Toolbox™ objects from memory when you no longer need them. Deleting the client object deletes the group and item objects also.