4.2
OPCBrowser Object
Description
The OPCBrowser object is a collection of branch or item names that exist in the server. Browsing
is optional. If the server does not support browsing, CreateBrowser will not create this object.
Syntax OPCBrowser
Remarks
The properties Filter, DataType, and AccessRights affect the collection at the time a method such
as ShowLeafs is called. These properties let the client request a subset of the address space.
If the user is browsing names of items to write data to, then the AccessRights property should be
set to OPCWritable before calling ShowLeafs.
Servers can have either a flat or hierarchical name space. When the namespace is flat, calling the
method ShowLeafs fills the collection with the entire set of names in the server.
Hierarchical browsing is a two step process. First, the browse position is set using a Move method,
then the names are put into the collection using the Show methods. Calling ShowBranches fills the
collection with the branches below the current position. Calling MoveDown with one of these
branch names moves the position to that branch. Calling MoveUp moves up one level. Calling
MoveToRoot moves all the way to the top level. From any position, branches and leafs can be
browsed.
ShowBranches and ShowLeafs should not be called from inside a For Each loop.
The reason for this restriction is when in a For Each loop or a loop to Count the items, basically
you would be changing the contents of the collection, and the next item has no meaning.
Basically, you should not call ShowBranches and ShowLeafs while looping through the Browse
object's collection. It is legal to call ShowLeafs while in a loop on some other collection.
Example
Dim WithEvents AnOPCServer As OPCServer
Dim ARealOPCServer As String
Dim ARealOPCNodeName As String
Dim AnOPCServerBrowser As OPCBrowser
Dim SomeName As Variant
Set AnOPCServer = New OPCServer
ARealOPCServer = “VendorX.DataAccessCustomServer”
ARealOPCNodeName = “SomeComputerNodeName”
AnOPCServer.Connect(ARealOPCServer, ARealOPCNodeName)
Set browser = AnOPCServer.CreateBrowser
AnOPCServerBrowser.ShowBranches
AnOPCServerBrowser.MoveDown(AnOPCServerBrowser.Item(1) )
AnOPCServerBrowser.DataType = vbInteger
AnOPCServerBrowser.ShowLeafs
’ 1
st
method for getting all names
For I = 1 To AnOPCServerBrowser.Count
30
OPC Data Access Automation Specification2.02
name = AnOPCServerBrowser.Item( I )
’ Or…
name = AnOPCServerBrowser ( I )
listBox.Add
name
Next I
’ 2
nd
method for getting all names
For Each name In AnOPCServerBrowser
listBox.Add
name
Next name
Do'stlaringiz bilan baham: |