博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
OPC BROWSER ITEM程序(VB篇)
阅读量:4077 次
发布时间:2019-05-25

本文共 3005 字,大约阅读时间需要 10 分钟。

OPC技术论坛  OPC服务器,客户程序技术讨论

一、VB新建窗体如下
详见相册OPC技术。
二、引用如下
详见相册OPC技术。
三、代码如下
Dim WithEvents g_Server As OPCServer
Dim g_Browser As OPCBrowser

Dim BrowseFilter As Long

Dim Vt_Filter As Integer

Dim nodX As Node
Dim Value As Variant
Dim FullName As String
Dim Relative As String
Dim i As Integer

 

Private Sub cmbAccessRights_Click()

 Select Case cmbAccessRights.Text
    Case "OPC_ACCESS_WRITE"
      g_Browser.AccessRights = OPCWritable
    Case Else
      g_Browser.AccessRights = OPCReadable
  End Select
End Sub

 

 

Private Sub cmbBrowseFilter_Click()

  Select Case cmbBrowseFilter.Text
    Case "OPC_FLAT"
      BrowseFilter = OPC_FLAT
    Case Else
      BrowseFilter = OPC_BRANCH
 End Select
End Sub

Private Sub cmbVtFilter_Click()

  Select Case cmbVtFilter.Text
    Case "VT_EMPTY"
      g_Browser.DataType = VT_EMPTY
    Case "UINT1"
      g_Browser.DataType = VT_UI1
    Case "UINT2"
      g_Browser.DataType = VT_UI2
    Case "TEXT"
      g_Browser.DataType = VT_BSTR
    Case "BOOLEAN"
      g_Browser.DataType = VT_BOOL
  End Select
End Sub

Private Sub Command1_Click()

 Dim i As Integer
  Dim Key As String
 
  MousePointer = 11 ' Mousepointer as hourclass
 
  Set nodX = Nothing
  TreeView.Nodes.Clear
  Select Case BrowseFilter
    Case OPC_FLAT
      BuildFlat
    Case OPC_BRANCH
      BuildTree
  End Select
 
  MousePointer = 0 ' Normal mousepointer
 
End Sub
'----------------------------------------------------------------------------
' Sub BuildFlat()
' Purpose: show all items
'----------------------------------------------------------------------------
Public Sub BuildFlat()
  Dim Key As String
  Dim Leaf As Variant
 
  g_Browser.MoveToRoot
  g_Browser.ShowLeafs True
  For Each Leaf In g_Browser
    i = i + 1
    Key = "#" & i
    Set nodX = TreeView.Nodes.Add(Null, tvwNext, Key, g_Browser.GetItemID(Leaf))
    DoEvents
  Next Leaf
End Sub

'----------------------------------------------------------------------------

' Sub BuildTree()
' Purpose: recursive building of the tree view
'----------------------------------------------------------------------------
Public Sub BuildTree(Optional Relative As Variant)
  Dim Branch, Leaf As Variant
  Dim Key As String
 
  g_Browser.ShowBranches
  For Each Branch In g_Browser
    i = i + 1
    Key = "#" & i
    Set nodX = TreeView.Nodes.Add(Relative, tvwChild, Key, Branch)
    'Go down to next level
    g_Browser.MoveDown (Branch)
    BuildTree (Key)
    'Go up to next level
    g_Browser.MoveUp
    DoEvents
  Next Branch
 
  g_Browser.ShowLeafs False
  For Each Leaf In g_Browser
    i = i + 1
    Key = "#" & i
    Set nodX = TreeView.Nodes.Add(Relative, tvwChild, Key, g_Browser.GetItemID(Leaf))
  Next Leaf
 
End Sub

Private Sub Command2_Click()

 Set g_Server = Nothing
 Set g_Browser = Nothing
 End
End Sub

Private Sub Form_Load()

 Set g_Server = New OPCServer
  g_Server.Connect ("Matrikon.OPC.Simulation")'OPC SERVER名称
  Set g_Browser = g_Server.CreateBrowser
  cmbVtFilter.Text = "VT_EMPTY"
  cmbVtFilter.AddItem "UINT1"
  cmbVtFilter.AddItem "UINT2"
  cmbVtFilter.AddItem "TEXT"
  cmbVtFilter.AddItem "BOOLEAN"
  cmbVtFilter.AddItem "VT_EMPTY"
  BrowseFilter = OPC_BRANCH
  g_Browser.AccessRights = OPCReadable
  g_Browser.DataType = VT_EMPTY
  TreeView.LineStyle = tvwRootLines  ' Linestyle 1

End Sub

转载地址:http://akini.baihongyu.com/

你可能感兴趣的文章
Linux基础教程:CentOS卸载KDE桌面
查看>>
db sql montior
查看>>
read humor_campus
查看>>
IBM WebSphere Commerce Analyzer
查看>>
Unix + OS IBM Aix FTP / wu-ftp / proftp
查看>>
my read work
查看>>
db db2 base / instance database tablespace container
查看>>
hd disk / disk raid / disk io / iops / iostat / iowait / iotop / iometer
查看>>
project ASP.NET
查看>>
db db2_monitorTool IBM Rational Performace Tester
查看>>
OS + Unix Aix telnet
查看>>
IBM Lotus
查看>>
Linux +Win LAMPP Tools XAMPP 1.7.3 / 5.6.3
查看>>
my read_university
查看>>
network manager
查看>>
OS + Linux Disk disk lvm / disk partition / disk mount / disk io
查看>>
RedHat + OS CPU、MEM、DISK
查看>>
net TCP/IP / TIME_WAIT / tcpip / iperf / cain
查看>>
webServer kzserver/1.0.0
查看>>
OS + Unix IBM Aix basic / topas / nmon / filemon / vmstat / iostat / sysstat/sar
查看>>