This is machine translation

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

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Configure OPC Toolbox Data Access Object Properties

Purpose of Object Properties

All OPC Toolbox™ Data Access objects support properties that enable you to control characteristics of the object:

  • The opcda client object properties control aspects of the connection to the OPC server, and event information obtained from the server. For example, you can use the Timeout property to define how long to wait for the server to respond to a request from the client.

  • The dagroup object properties control aspects of the collection of items contained within that group, including all logging properties. For example, the UpdateRate property defines how often the items in the group must be checked for value changes, as well as the rate at which data will be sent from the server during a logging session.

  • The daitem object properties control aspects of a single server item. For example, you use the DataType property to define the data type that the server must use to send values of that server item to the OPC Toolbox software.

For all three toolbox objects, you can use the same toolbox functions to

  • View a list of all the properties supported by the object, with their current values

  • View the value of a particular property

  • Get information about a property

  • Set the value of a property

View the Values of Object Properties

To view all the properties of an OPC Toolbox Data Access object, with their current values, use the get function.

If you do not specify a return value, the get function displays the object properties in categories that group similar properties together. You use the display form of the get function to view the value of all properties for the toolbox object.

This example uses the get function to display a list of all the properties of the OPC dagroup object grp.

get(grp)
  General Settings:
    DeadbandPercent = 0
    GroupType = private
    Item = []
    Name = group1
    Parent = [1x1 opcda]
    Tag = 
    TimeBias = 0
    Type = dagroup
    UpdateRate = 0.5000
    UserData = []

  Callback Function Settings:
    CancelAsyncFcn = @opccallback
    DataChangeFcn = []
    ReadAsyncFcn = @opccallback
    RecordsAcquiredFcn = []
    RecordsAcquiredFcnCount = 20
    StartFcn = []
    StopFcn = []
    WriteAsyncFcn = @opccallback

  Subscription and Logging Settings:
    Active = on
    LogFileName = opcdatalog.olf
    Logging = off
    LoggingMode = memory
    LogToDiskMode = index
    RecordsAcquired = 0
    RecordsAvailable = 0
    RecordsToAcquire = 120
    Subscription = on

View the Value of a Particular Property

To view the value of a particular property of an OPC Toolbox Data Access object, use the get function, specifying the name of the property as an argument. You can also access the value of the property as you would a field in a MATLAB® structure.

This example uses the get function to retrieve the value of the Subscription property for the dagroup object.

get(grp,'Subscription')
ans =

on

This example illustrates how to access the same property by referencing the object as if it were a MATLAB structure.

grp.Subscription
ans =

on

Get Information About Object Properties

To get information about a particular property, use the propinfo or opchelp functions.

The propinfo function returns a structure that contains information about the property, such as its data type, default value, and a list of all possible values if the property supports such a list. This example uses propinfo to get information about the LoggingMode property.

propinfo(grp,'LoggingMode')
ans = 

               Type: 'string'
         Constraint: 'enum'
    ConstraintValue: {'memory'  'disk'  'disk&memory'}
       DefaultValue: 'memory'
           ReadOnly: 'whileLogging'

The opchelp function returns reference information about the property with a complete description. This example uses opchelp to get information about the LoggingMode property.

opchelp(grp,'LoggingMode')

Set the Value of an Object Property

To set the value of a particular property of an OPC Toolbox Data Access object, use the set function, specifying the name of the property as an argument. You can also assign the value to the property as you would a field in a MATLAB structure.

Note

Because some properties are read-only, only a subset of the toolbox object properties can be set. Use the property reference pages or the propinfo function to determine if a property is read-only.

This example uses the set function to set the value of the LoggingMode property.

set(grp,'LoggingMode','disk&memory')

To verify the new value of the property, use the get function.

get(grp,'LoggingMode')
ans =

disk&memory

This example sets the value of a property by assigning the value to the object as if it were a MATLAB structure.

grp.LoggingMode = 'disk';
grp.LoggingMode
ans =

disk

View a List of All Settable Object Properties

To view a list of all the properties of a toolbox object that can be set, use the set function.

set(grp)
  General Settings:
    DeadbandPercent
    Name
    Tag
    TimeBias
    UpdateRate
    UserData

  Callback Function Settings:
    CancelAsyncFcn: character vector -or- function handle -or- cell array
    DataChangeFcn: character vector -or- function handle -or- cell array
    ReadAsyncFcn: character vector -or- function handle -or- cell array
    RecordsAcquiredFcn: character vector -or- function handle -or- cell array
    RecordsAcquiredFcnCount
    StartFcn: character vector -or- function handle -or- cell array
    StopFcn: character vector -or- function handle -or- cell array
    WriteAsyncFcn: character vector -or- function handle -or- cell array

  Subscription and Logging Settings:
    Active: [ {on} | off ]
    LogFileName
    LoggingMode: [ {memory} | disk | disk&memory ]
    LogToDiskMode: [ {index} | append | overwrite ]
    RecordsToAcquire
    Subscription: [ {on} | off ]

When using the set function to display a list of settable properties, all properties that have a predefined set of acceptable values list those values after the property. The default value is enclosed in curly braces ({}). For example, from the display shown above, you can set the Subscription property for a dagroup object to 'on' or 'off', with the default value being 'on'. You can set the LogFileName property to any value.

Special Read-Only Modes

Some OPC Toolbox Data Access object properties change their read-only status, depending on the state of an object (defined by another property of that object, or the parent of that object). The toolbox uses two special read-only modes:

  • 'whileConnected': These properties cannot be changed while the client is connected to the OPC server. For example, the client's Host property is read-only while connected.

  • 'whileLogging': These properties cannot be changed while the dagroup object is logging. For example, the LoggingMode property is read-only while logging. For more information on logging, see Log OPC Server Data.

  • 'whilePublic': These properties cannot be changed because the group is a public group. For more information on public groups, see Work with Public Groups.

    Note

    Properties that modify their read-only state are always displayed when using set to display settable properties, even when they cannot be changed because of the state of the object.

To determine if a property has a modifiable read-only state, use the propinfo function.