Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

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 = 

1×2 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: [2016 4 12 16 11 50.3170]
          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.8630

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 can 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 also deletes the group and item objects.

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