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

Managing OPC Toolbox™ Objects

This example shows you how to manage OPC Toolbox™ objects.

Contents

Step 1: Find OPC Toolbox™ Objects in Memory

You use the opcfind function to find OPC Toolbox objects in memory.

opcfind
ans =
     []

Create some OPC Toolbox™ objects

da = opcda('localhost', 'Dummy.Server.1');
grp = addgroup(da);
itm1 = additem(grp, 'Fake.Item.ID1');
itm2 = additem(grp, 'Fake.Item.ID2');

Find all valid objects

allOPC = opcfind
allOPC =
    [1x1 opcda]    [1x1 dagroup]    [1x1 daitem]    [1x1 daitem]

The information is returned in a cell array, because opcfind can locate different objects. To access an object, use cell indexing.

newGrp = allOPC{2}
newGrp =
Summary of OPC Data Access Group Object: group1
   Object Parameters
      Group Type   : private
      Item         : 2-by-1 daitem object
      Parent       : localhost/Dummy.Server.1
      Update Rate  : 0.5
      Deadband     : 0%
   Object Status
      Active       : on
      Subscription : on
      Logging      : off
   Logging Parameters
      Records      : 120
      Duration     : at least 60 seconds
      Logging to   : memory
      Status       : Waiting for START.
                     0 records available for GETDATA/PEEKDATA

To find objects with a specific property, pass property/value pairs to the opcfind function.

allDA = opcfind('Type', 'opcda')
allDA =
    [1x1 opcda]

Step 2: Remove Objects From Memory

To delete an OPC Toolbox object from memory, use the delete function with the object. Deleting a client object deletes all group and item objects associated with the client. Deleting a group deletes all items in that group.

delete(grp)

Find all remaining valid objects.

allOPC = opcfind
allOPC =
    [1x1 opcda]

Using the delete function with the object will remove the object from the OPC Toolbox engine but not from the MATLAB® workspace. To remove an object from the MATLAB workspace use the clear function. To see what objects are in the MATLAB workspace, use the whos function.

Display the current workspace.

whos
  Name                         Size             Bytes  Class      Attributes

  OPCBlksTutorial_Scope        1x1               1866  struct
  accessRights                 1x1                560  struct
  allDA                        1x1                690  cell
  allID                        1x1                110  cell
  allMdlFiles                  2x1                918  struct
  allOPC                       1x1                690  cell
  allServers                   1x1                110  cell
  ans                          0x0                  0  double
  badInd                     600x1                600  logical
  canDT                        1x1                562  struct
  clientName                   1x35                70  char
  da                           1x1                630  opcda
  events                       1x2               1290  struct
  exEvtTime                   20x1                160  double
  exItmId                      1x3                252  cell
  exQual                      20x3               5760  cell
  exTStamp                    20x3                480  double
  exVal                       20x3                480  double
  grp                          1x1                630  dagroup
  hostInfo                     1x1               1120  struct
  isBadQual                  600x3               1800  logical
  isRepeatQual               600x3               1800  logical
  itm1                         1x1                630  daitem
  itm2                         1x1                630  daitem
  itmIDs                       1x2                184  cell
  k                            1x1                  8  double
  logDuration                  1x1                  8  double
  logEvtTime                 600x1               4800  double
  logIDs                       1x3                306  cell
  logQual                    600x3             172778  cell
  logRate                      1x1                  8  double
  logTime                    600x3              14400  double
  logVal                     600x3              14400  double
  loggingDuration              1x1                  8  double
  loggingSeconds               1x1                  8  double
  mDir                         1x48                96  char
  mI                           1x1                  8  double
  mdlDir                       1x61               122  char
  mdlPubDir                    1x59               118  char
  newGrp                       1x1                630  dagroup
  ns                           3x1              29452  struct
  numRecords                   1x1                  8  double
  oldDir                       1x59               118  char
  options                      1x1                130  struct
  opts                         1x1                719  struct
  pI                           1x1                  8  double
  pubMFiles                    9x1               3209  struct
  r                            1x1                752  struct
  realItems                   21x1               2060  cell
  recAvail                     1x1                  8  double
  repInd                     600x1                600  logical
  sFirst                      20x1              29768  struct
  sPeek                        1x1               1610  struct
  sReal8Disk                  40x1              31328  struct
  sawtoothItems               10x1               1044  cell
  statusInfo                   1x1                838  struct
  stopdata                     1x1                452  struct
  thisMFile                    1x20                40  char
  thisName                     1x15                30  char
  thisPath                     0x0                  0  char
  tout                        51x1                408  double
  triangleItems               10x1                984  cell
  vals                         1x2                 16  double

Since an object was deleted, it is no longer valid.

grp
grp =
Invalid dagroup object.
This object should be removed from your workspace using CLEAR.

The items contained by that group are also invalid

itm1
itm1 =
Invalid daitem object.
This object should be removed from your workspace using CLEAR.

Clear the associated variables.

clear grp itm1 itm2

Display the current workspace.

whos
  Name                         Size             Bytes  Class      Attributes

  OPCBlksTutorial_Scope        1x1               1866  struct
  accessRights                 1x1                560  struct
  allDA                        1x1                690  cell
  allID                        1x1                110  cell
  allMdlFiles                  2x1                918  struct
  allOPC                       1x1                690  cell
  allServers                   1x1                110  cell
  ans                          0x0                  0  double
  badInd                     600x1                600  logical
  canDT                        1x1                562  struct
  clientName                   1x35                70  char
  da                           1x1                630  opcda
  events                       1x2               1290  struct
  exEvtTime                   20x1                160  double
  exItmId                      1x3                252  cell
  exQual                      20x3               5760  cell
  exTStamp                    20x3                480  double
  exVal                       20x3                480  double
  hostInfo                     1x1               1120  struct
  isBadQual                  600x3               1800  logical
  isRepeatQual               600x3               1800  logical
  itmIDs                       1x2                184  cell
  k                            1x1                  8  double
  logDuration                  1x1                  8  double
  logEvtTime                 600x1               4800  double
  logIDs                       1x3                306  cell
  logQual                    600x3             172778  cell
  logRate                      1x1                  8  double
  logTime                    600x3              14400  double
  logVal                     600x3              14400  double
  loggingDuration              1x1                  8  double
  loggingSeconds               1x1                  8  double
  mDir                         1x48                96  char
  mI                           1x1                  8  double
  mdlDir                       1x61               122  char
  mdlPubDir                    1x59               118  char
  newGrp                       1x1                630  dagroup
  ns                           3x1              29452  struct
  numRecords                   1x1                  8  double
  oldDir                       1x59               118  char
  options                      1x1                130  struct
  opts                         1x1                719  struct
  pI                           1x1                  8  double
  pubMFiles                    9x1               3209  struct
  r                            1x1                752  struct
  realItems                   21x1               2060  cell
  recAvail                     1x1                  8  double
  repInd                     600x1                600  logical
  sFirst                      20x1              29768  struct
  sPeek                        1x1               1610  struct
  sReal8Disk                  40x1              31328  struct
  sawtoothItems               10x1               1044  cell
  statusInfo                   1x1                838  struct
  stopdata                     1x1                452  struct
  thisMFile                    1x20                40  char
  thisName                     1x15                30  char
  thisPath                     0x0                  0  char
  tout                        51x1                408  double
  triangleItems               10x1                984  cell
  vals                         1x2                 16  double

To remove all OPC Toolbox objects from the engine and to reset the toolbox to its initial state, use the opcreset function.

Note: Using the opcreset function will only delete objects from memory, not clear them from the MATLAB workspace.

opcreset

Verify that no objects remain.

allOPC = opcfind
allOPC =
     []

Variables associated with deleted objects still remain.

whos
  Name                         Size             Bytes  Class      Attributes

  OPCBlksTutorial_Scope        1x1               1866  struct
  accessRights                 1x1                560  struct
  allDA                        1x1                690  cell
  allID                        1x1                110  cell
  allMdlFiles                  2x1                918  struct
  allOPC                       0x0                  0  double
  allServers                   1x1                110  cell
  ans                          0x0                  0  double
  badInd                     600x1                600  logical
  canDT                        1x1                562  struct
  clientName                   1x35                70  char
  da                           1x1                630  opcda
  events                       1x2               1290  struct
  exEvtTime                   20x1                160  double
  exItmId                      1x3                252  cell
  exQual                      20x3               5760  cell
  exTStamp                    20x3                480  double
  exVal                       20x3                480  double
  hostInfo                     1x1               1120  struct
  isBadQual                  600x3               1800  logical
  isRepeatQual               600x3               1800  logical
  itmIDs                       1x2                184  cell
  k                            1x1                  8  double
  logDuration                  1x1                  8  double
  logEvtTime                 600x1               4800  double
  logIDs                       1x3                306  cell
  logQual                    600x3             172778  cell
  logRate                      1x1                  8  double
  logTime                    600x3              14400  double
  logVal                     600x3              14400  double
  loggingDuration              1x1                  8  double
  loggingSeconds               1x1                  8  double
  mDir                         1x48                96  char
  mI                           1x1                  8  double
  mdlDir                       1x61               122  char
  mdlPubDir                    1x59               118  char
  newGrp                       1x1                630  dagroup
  ns                           3x1              29452  struct
  numRecords                   1x1                  8  double
  oldDir                       1x59               118  char
  options                      1x1                130  struct
  opts                         1x1                719  struct
  pI                           1x1                  8  double
  pubMFiles                    9x1               3209  struct
  r                            1x1                752  struct
  realItems                   21x1               2060  cell
  recAvail                     1x1                  8  double
  repInd                     600x1                600  logical
  sFirst                      20x1              29768  struct
  sPeek                        1x1               1610  struct
  sReal8Disk                  40x1              31328  struct
  sawtoothItems               10x1               1044  cell
  statusInfo                   1x1                838  struct
  stopdata                     1x1                452  struct
  thisMFile                    1x20                40  char
  thisName                     1x15                30  char
  thisPath                     0x0                  0  char
  tout                        51x1                408  double
  triangleItems               10x1                984  cell
  vals                         1x2                 16  double

Step 3: Clean Up

Clear any remaining variables associated with deleted objects.

clear da newGrp allOPC allDA
Contact sales
Trial software
E-mail this page

Get Pricing and
Licensing Options