Using the read
and readasync
functions
described in Read Data from an Item, you can obtain information about
OPC server item values upon request. The OPC Data Access specification
provides another mechanism for clients to get information on server
item values. This mechanism allows the OPC server to notify a client
when a server item value or quality has updated. This mechanism is
called a data change event. OPC Toolbox™ software
supports data change event notification by executing a MATLAB® function
when a data change event is received from a connected OPC server.
This section describes how to use the data change event notification.
A data change event occurs at the dagroup
object
level. Using dagroup
object properties, you can
control whether a data change event is generated for a particular
group, the minimum time between successive events, and the MATLAB function
to run when the event notification is received and processed by OPC Toolbox software.
You can also control which items in a particular group should be monitored
for data changes. In this way, you can control the number and frequency
of data change events that MATLAB has to process. On a busy OPC
server, you can also turn off data change notification for groups
that you are not currently interested in.
The following sections describe how to control data change notification.
Control Data Change Notification for a Group describes
how to turn off data change notification for a dagroup
object.
Temporarily Disable Items in a Group describes how to control which items in a group must be monitored for data changes.
Customize the Data Change Event Response provided information on how to configure the MATLAB function to run when a data change event occurs.
The following properties of a dagroup
object
control whether a server notifies the group of data changes on items
in that group:
UpdateRate
:
The UpdateRate
property defines
the rate at which an OPC server must monitor server item values and
generate data change events. Even if a server item's value changes
more frequently than the update rate, the OPC server will only generate
a data change at the interval specified by the update rate.
Subscription
:
The Subscription
property defines
whether the OPC server will generate a data change event for the group.
When you create a dagroup
object, the Subscription
property
is set to 'on'
. When you set the Subscription
property
to 'off'
, you tell the OPC server not to generate
data change events for that group.
Active
:
The Active
property must be 'on'
for
data change events to be generated. When you create a dagroup
object,
the Active
property is set to 'on'
.
When you set the Active
property to 'off'
,
you remove any ability to read data from the group, whether through
read operations or data change events.
A summary of group read, write, and data change behavior for
the Active
and Subscription
properties
is given in the following table.
Active | Subscription | Read | Write | Data Change |
---|---|---|---|---|
|
| Yes | Yes | Yes |
|
| Yes | Yes | No |
|
| No | No | No |
|
| No | No | No |
You can temporarily disable items in a group without deleting
the item from the group. When you disable a daitem
object,
the OPC server no longer monitors changes in the associated server
item's value, and will therefore not generate data change events when
the value of that server item changes.
You can disable a daitem
object by setting
that object's Active
property to 'off'
.
You can reenable the daitem
object by setting the Active
property
to 'on'
.
You can force an OPC server to generate a data change event
for all active items in a group by using the refresh
function
with the dagroup
object as the first argument.
The OPC server will generate a data change event containing information
for every active item in the group.
You can pass an optional second argument to the refresh
function
to instruct the OPC server where to source the data values that are
sent back in the data change event. By specifying a source of 'device'
,
you instruct the OPC server to update the values from the device.
By specifying a source of 'cache'
(the default)
you instruct the OPC server to return values from the OPC server's
cache.
OPC Toolbox software uses data change events for a number of tasks. The following activities take place when a data change event occurs:
The Value
, Quality
, and TimeStamp
properties
of the daitem
object are automatically updated.
For more information on these properties, see OPC Data: Value, Quality, and TimeStamp.
If the dagroup
object
is logging, the data change event is logged to memory and/or disk
as a record. For information on logging, see Log OPC Server Data.
If the dagroup
object's DataChangeFcn
property is not empty, that
function is called with the data change event information. By default,
this property is empty, since data change events occur frequently.
You can customize the behavior of the toolbox by setting this property
to call a function that you choose. For information on the data change
event, see the reference page for the DataChangeFcn
property.
Note
If you disable data change events by setting the Subscription
property to 'off'
or
the Active
property to 'off'
,
none of the activities listed above can take place. You cannot change
the Active
or Subscription
properties
while a dagroup
object is logging, otherwise the
logging task may never complete.
One of the activities that occurs when OPC Toolbox software
receives a data change event from the OPC server is the running of
the function defined in the DataChangeFcn
property.
By setting this property to a the name of a function that you have
written, you can fully customize the data change event behavior of
the toolbox. For example, you may configure a dagroup
object
to monitor a server item that is updated from an operator interface.
By pushing a button on the operator interface, the server item value
will change, initiating a data change event on that group. By configuring
the DataChangeFcn
property to run a MATLAB function
that performs control loop optimization, you can allow an operator
to initiate a control loop performance test on all critical control
loops in the plant.