Skip to Main Content Skip to Search
Home |   Select Country  Choose Country  |  Contact Us  |  Cart Store 
Create Account | Log In
Products & Services Solutions Academia Support User Community Company
spacer spacer spacer spacer spacer spacer

 

OPC Toolbox 2.1.4

Using the Default Callback

This example demonstrates the use of callbacks during a logging task.

Contents

Step 1: Configure OPC Toolbox Objects™

Start by creating objects for the Matrikon™ Simulation Server.

da = opcda('localhost', 'Matrikon.OPC.Simulation.1');
connect(da);
grp = addgroup(da, 'CallbackTest');
itm = additem(grp, {'Random.Real8', 'Saw-toothed Waves.UInt2'});

Step 2: Configure the Logging Task Properies

This example acquires 20 records at 0.5 second intervals.

grp.RecordsToAcquire = 20;
grp.UpdateRate = 0.5;

Step 3: Configure the Callbacks

This example uses the default callback, opccallback to display how the start, records acquired and stop events are processed by MATLAB® during a logging task.

grp.StartFcn = @opccallback;
grp.StopFcn = @opccallback;
grp.RecordsAcquiredFcn = @opccallback;
grp.RecordsAcquiredFcnCount = 5;

Step 4: Start the Logging Task

When you start the logging task, the Start event will be generated. During the task, the Records Acquired event will be generated each time 5 records have been logged. Finally, the Stop event will be generated when the logging task completes.

start(grp)
OPC Start event occurred at local time 08:17:59
    Group 'CallbackTest': 0 records acquired.

The wait function does not block the MATLAB command-line, so the events can be processed.

wait(grp)
OPC RecordsAcquired event occurred at local time 08:18:01
    Group 'CallbackTest': 5 records acquired.
OPC RecordsAcquired event occurred at local time 08:18:04
    Group 'CallbackTest': 10 records acquired.
OPC RecordsAcquired event occurred at local time 08:18:07
    Group 'CallbackTest': 15 records acquired.
OPC RecordsAcquired event occurred at local time 08:18:10
    Group 'CallbackTest': 20 records acquired.
OPC Stop event occurred at local time 08:18:10
    Group 'CallbackTest': 20 records acquired.

Step 5: Clean Up

Always remove OPC Toolbox™ objects from memory, and the variables that reference them, when you no longer need them.

disconnect(da)
delete(da)
clear da grp itm
Contact sales
Trial software
E-mail this page

Get Pricing and
Licensing Options