OPC Toolbox 2.1.4
Viewing Events
This example demonstrates the use of the OPC Toolbox event log. A logging task is started, and the event log is examined to determine the start and stop times for the logging task.
Contents
Step 1: Create the OPC Toolbox™ Hierarchy
This example creates a hierarchy of OPC Toolbox™ objects for the Matrikon™ Simulation Server. To run this example on your system, you must have the Matrikon™ Simulation Server installed. Alternatively, you can replace the values used in the creation of the objects with values for a server you can access.
da = opcda('localhost','Matrikon.OPC.Simulation.1'); connect(da); grp = addgroup(da,'CallbackTest'); itm1 = additem(grp,'Triangle Waves.Real8');
Step 2: Start the Logging Task
Configure the group to log only 10 records, then start the group object.
grp.RecordsToAcquire = 10; start(grp)
Wait for the object to stop logging data.
wait(grp)
Step 3: View the Event Log
Access the EventLog property of the client object. The execution of the group logging task generated two events: start, and stop. Thus the value of the EventLog property is a 1-by-2 array of event structures.
events = da.EventLog
events =
1x2 struct array with fields:
Type
Data
To list the events that are recorded in the EventLog property, examine the contents of the Type field.
{events.Type}
ans =
'Start' 'Stop'
To get information about a particular event, access the Data field in that event structure. The example retrieves information about the stop event.
stopdata = events(2).Data
stopdata =
LocalEventTime: [2006 11 21 8 18 17.1710]
GroupName: 'CallbackTest'
RecordsAcquired: 10
The LocalEventTime field of the Data structure contains the time the event occurred. To see how long the server took to send 10 records, subtract the Stop event's time from the Start event's time.
loggingDuration = datenum(events(2).Data.LocalEventTime) - ...
datenum(events(1).Data.LocalEventTime);
loggingSeconds = loggingDuration * 24 * 60 * 60
loggingSeconds =
5.8430
Step 4: Clean Up
Always remove OPC Toolbox objects from memory, and the variables that reference them, when you no longer need them. Deleting the client object deletes the group and item objects also.
disconnect(da) delete(da) clear da grp itm1
Store