⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frmmain.vb

📁 visual basic 2005 express 写的上位机
💻 VB
📖 第 1 页 / 共 4 页
字号:
Option Strict Off
Option Explicit On
Imports System.Runtime.InteropServices



Friend Class frmMain
    Inherits System.Windows.Forms.Form
#Region "Windows Form Designer generated code "
    Public Sub New()
        MyBase.New()
        If m_vb6FormDefInstance Is Nothing Then
            If m_InitializingDefInstance Then
                m_vb6FormDefInstance = Me
            Else
                Try
                    'For the start-up form, the first instance created is the default instance.
                    If System.Reflection.Assembly.GetExecutingAssembly.EntryPoint.DeclaringType Is Me.GetType Then
                        m_vb6FormDefInstance = Me
                    End If
                Catch
                End Try
            End If
        End If
        'This call is required by the Windows Form Designer.
        InitializeComponent()
    End Sub
    'Form overrides dispose to clean up the component list.
    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
    'Required by the Windows Form Designer

    Public InputReportBuffer(8) As Byte
    Public OutBuffer(8) As Byte
    Public InBuffer(8) As Byte
    Public LEDCommand As Byte


    Private components As System.ComponentModel.IContainer
    Public WithEvents tmrContinuousDataCollect As System.Windows.Forms.Timer
    Public WithEvents cmdContinuous As System.Windows.Forms.Button
    Public WithEvents cmdOnce As System.Windows.Forms.Button
    Public WithEvents fraSendAndReceive As System.Windows.Forms.GroupBox
    Public WithEvents tmrDelay As System.Windows.Forms.Timer
    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.
    'Do not modify it using the code editor.
    Friend WithEvents fraInputReportBufferSize As System.Windows.Forms.GroupBox
    Friend WithEvents txtInputReportBufferSize As System.Windows.Forms.TextBox
    Friend WithEvents cmdInputReportBufferSize As System.Windows.Forms.Button
    Friend WithEvents fraDeviceIdentifiers As System.Windows.Forms.GroupBox
    Friend WithEvents lblVendorID As System.Windows.Forms.Label
    Friend WithEvents txtVendorID As System.Windows.Forms.TextBox
    Friend WithEvents lblProductID As System.Windows.Forms.Label
    Friend WithEvents txtProductID As System.Windows.Forms.TextBox
    Friend WithEvents ProgressBar1 As System.Windows.Forms.ProgressBar
    Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
    Friend WithEvents GroupBox2 As System.Windows.Forms.GroupBox
    Friend WithEvents Button_LEDOnOff As System.Windows.Forms.Button
    Friend WithEvents LEDStatus As System.Windows.Forms.Button
    Friend WithEvents SWStatus As System.Windows.Forms.Button
    Friend WithEvents GroupBox3 As System.Windows.Forms.GroupBox
    Friend WithEvents GroupBox4 As System.Windows.Forms.GroupBox
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents TextofTemperature As System.Windows.Forms.TextBox
    Friend WithEvents cmdFindDevice As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Me.tmrContinuousDataCollect = New System.Windows.Forms.Timer(Me.components)
        Me.fraSendAndReceive = New System.Windows.Forms.GroupBox
        Me.cmdContinuous = New System.Windows.Forms.Button
        Me.cmdOnce = New System.Windows.Forms.Button
        Me.tmrDelay = New System.Windows.Forms.Timer(Me.components)
        Me.fraInputReportBufferSize = New System.Windows.Forms.GroupBox
        Me.cmdInputReportBufferSize = New System.Windows.Forms.Button
        Me.txtInputReportBufferSize = New System.Windows.Forms.TextBox
        Me.fraDeviceIdentifiers = New System.Windows.Forms.GroupBox
        Me.txtProductID = New System.Windows.Forms.TextBox
        Me.lblProductID = New System.Windows.Forms.Label
        Me.txtVendorID = New System.Windows.Forms.TextBox
        Me.lblVendorID = New System.Windows.Forms.Label
        Me.cmdFindDevice = New System.Windows.Forms.Button
        Me.ProgressBar1 = New System.Windows.Forms.ProgressBar
        Me.GroupBox1 = New System.Windows.Forms.GroupBox
        Me.GroupBox2 = New System.Windows.Forms.GroupBox
        Me.LEDStatus = New System.Windows.Forms.Button
        Me.Button_LEDOnOff = New System.Windows.Forms.Button
        Me.SWStatus = New System.Windows.Forms.Button
        Me.GroupBox3 = New System.Windows.Forms.GroupBox
        Me.GroupBox4 = New System.Windows.Forms.GroupBox
        Me.Label1 = New System.Windows.Forms.Label
        Me.TextofTemperature = New System.Windows.Forms.TextBox
        Me.fraSendAndReceive.SuspendLayout()
        Me.fraInputReportBufferSize.SuspendLayout()
        Me.fraDeviceIdentifiers.SuspendLayout()
        Me.GroupBox1.SuspendLayout()
        Me.GroupBox2.SuspendLayout()
        Me.GroupBox3.SuspendLayout()
        Me.GroupBox4.SuspendLayout()
        Me.SuspendLayout()
        '
        'tmrContinuousDataCollect
        '
        '
        'fraSendAndReceive
        '
        Me.fraSendAndReceive.BackColor = System.Drawing.SystemColors.Control
        Me.fraSendAndReceive.Controls.Add(Me.cmdContinuous)
        Me.fraSendAndReceive.Controls.Add(Me.cmdOnce)
        Me.fraSendAndReceive.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.fraSendAndReceive.ForeColor = System.Drawing.SystemColors.ControlText
        Me.fraSendAndReceive.Location = New System.Drawing.Point(613, 16)
        Me.fraSendAndReceive.Name = "fraSendAndReceive"
        Me.fraSendAndReceive.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.fraSendAndReceive.Size = New System.Drawing.Size(176, 137)
        Me.fraSendAndReceive.TabIndex = 7
        Me.fraSendAndReceive.TabStop = False
        Me.fraSendAndReceive.Text = "Send and Receive Data"
        '
        'cmdContinuous
        '
        Me.cmdContinuous.BackColor = System.Drawing.SystemColors.Control
        Me.cmdContinuous.Cursor = System.Windows.Forms.Cursors.Default
        Me.cmdContinuous.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.cmdContinuous.ForeColor = System.Drawing.SystemColors.ControlText
        Me.cmdContinuous.Location = New System.Drawing.Point(26, 85)
        Me.cmdContinuous.Name = "cmdContinuous"
        Me.cmdContinuous.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.cmdContinuous.Size = New System.Drawing.Size(121, 36)
        Me.cmdContinuous.TabIndex = 9
        Me.cmdContinuous.Text = "Continuous"
        Me.cmdContinuous.UseVisualStyleBackColor = False
        '
        'cmdOnce
        '
        Me.cmdOnce.BackColor = System.Drawing.SystemColors.Control
        Me.cmdOnce.Cursor = System.Windows.Forms.Cursors.Default
        Me.cmdOnce.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.cmdOnce.ForeColor = System.Drawing.SystemColors.ControlText
        Me.cmdOnce.Location = New System.Drawing.Point(26, 27)
        Me.cmdOnce.Name = "cmdOnce"
        Me.cmdOnce.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.cmdOnce.Size = New System.Drawing.Size(121, 36)
        Me.cmdOnce.TabIndex = 8
        Me.cmdOnce.Text = "Once"
        Me.cmdOnce.UseVisualStyleBackColor = False
        '
        'tmrDelay
        '
        Me.tmrDelay.Interval = 1
        '
        'fraInputReportBufferSize
        '
        Me.fraInputReportBufferSize.Controls.Add(Me.cmdInputReportBufferSize)
        Me.fraInputReportBufferSize.Controls.Add(Me.txtInputReportBufferSize)
        Me.fraInputReportBufferSize.Location = New System.Drawing.Point(248, 16)
        Me.fraInputReportBufferSize.Name = "fraInputReportBufferSize"
        Me.fraInputReportBufferSize.Size = New System.Drawing.Size(208, 96)
        Me.fraInputReportBufferSize.TabIndex = 9
        Me.fraInputReportBufferSize.TabStop = False
        Me.fraInputReportBufferSize.Text = "Input Report Buffer Size"
        '
        'cmdInputReportBufferSize
        '
        Me.cmdInputReportBufferSize.Location = New System.Drawing.Point(96, 32)
        Me.cmdInputReportBufferSize.Name = "cmdInputReportBufferSize"
        Me.cmdInputReportBufferSize.Size = New System.Drawing.Size(96, 56)
        Me.cmdInputReportBufferSize.TabIndex = 1
        Me.cmdInputReportBufferSize.Text = "Change Buffer Size"
        '
        'txtInputReportBufferSize
        '
        Me.txtInputReportBufferSize.Location = New System.Drawing.Point(16, 40)
        Me.txtInputReportBufferSize.Name = "txtInputReportBufferSize"
        Me.txtInputReportBufferSize.Size = New System.Drawing.Size(56, 20)
        Me.txtInputReportBufferSize.TabIndex = 0
        '
        'fraDeviceIdentifiers
        '
        Me.fraDeviceIdentifiers.Controls.Add(Me.txtProductID)
        Me.fraDeviceIdentifiers.Controls.Add(Me.lblProductID)
        Me.fraDeviceIdentifiers.Controls.Add(Me.txtVendorID)
        Me.fraDeviceIdentifiers.Controls.Add(Me.lblVendorID)
        Me.fraDeviceIdentifiers.Location = New System.Drawing.Point(16, 16)
        Me.fraDeviceIdentifiers.Name = "fraDeviceIdentifiers"
        Me.fraDeviceIdentifiers.Size = New System.Drawing.Size(208, 96)
        Me.fraDeviceIdentifiers.TabIndex = 10
        Me.fraDeviceIdentifiers.TabStop = False
        Me.fraDeviceIdentifiers.Text = "Device Identifiers"
        '
        'txtProductID
        '
        Me.txtProductID.Location = New System.Drawing.Point(120, 56)
        Me.txtProductID.Name = "txtProductID"
        Me.txtProductID.Size = New System.Drawing.Size(72, 20)
        Me.txtProductID.TabIndex = 3
        Me.txtProductID.Text = "0099"
        '
        'lblProductID
        '
        Me.lblProductID.Location = New System.Drawing.Point(16, 56)
        Me.lblProductID.Name = "lblProductID"
        Me.lblProductID.Size = New System.Drawing.Size(112, 23)
        Me.lblProductID.TabIndex = 2
        Me.lblProductID.Text = "Product ID (hex):"
        '
        'txtVendorID
        '
        Me.txtVendorID.Location = New System.Drawing.Point(120, 24)
        Me.txtVendorID.Name = "txtVendorID"
        Me.txtVendorID.Size = New System.Drawing.Size(72, 20)
        Me.txtVendorID.TabIndex = 1
        Me.txtVendorID.Text = "04d8"
        '
        'lblVendorID
        '
        Me.lblVendorID.Location = New System.Drawing.Point(16, 24)
        Me.lblVendorID.Name = "lblVendorID"
        Me.lblVendorID.Size = New System.Drawing.Size(112, 23)
        Me.lblVendorID.TabIndex = 0
        Me.lblVendorID.Text = "Vendor ID (hex):"
        '
        'cmdFindDevice
        '
        Me.cmdFindDevice.Location = New System.Drawing.Point(473, 52)
        Me.cmdFindDevice.Name = "cmdFindDevice"
        Me.cmdFindDevice.Size = New System.Drawing.Size(121, 40)
        Me.cmdFindDevice.TabIndex = 11
        Me.cmdFindDevice.Text = "Find My Device"
        '
        'ProgressBar1
        '
        Me.ProgressBar1.BackColor = System.Drawing.SystemColors.ActiveCaptionText
        Me.ProgressBar1.ForeColor = System.Drawing.Color.Lime
        Me.ProgressBar1.Location = New System.Drawing.Point(6, 40)
        Me.ProgressBar1.Name = "ProgressBar1"
        Me.ProgressBar1.Size = New System.Drawing.Size(192, 23)
        Me.ProgressBar1.TabIndex = 12
        '
        'GroupBox1
        '
        Me.GroupBox1.Controls.Add(Me.ProgressBar1)
        Me.GroupBox1.Location = New System.Drawing.Point(16, 152)
        Me.GroupBox1.Name = "GroupBox1"
        Me.GroupBox1.Size = New System.Drawing.Size(208, 100)
        Me.GroupBox1.TabIndex = 13
        Me.GroupBox1.TabStop = False
        Me.GroupBox1.Text = "ADC Value"
        '
        'GroupBox2
        '
        Me.GroupBox2.Controls.Add(Me.LEDStatus)
        Me.GroupBox2.Controls.Add(Me.Button_LEDOnOff)
        Me.GroupBox2.Location = New System.Drawing.Point(250, 152)
        Me.GroupBox2.Name = "GroupBox2"
        Me.GroupBox2.Size = New System.Drawing.Size(205, 99)
        Me.GroupBox2.TabIndex = 14
        Me.GroupBox2.TabStop = False
        Me.GroupBox2.Text = "LED ON/OFF"
        '
        'LEDStatus
        '
        Me.LEDStatus.BackColor = System.Drawing.Color.Black
        Me.LEDStatus.Location = New System.Drawing.Point(32, 28)
        Me.LEDStatus.Name = "LEDStatus"
        Me.LEDStatus.Size = New System.Drawing.Size(51, 54)
        Me.LEDStatus.TabIndex = 15
        Me.LEDStatus.UseVisualStyleBackColor = False
        '
        'Button_LEDOnOff
        '
        Me.Button_LEDOnOff.Cursor = System.Windows.Forms.Cursors.Hand
        Me.Button_LEDOnOff.FlatStyle = System.Windows.Forms.FlatStyle.System
        Me.Button_LEDOnOff.Location = New System.Drawing.Point(94, 28)
        Me.Button_LEDOnOff.Name = "Button_LEDOnOff"
        Me.Button_LEDOnOff.Size = New System.Drawing.Size(96, 54)
        Me.Button_LEDOnOff.TabIndex = 15
        Me.Button_LEDOnOff.Text = "LED ON"
        Me.Button_LEDOnOff.UseVisualStyleBackColor = True
        '
        'SWStatus
        '
        Me.SWStatus.BackColor = System.Drawing.Color.Black
        Me.SWStatus.Location = New System.Drawing.Point(32, 29)
        Me.SWStatus.Name = "SWStatus"
        Me.SWStatus.Size = New System.Drawing.Size(51, 54)
        Me.SWStatus.TabIndex = 16
        Me.SWStatus.UseVisualStyleBackColor = False
        '
        'GroupBox3
        '
        Me.GroupBox3.Controls.Add(Me.SWStatus)
        Me.GroupBox3.Location = New System.Drawing.Point(473, 151)
        Me.GroupBox3.Name = "GroupBox3"
        Me.GroupBox3.Size = New System.Drawing.Size(121, 100)
        Me.GroupBox3.TabIndex = 17
        Me.GroupBox3.TabStop = False
        Me.GroupBox3.Text = "S2 Status"
        '
        'GroupBox4
        '
        Me.GroupBox4.Controls.Add(Me.Label1)
        Me.GroupBox4.Controls.Add(Me.TextofTemperature)
        Me.GroupBox4.Location = New System.Drawing.Point(608, 159)
        Me.GroupBox4.Name = "GroupBox4"
        Me.GroupBox4.Size = New System.Drawing.Size(180, 91)
        Me.GroupBox4.TabIndex = 18
        Me.GroupBox4.TabStop = False
        Me.GroupBox4.Text = "Temperature"
        '
        'Label1
        '
        Me.Label1.AutoSize = True
        Me.Label1.Location = New System.Drawing.Point(116, 30)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(36, 14)
        Me.Label1.TabIndex = 1
        Me.Label1.Text = "Deg.C"
        '
        'TextofTemperature
        '
        Me.TextofTemperature.Location = New System.Drawing.Point(13, 27)
        Me.TextofTemperature.Name = "TextofTemperature"
        Me.TextofTemperature.Size = New System.Drawing.Size(97, 20)
        Me.TextofTemperature.TabIndex = 0
        '
        'frmMain
        '
        Me.ClientSize = New System.Drawing.Size(792, 396)
        Me.Controls.Add(Me.GroupBox4)
        Me.Controls.Add(Me.GroupBox3)
        Me.Controls.Add(Me.GroupBox2)
        Me.Controls.Add(Me.GroupBox1)
        Me.Controls.Add(Me.cmdFindDevice)
        Me.Controls.Add(Me.fraDeviceIdentifiers)
        Me.Controls.Add(Me.fraInputReportBufferSize)
        Me.Controls.Add(Me.fraSendAndReceive)
        Me.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Location = New System.Drawing.Point(21, 28)
        Me.Name = "frmMain"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.Manual
        Me.Text = "USB Training-Lawrence"
        Me.fraSendAndReceive.ResumeLayout(False)
        Me.fraInputReportBufferSize.ResumeLayout(False)
        Me.fraInputReportBufferSize.PerformLayout()
        Me.fraDeviceIdentifiers.ResumeLayout(False)
        Me.fraDeviceIdentifiers.PerformLayout()
        Me.GroupBox1.ResumeLayout(False)
        Me.GroupBox2.ResumeLayout(False)
        Me.GroupBox3.ResumeLayout(False)
        Me.GroupBox4.ResumeLayout(False)
        Me.GroupBox4.PerformLayout()
        Me.ResumeLayout(False)

    End Sub
#End Region
#Region "Upgrade Support "
    Private Shared m_vb6FormDefInstance As frmMain
    Private Shared m_InitializingDefInstance As Boolean
    Public Shared Property DefInstance() As frmMain
        Get
            If m_vb6FormDefInstance Is Nothing OrElse m_vb6FormDefInstance.IsDisposed Then
                m_InitializingDefInstance = True
                m_vb6FormDefInstance = New frmMain()
                m_InitializingDefInstance = False
            End If
            DefInstance = m_vb6FormDefInstance
        End Get
        Set(ByVal Value As frmMain)
            m_vb6FormDefInstance = Value
        End Set
    End Property
#End Region

    'Project: usbhidio_vbdotnet
    'Version: 2.3
    'Date: 8/29/05
    '
    'This version is written using Visual Basic 2005 Express Edition, Beta 2, available from:
    ' http://lab.msdn.microsoft.com/express
    'This version does not compile and run on earlier editions of Visual Studio.

    'Purpose: 
    'Demonstrates USB communications with a generic HID-class device

    'Description:
    'Finds an attached device that matches the vendor and product IDs in the form's 
    'text boxes.
    'Retrieves the device's capabilities.
    'Sends and requests HID reports.

    'Uses RegisterDeviceNotification() and WM_DEVICE_CHANGE messages
    'to detect when a device is attached or removed.
    'RegisterDeviceNotification doesn't work under Windows 98 (not sure why).

    'A list box displays the data sent and received,
    'along with error and status messages.

    'Combo boxes select data to send, and 1-time or timed, periodic transfers.

    'You can change the size of the host's Input report buffer and request to use control
    'transfers only to exchange Input and Output reports.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -