Documentation

View the OPC Toolbox Event Log

This example shows you how to examine the OPC Toolbox event log after a logging task.

PREREQUISITES:

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,'Triangle Waves.Real8');

Step 2: Configure and Execute a Logging Task

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)

Step 3: View the Event Log

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.

{events.Type}
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.

Step 4: Clean Up

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.

disconnect(da)
delete(da)
Was this topic helpful?