📄 form1.vb
字号:
'==============================================================================
' TITLE: Form1.vb
'
' CONTENTS:
'
'
' (c) Copyright 2004 Takebishi Electric Sales Corporation
' ALL RIGHTS RESERVED.
'
' DISCLAIMER:
' This code is provided by the Takebishi Electric Sales Corporation solely
' to assist in understanding and use of the appropriate OPC Specification(s).
' This code is provided as-is and without warranty or support of any sort.
'==============================================================================
Option Strict Off
Option Explicit On
Imports System.Runtime.InteropServices
Public Class Form1
Inherits System.Windows.Forms.Form
Const ITEMMAX = 8
Const STR_OPC_INI As String = "OPCSample.ini"
Const VAL_CTRL_SPACE = 8
Const VAL_CTRL_TOP = 192
Const VAL_CTRL_LEFT = 16
Const VAL_ITEMNAME_HEIGHT = 24
Const VAL_ITEMNAME_WIDTH = 88
Const VAL_VALUE_HEIGHT = VAL_ITEMNAME_HEIGHT
Const VAL_VALUE_WIDTH = 48
Const VAL_TIME_HEIGHT = VAL_ITEMNAME_HEIGHT
Const VAL_TIME_WIDTH = 128
Const VAL_QUALITY_HEIGHT = VAL_ITEMNAME_HEIGHT
Const VAL_QUALITY_WIDTH = 40
Dim WithEvents OPCMyServer As OPCAutomation.OPCServer
Dim WithEvents OPCMyGroups As OPCAutomation.OPCGroups
Dim WithEvents OPCMyGroup As OPCAutomation.OPCGroup
Dim OPCMyItems As OPCAutomation.OPCItems
Dim OPCMyItem As OPCAutomation.OPCItem
Dim sItemName(ITEMMAX) As String
Dim cH(ITEMMAX) As Integer
Dim sH(ITEMMAX) As Integer
Dim oVal(ITEMMAX) As Object
Dim dTime(ITEMMAX) As Date
Dim wQuality(ITEMMAX) As Short
Dim bConnect As Boolean
Dim txtItemName(ITEMMAX - 1) As System.Windows.Forms.TextBox
Dim txtValue(ITEMMAX - 1) As System.Windows.Forms.TextBox
Dim txtTime(ITEMMAX - 1) As System.Windows.Forms.TextBox
Dim txtQuality(ITEMMAX - 1) As System.Windows.Forms.TextBox
Enum COPY_DIR
DISP_TO_MEM ' display to memory
MEM_TO_DISP ' memory to display
End Enum
#Region " Windows 僼僅乕儉 僨僓僀僫偱惗惉偝傟偨僐乕僪 "
Public Sub New()
MyBase.New()
' 偙偺屇傃弌偟偼 Windows 僼僅乕儉 僨僓僀僫偱昁梫偱偡丅
InitializeComponent()
' InitializeComponent() 屇傃弌偟偺屻偵弶婜壔傪捛壛偟傑偡丅
End Sub
' Form 偼丄僐儞億乕僱儞僩堦棗偵屻張棟傪幚峴偡傞偨傔偵 dispose 傪僆乕僶乕儔僀僪偟傑偡丅
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
' Windows 僼僅乕儉 僨僓僀僫偱昁梫偱偡丅
Private components As System.ComponentModel.IContainer
' 儊儌 : 埲壓偺僾儘僔乕僕儍偼丄Windows 僼僅乕儉 僨僓僀僫偱昁梫偱偡丅
'Windows 僼僅乕儉 僨僓僀僫傪巊偭偰曄峏偟偰偔偩偝偄丅
' 僐乕僪 僄僨傿僞傪巊偭偰曄峏偟側偄偱偔偩偝偄丅
Public WithEvents btnAsyncWrite As System.Windows.Forms.Button
Public WithEvents btnAsyncRead As System.Windows.Forms.Button
Public WithEvents txtSvrName As System.Windows.Forms.TextBox
Public WithEvents btnAdvise As System.Windows.Forms.Button
Public WithEvents txtUpdateRate As System.Windows.Forms.TextBox
Public WithEvents btnWrite As System.Windows.Forms.Button
Public WithEvents btnRead As System.Windows.Forms.Button
Public WithEvents btnConnect As System.Windows.Forms.Button
Public WithEvents Label6 As System.Windows.Forms.Label
Public WithEvents Label5 As System.Windows.Forms.Label
Public WithEvents Label4 As System.Windows.Forms.Label
Public WithEvents Label3 As System.Windows.Forms.Label
Public WithEvents Label2 As System.Windows.Forms.Label
Public WithEvents Label1 As System.Windows.Forms.Label
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.btnAsyncWrite = New System.Windows.Forms.Button
Me.btnAsyncRead = New System.Windows.Forms.Button
Me.txtSvrName = New System.Windows.Forms.TextBox
Me.btnAdvise = New System.Windows.Forms.Button
Me.txtUpdateRate = New System.Windows.Forms.TextBox
Me.btnWrite = New System.Windows.Forms.Button
Me.btnRead = New System.Windows.Forms.Button
Me.btnConnect = New System.Windows.Forms.Button
Me.Label6 = New System.Windows.Forms.Label
Me.Label5 = New System.Windows.Forms.Label
Me.Label4 = New System.Windows.Forms.Label
Me.Label3 = New System.Windows.Forms.Label
Me.Label2 = New System.Windows.Forms.Label
Me.Label1 = New System.Windows.Forms.Label
Me.SuspendLayout()
'
'btnAsyncWrite
'
Me.btnAsyncWrite.BackColor = System.Drawing.SystemColors.Control
Me.btnAsyncWrite.Cursor = System.Windows.Forms.Cursors.Default
Me.btnAsyncWrite.Enabled = False
Me.btnAsyncWrite.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.btnAsyncWrite.ForeColor = System.Drawing.SystemColors.ControlText
Me.btnAsyncWrite.Location = New System.Drawing.Point(240, 128)
Me.btnAsyncWrite.Name = "btnAsyncWrite"
Me.btnAsyncWrite.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.btnAsyncWrite.Size = New System.Drawing.Size(104, 32)
Me.btnAsyncWrite.TabIndex = 60
Me.btnAsyncWrite.Text = "Async Write"
'
'btnAsyncRead
'
Me.btnAsyncRead.BackColor = System.Drawing.SystemColors.Control
Me.btnAsyncRead.Cursor = System.Windows.Forms.Cursors.Default
Me.btnAsyncRead.Enabled = False
Me.btnAsyncRead.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.btnAsyncRead.ForeColor = System.Drawing.SystemColors.ControlText
Me.btnAsyncRead.Location = New System.Drawing.Point(128, 128)
Me.btnAsyncRead.Name = "btnAsyncRead"
Me.btnAsyncRead.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.btnAsyncRead.Size = New System.Drawing.Size(104, 32)
Me.btnAsyncRead.TabIndex = 59
Me.btnAsyncRead.Text = "Async Read"
'
'txtSvrName
'
Me.txtSvrName.Anchor = System.Windows.Forms.AnchorStyles.Left
Me.txtSvrName.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.txtSvrName.Location = New System.Drawing.Point(96, 16)
Me.txtSvrName.Name = "txtSvrName"
Me.txtSvrName.Size = New System.Drawing.Size(136, 20)
Me.txtSvrName.TabIndex = 58
Me.txtSvrName.Text = "Takebishi"
'
'btnAdvise
'
Me.btnAdvise.BackColor = System.Drawing.SystemColors.Control
Me.btnAdvise.Cursor = System.Windows.Forms.Cursors.Default
Me.btnAdvise.Enabled = False
Me.btnAdvise.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.btnAdvise.ForeColor = System.Drawing.SystemColors.ControlText
Me.btnAdvise.Location = New System.Drawing.Point(16, 128)
Me.btnAdvise.Name = "btnAdvise"
Me.btnAdvise.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.btnAdvise.Size = New System.Drawing.Size(104, 32)
Me.btnAdvise.TabIndex = 57
Me.btnAdvise.Text = "Advise"
'
'txtUpdateRate
'
Me.txtUpdateRate.AcceptsReturn = True
Me.txtUpdateRate.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
Or System.Windows.Forms.AnchorStyles.Left) _
Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me.txtUpdateRate.BackColor = System.Drawing.SystemColors.Window
Me.txtUpdateRate.Cursor = System.Windows.Forms.Cursors.IBeam
Me.txtUpdateRate.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.txtUpdateRate.ForeColor = System.Drawing.SystemColors.WindowText
Me.txtUpdateRate.Location = New System.Drawing.Point(96, 40)
Me.txtUpdateRate.MaxLength = 0
Me.txtUpdateRate.Name = "txtUpdateRate"
Me.txtUpdateRate.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.txtUpdateRate.Size = New System.Drawing.Size(64, 19)
Me.txtUpdateRate.TabIndex = 54
Me.txtUpdateRate.Text = "1000"
Me.txtUpdateRate.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
'
'btnWrite
'
Me.btnWrite.BackColor = System.Drawing.SystemColors.Control
Me.btnWrite.Cursor = System.Windows.Forms.Cursors.Default
Me.btnWrite.Enabled = False
Me.btnWrite.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.btnWrite.ForeColor = System.Drawing.SystemColors.ControlText
Me.btnWrite.Location = New System.Drawing.Point(240, 88)
Me.btnWrite.Name = "btnWrite"
Me.btnWrite.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.btnWrite.Size = New System.Drawing.Size(104, 32)
Me.btnWrite.TabIndex = 49
Me.btnWrite.Text = "Write"
'
'btnRead
'
Me.btnRead.BackColor = System.Drawing.SystemColors.Control
Me.btnRead.Cursor = System.Windows.Forms.Cursors.Default
Me.btnRead.Enabled = False
Me.btnRead.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.btnRead.ForeColor = System.Drawing.SystemColors.ControlText
Me.btnRead.Location = New System.Drawing.Point(128, 88)
Me.btnRead.Name = "btnRead"
Me.btnRead.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.btnRead.Size = New System.Drawing.Size(104, 32)
Me.btnRead.TabIndex = 48
Me.btnRead.Text = "Read"
'
'btnConnect
'
Me.btnConnect.BackColor = System.Drawing.SystemColors.Control
Me.btnConnect.Cursor = System.Windows.Forms.Cursors.Default
Me.btnConnect.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.btnConnect.ForeColor = System.Drawing.SystemColors.ControlText
Me.btnConnect.Location = New System.Drawing.Point(240, 16)
Me.btnConnect.Name = "btnConnect"
Me.btnConnect.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.btnConnect.Size = New System.Drawing.Size(104, 32)
Me.btnConnect.TabIndex = 47
Me.btnConnect.Text = "Connect"
'
'Label6
'
Me.Label6.BackColor = System.Drawing.SystemColors.Control
Me.Label6.Cursor = System.Windows.Forms.Cursors.Default
Me.Label6.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label6.ForeColor = System.Drawing.SystemColors.ControlText
Me.Label6.Location = New System.Drawing.Point(16, 40)
Me.Label6.Name = "Label6"
Me.Label6.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.Label6.Size = New System.Drawing.Size(80, 16)
Me.Label6.TabIndex = 56
Me.Label6.Text = "Update Rate"
Me.Label6.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
'
'Label5
'
Me.Label5.Anchor = System.Windows.Forms.AnchorStyles.Left
Me.Label5.BackColor = System.Drawing.SystemColors.Control
Me.Label5.Cursor = System.Windows.Forms.Cursors.Default
Me.Label5.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label5.ForeColor = System.Drawing.SystemColors.ControlText
Me.Label5.Location = New System.Drawing.Point(16, 16)
Me.Label5.Name = "Label5"
Me.Label5.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.Label5.Size = New System.Drawing.Size(80, 16)
Me.Label5.TabIndex = 55
Me.Label5.Text = "Server Name"
Me.Label5.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
'
'Label4
'
Me.Label4.BackColor = System.Drawing.SystemColors.Control
Me.Label4.Cursor = System.Windows.Forms.Cursors.Default
Me.Label4.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label4.ForeColor = System.Drawing.SystemColors.ControlText
Me.Label4.Location = New System.Drawing.Point(304, 176)
Me.Label4.Name = "Label4"
Me.Label4.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.Label4.Size = New System.Drawing.Size(48, 16)
Me.Label4.TabIndex = 53
Me.Label4.Text = "Quality"
'
'Label3
'
Me.Label3.BackColor = System.Drawing.SystemColors.Control
Me.Label3.Cursor = System.Windows.Forms.Cursors.Default
Me.Label3.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label3.ForeColor = System.Drawing.SystemColors.ControlText
Me.Label3.Location = New System.Drawing.Point(168, 176)
Me.Label3.Name = "Label3"
Me.Label3.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.Label3.Size = New System.Drawing.Size(65, 16)
Me.Label3.TabIndex = 52
Me.Label3.Text = "Date/Time"
'
'Label2
'
Me.Label2.BackColor = System.Drawing.SystemColors.Control
Me.Label2.Cursor = System.Windows.Forms.Cursors.Default
Me.Label2.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label2.ForeColor = System.Drawing.SystemColors.ControlText
Me.Label2.Location = New System.Drawing.Point(112, 176)
Me.Label2.Name = "Label2"
Me.Label2.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.Label2.Size = New System.Drawing.Size(41, 16)
Me.Label2.TabIndex = 51
Me.Label2.Text = "Value"
'
'Label1
'
Me.Label1.BackColor = System.Drawing.SystemColors.Control
Me.Label1.Cursor = System.Windows.Forms.Cursors.Default
Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label1.ForeColor = System.Drawing.SystemColors.ControlText
Me.Label1.Location = New System.Drawing.Point(16, 176)
Me.Label1.Name = "Label1"
Me.Label1.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.Label1.Size = New System.Drawing.Size(65, 16)
Me.Label1.TabIndex = 50
Me.Label1.Text = "Item Name"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -