📄 frmadditem.frm
字号:
VERSION 5.00
Object = "{6B7E6392-850A-101B-AFC0-4210102A8DA7}#1.3#0"; "COMCTL32.OCX"
Begin VB.Form frmAddItem
Caption = "Add Item"
ClientHeight = 4680
ClientLeft = 60
ClientTop = 345
ClientWidth = 8520
ControlBox = 0 'False
LinkTopic = "Form1"
ScaleHeight = 4680
ScaleWidth = 8520
ShowInTaskbar = 0 'False
StartUpPosition = 1 'CenterOwner
Begin VB.Frame Browsing
Caption = "Browsing"
Height = 2895
Left = 0
TabIndex = 10
Top = 1680
Width = 8415
Begin VB.ComboBox AccessFilter
Height = 315
ItemData = "frmAddItem.frx":0000
Left = 6720
List = "frmAddItem.frx":0010
TabIndex = 18
Text = "Any"
ToolTipText = "Select an access type to filter the list of items displayed"
Top = 360
Width = 1215
End
Begin ComctlLib.ListView lvItemView
Height = 2055
Left = 3960
TabIndex = 14
ToolTipText = "Select an item from this list by double clicking on the item"
Top = 720
Width = 4335
_ExtentX = 7646
_ExtentY = 3625
View = 3
Sorted = -1 'True
LabelWrap = -1 'True
HideSelection = -1 'True
HideColumnHeaders= -1 'True
_Version = 327682
ForeColor = -2147483640
BackColor = -2147483643
BorderStyle = 1
Appearance = 1
NumItems = 0
End
Begin VB.ComboBox DataTypeFilter
Height = 315
ItemData = "frmAddItem.frx":003C
Left = 5400
List = "frmAddItem.frx":006F
TabIndex = 13
Text = "Native"
ToolTipText = "Select a datatype to filter the list of items displayed"
Top = 360
Width = 1215
End
Begin VB.TextBox ItemNameFilter
Height = 285
Left = 3960
TabIndex = 12
Text = "*"
ToolTipText = "Enter a filter expression to reduce the number of item displayed Ex. Temp* , N* , *"
Top = 360
Width = 1335
End
Begin ComctlLib.TreeView tvBranchView
Height = 2535
Left = 120
TabIndex = 11
ToolTipText = "Expand the branches of the browser tree to access individual item names"
Top = 240
Width = 3735
_ExtentX = 6588
_ExtentY = 4471
_Version = 327682
HideSelection = 0 'False
LabelEdit = 1
LineStyle = 1
Style = 7
Appearance = 1
End
Begin VB.Label Label5
Caption = "Access Filter"
Height = 255
Left = 6720
TabIndex = 17
Top = 120
Width = 1095
End
Begin VB.Label Label4
Caption = "Datatype Filter"
Height = 255
Left = 5400
TabIndex = 16
Top = 120
Width = 1095
End
Begin VB.Label Label1
Caption = "Leaf Filter"
Height = 255
Left = 3960
TabIndex = 15
Top = 120
Width = 855
End
End
Begin VB.CommandButton Abort
Caption = "Done"
Height = 375
Left = 6960
TabIndex = 5
ToolTipText = "Click here when you have finished adding tags"
Top = 720
Width = 1455
End
Begin VB.CommandButton AddItem
Caption = "Add Item"
Height = 375
Left = 6960
TabIndex = 4
ToolTipText = "Click here to add a tag to the current group"
Top = 240
Width = 1455
End
Begin VB.CommandButton Validate
Caption = "Validate"
Height = 375
Left = 2640
TabIndex = 3
ToolTipText = "Once you have entered an ItemID and Datatype click here to test the entry"
Top = 720
Width = 1575
End
Begin VB.CheckBox ActiveState
Alignment = 1 'Right Justify
Caption = "Active State:"
Height = 375
Left = 360
TabIndex = 2
ToolTipText = "Set the initial Active state of the item to be added"
Top = 1080
Value = 1 'Checked
Width = 1215
End
Begin VB.ComboBox DataType
Height = 315
ItemData = "frmAddItem.frx":00D4
Left = 960
List = "frmAddItem.frx":0107
TabIndex = 1
Text = "Native"
ToolTipText = "Select the datatype that will be applied to this item"
Top = 720
Width = 1575
End
Begin VB.TextBox ItemID
Height = 285
Left = 960
TabIndex = 0
Text = "Tag.Item001"
ToolTipText = "Enter a valid Item ID String for the server you are using"
Top = 360
Width = 5775
End
Begin VB.Frame Frame1
Caption = "Item Definition"
Height = 1455
Left = 0
TabIndex = 6
Top = 120
Width = 6855
Begin VB.TextBox Report
Height = 285
Left = 2640
Locked = -1 'True
TabIndex = 9
ToolTipText = "This box will report the results of the Validate Item button"
Top = 1080
Width = 4095
End
Begin VB.Label Label2
Caption = "Item ID:"
Height = 255
Left = 360
TabIndex = 8
Top = 240
Width = 615
End
Begin VB.Label Label3
Caption = "Data Type:"
Height = 255
Left = 120
TabIndex = 7
Top = 600
Width = 855
End
End
End
Attribute VB_Name = "frmAddItem"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
' The Add OPC Item form allows the user to set the ItemID,
' DataType, and Active state for an OPC item that will added
' to the selected group. When this form is displayed the
' tvTreeView on the main form is disable to prevent the
' user from invoking an Add group or Add Server menu.
' This form will only be invoke while the user has an
' existing OPC server group selected. This means that
' global variable SelectedOPCGroup and SelectedOPCServer
' will be set.
'
' The Add item form is preconfigured with a simple default
' ItemID string that will work in our
' OPC Servers when running the Simdemo
' project in server. If you are using a driver
' other than our Simulator or using a differnt OPC server
' altogether simply replace this default ItemID with a
' fully qualified item id for the driver or server being used.
' You can also browse the tag space of the server you are connected
' with to receive a list of item IDs.
'
' You'll also notice that I preselect a DataType of "Native" for
' the item. Normally when you add an item to an OPC server
' group you will set the datatype to format that you desire for
' the item. OPC and COM objects in general support many data
' type formats. In some cases you may not know the format of the
' data for ItemID you are trying to register. In these cases you can
' specify what is refered to as either Empty or Native. When
' selecting a datatype of Native you are telling the OPC server
' to pick the default data type of the item for you.
'
' There is one possible problem with using the Native datatype
' and allowing the server to pick the data type. Sometimes the
' default data type for an item is an Unsigned format. At this
' time the Automation Wrapper can have problems with some
' Unsigned datatypes. I have seen a problem with arrays of
' Unsigned values. I have however successfully used Unsigned
' values of single items. In general try to select a data type
' from those presented in the drop down Datatype control.
' For more reference on the datatype available for OPC items
' use the VB help system and search for "VarType Constants"
' You'll also notice that I have provided some array type
' selections. An array data type is built by adding the VB
' Const vbArray + (desired type), you'll see this in the
' DataType combobox's ItemData and on the VB help page.
'
' The Active state allows you to set whether or not the OPC
' item you intend to add will be actively acquiring data or
' idle. The active state of an OPC item is an important tool
' in controlling how an OPC server is talking to you phsyical
' device. The amount of data that an OPC server is gathering
' from a device depends on two factors, the number of actual
' OPC items added to the OPC server/groups and the number of
' those item that are marked as active. This is an important
' consideration. When designing your OPC client application
' you can control the operation of the OPC server by adding
' OPC items and deleting them as need. This works but it
' forces the OPC server to do a great deal of memory allocation
' and releasing as well as potentially interupting the order
' of how data is being polled from the server. A better way
' to control how much data is being acquired by the OPC server
' is to use the active state of the item. By using the active
' state of the item you can essential turn an item off. When
' this occurs the OPC server will stop scanning that item from
' the physical device. This of course will reduce the
' bandwidth requirements of the OPC server. By using the
' active state of the item instead of adding and deleting the
' items you allow the OPC server to operate at peak performance.
'
' The AddItem form also demonstrates another important and
' useful component of the OPC inteface, that is the Validate
' method found on the OPCItems object of the Automation
' Wrapper. The Validate method allows you to ask the OPC
' server if the ItemID, DataType, and Active State of the item
' you intend to add is valid. Essentially the Validate
' method is just like calling the acutal AddItem mehtod but
' it doesn't actually add the item to the server. The OPC
' server will return error status of the item. This is a great
' way to let the users of your OPC client application known
' that the item they are entering is valid
'
' Just like the Add OPC Group form, the actual addition of the
' OPC item occurs over in frmMain since this is where the item
' will be added to the lvListView control. The actual
' AddOPCItem function of the OPCGroupClass is shown in frmMain.
' Calling the ValidateOPCItem of the OPCGroupClass is shown
' here directly.
'
' This form also handles most of tag browsing code for this
' example application. The browse interface is housed in the
' OPCBrowserClass. Most of the actual work is done here since
' majority of the work is in managing the treeviiew and listview
' controls.
'
' I take a simplified approach to maintaining browser sync with the OPC
' server. The browse interface provides a number of method that allow you to
' move up and down the browse tree of the OPC server. You can use these
' methods to change what segment of the server's tag space you can access
' at a given level. In this example I keep track of the various branches
' in the browse space and use this data to do a simple Move operation that
' always starts at the root of the server browse space. In this way it
' would be pretty hard to get out of sync with the server.
Option Explicit
Option Base 1
' This object is returned from the OPCServerClass function
' GetServerBrowseObject. The OPCBrowserClass object is a relative thin
' wrapper for the Automation browse object.
'
Dim OPCBrowserClassObj As OPCBrowserClass
' The variable is used to generate a number of dummy treeview
' nodes that allow the tree to always have an expansion available.
' In this way we can get the data for each branch of the browse
' space when the user expands a branch. You will see the
' addition of the Dummy node each time a branch is collapsed.
' By the same token the dummy node is removed before the branch is
' completely expanded so the user never sees this phatom node.
'
Dim DummyNodeNum As Integer
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -