This example shows you how to use a custom callback for the OPC Toolbox™ to plot data acquired during a logging task.
The example makes use of the display_opcdata function, which plots recently acquired data in a figure window.
Create a hierarchy of OPC Toolbox objects.
da = opcda('localhost','Matrikon.OPC.Simulation.1'); connect(da); grp = addgroup(da,'CallbackTest'); additem(grp,'Triangle Waves.Real8'); additem(grp,'Saw-toothed Waves.UInt2');
Configure the logging task to acquire 200 records at 0.1 second intervals.
grp.RecordsToAcquire = 200; grp.UpdateRate = 0.1;
Specify the display_opcdata function as the
RecordsAcquiredFcn callback, which must be called after each 10 records are acquired.
grp.RecordsAcquiredFcnCount = 10; grp.RecordsAcquiredFcn = @display_opcdata;
Start the group object. After every 10 records are acquired, the object executes the
display_opcdata callback function. This callback function plots the most recently acquired records logged to the memory buffer.
Always remove OPC Toolbox objects from memory when you no longer need them.
Deleting the client object disconnects the client from the server, and deletes the group and item objects also.