📄 frmwriteitem.frm
字号:
VERSION 5.00
Begin VB.Form frmWriteItem
Caption = "OPC Write Item"
ClientHeight = 2985
ClientLeft = 60
ClientTop = 345
ClientWidth = 6525
ControlBox = 0 'False
LinkTopic = "Form1"
ScaleHeight = 2985
ScaleWidth = 6525
ShowInTaskbar = 0 'False
StartUpPosition = 1 'CenterOwner
Begin VB.CommandButton OkButton
Caption = "Ok"
Height = 375
Left = 5160
TabIndex = 1
Top = 2520
Width = 1215
End
Begin VB.CommandButton ApplyValue
Caption = "Apply Value"
Height = 375
Left = 3720
TabIndex = 0
Top = 2520
Width = 1335
End
Begin VB.Frame Frame1
Caption = "Value to Write"
Height = 2295
Left = 120
TabIndex = 2
Top = 120
Width = 6255
Begin VB.TextBox DataType
Height = 285
Left = 1080
Locked = -1 'True
TabIndex = 11
ToolTipText = "This box simply displays the selected Data Type for reference"
Top = 720
Width = 4935
End
Begin VB.OptionButton BooleanOff
Caption = "Off"
Height = 195
Left = 2040
TabIndex = 9
Top = 1800
Width = 615
End
Begin VB.OptionButton BooleanOn
Caption = "On"
Height = 195
Left = 1320
TabIndex = 8
Top = 1800
Value = -1 'True
Width = 615
End
Begin VB.TextBox ItemID
Height = 285
Left = 1080
Locked = -1 'True
TabIndex = 6
ToolTipText = "This box simply displays the selected ItemID for reference"
Top = 360
Width = 4935
End
Begin VB.TextBox WriteValue
Height = 285
Left = 1080
TabIndex = 3
Text = "0"
ToolTipText = "Enter the value to be written here, for arrays separate each element by a comma"
Top = 1320
Width = 4935
End
Begin VB.Label Label4
Caption = "Data Type:"
Height = 255
Left = 195
TabIndex = 10
Top = 720
Width = 855
End
Begin VB.Label Label3
Caption = "Boolean Value:"
Height = 255
Left = 120
TabIndex = 7
Top = 1800
Width = 1095
End
Begin VB.Label Label1
Caption = "ItemID:"
Height = 255
Left = 480
TabIndex = 5
Top = 360
Width = 495
End
Begin VB.Label Label2
Caption = "Numeric and String Values"
Height = 495
Left = 120
TabIndex = 4
Top = 1200
Width = 1095
End
End
End
Attribute VB_Name = "frmWriteItem"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
' The OPC Write Item form is used to send new data
' to a specific OPC item. The form will automatically
' set itself to accept either numeric, string,
' or boolean input depending on the data type of the
' item selected.
'
' This write operation uses the AsyncWriteOPCItem function
' of the OPCGroupClass object The OPCGroupClass wraps the
' AsyncWrite function of the Automation interface. The
' AsyncWrite function has the benefit of returning control
' immediately to your application. There are other mehtods
' for doing writes to OPC items but using the Async method
' is the best way to insure that your application does not
' get blocked by the write operation of the OPC server.
' When you use the write function directly on an OPC item
' or the SyncWrite function on an OPC group the operation
' is blocked until the OPC server completes the write.
' This includes the round trip time to the physical device
' and back. Depending on your device this could be a long
' wait during which your VB application would appear to be
' locked up. Using the AsyncWrite as shown here insures
' that your VB application can continue to process other
' operations. The results of the write operation is
' return to you later in the AsyncWriteComplete which is
' handled in the OPCGroupClass object. This event will
' place the returned error in the specific Quality field
' of the OPC item.
'
' When the Write item form is displayed it will atempt the
' identify and dsiplay the data type of the item selected.
' If you check the VB help system for VarType Const you'll
' see that some 17 data types are listed. Many of these
' datatypes do not apply to data you will receive from an
' OPC server. There is also the chance you will get back a
' datatype which doesn't fit one of these 17 datatypes.
' When this occurs you are most likely getting back an
' Unsigned Data type. Most of the time the Automation
' Wrapper can handle these unsigned datatypes. I have
' however seen a problem when attempting to write to an
' array of Unsigned short values. This is why I force
' the user to select one of the data types when adding an
' OPC item. I do allow the Native datatype selection which
' allows the OPC server to pick what it thinks is the
' default(canonical) datatype of the item. This is where
' an items datatype can become unsigned.
Option Explicit
' The option Base is not set here since we need an
' array that can start with a lower bound of zero
Dim DataTypes(17) As String
' The ValueChange flag is used to determine if the
' value needs to be written when the OK button is
' pressed. The Apply button allows you to write the
' value each time it is pressed without leaving the
' OPC Write Item form. If you change the value without
' hitting the apply button and exit the dialog with Ok
' button the value will still be sent. If the apply
' button is hit before the Ok button the value will not
' be written on the OK.
Dim ValueChange As Boolean
Private Sub Form_Load()
' Get the Item ID string for reference
ItemID.Text = Module1.SelectedOPCItem.GetItemID
' This list of data types is derived from the VarType Constants
' Some of the data type in the VarType Constants don't apply to
' normal OPC data objects and are therefore marked as invalid
DataTypes(0) = "Native - Data Type is not specific set by OPC Server"
DataTypes(1) = "Invalid Data Type for this example"
DataTypes(2) = "Integer - 16 bit Signed "
DataTypes(3) = "Long - 32 bit Signed "
DataTypes(4) = "Float - 32 bit Float "
DataTypes(5) = "Double - 64 bit Real "
DataTypes(6) = "Invalid Data Type for this example" ' Currency
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -