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

📄 frmmain.vb

📁 microsoft winusb interface for vb
💻 VB
📖 第 1 页 / 共 4 页
字号:
Option Strict On
Option Explicit On
Imports System.Runtime.InteropServices

'''<summary>
''' Project: WinUsb_vb
''' 
''' ***********************************************************************
''' Software License Agreement
'''
''' Licensor grants any person obtaining a copy of this software ("You") 
''' a worldwide, royalty-free, non-exclusive license, for the duration of 
''' the copyright, free of charge, to store and execute the Software in a 
''' computer system and to incorporate the Software or any portion of it 
''' in computer programs You write.   
''' 
''' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
''' IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
''' FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
''' AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
''' LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
''' OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
''' THE SOFTWARE.
''' ***********************************************************************
''' 
''' Author               Date        Version
''' Jan Axelson          3/05/08     1.1
''' 
''' This software was written using Visual Basic 2005 Professional Edition.
''' 
''' Purpose: 
''' Demonstrates USB communications using the Microsoft WinUSB driver.
''' 
''' Requirements:
''' Windows XP or later and an attached USB device that uses the WinUSB driver.
''' 
''' Description:
''' Finds an attached device whose INF file contains a specific device interface GUID.
''' Enables sending and receiving data via bulk, interrupt, and control transfers.
''' 
''' Uses RegisterDeviceNotification() and WM_DEVICE_CHANGE messages
''' to detect when a device is attached or removed.
''' 
''' For bulk and interrupt transfers, the application uses a Delegate and the BeginInvoke 
''' and EndInvoke methods to read data asynchronously, so the application's main thread 
''' doesn't have to wait for the device to return data. A callback routine uses 
''' marshaling to send data to the form, whose code runs in a different thread. 
'''  
''' This software, an example INF file, and companion device firmware are available from 
''' www.Lvr.com
''' 
''' Send comments, bug reports, etc. to jan@Lvr.com 
''' This application has been tested under Windows XP and Windows Vista.
''' 
''' Known issues:
''' 
''' In GetReceivedBulkData and GetReceivedInterruptData, in the EndInvoke method, bytesRead 
''' always returns zero even when data is returned. (Doesn't affect the returned data.) 
''' </summary>

Friend Class frmMain
    Inherits System.Windows.Forms.Form
#Region "Windows Form Designer generated code "
    Public Sub New()
        MyBase.New()

        '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
    Private components As System.ComponentModel.IContainer
    Public ToolTip1 As System.Windows.Forms.ToolTip
    Public WithEvents tmrContinuousDataCollect As System.Windows.Forms.Timer
    Public WithEvents cmdSendandRecieveViaBulkTransfers As System.Windows.Forms.Button
    Public WithEvents fraControlInTransfer As System.Windows.Forms.GroupBox
    Public WithEvents txtBulkDataToSend As System.Windows.Forms.TextBox
    Public WithEvents fraBulkTransfer As System.Windows.Forms.GroupBox
    Public WithEvents cboInterruptOutByte1 As System.Windows.Forms.ComboBox
    Public WithEvents cboInterruptOutByte0 As System.Windows.Forms.ComboBox
    Public WithEvents fraInterruptTransfer As System.Windows.Forms.GroupBox
    Public WithEvents tmrDelay As System.Windows.Forms.Timer
    Public WithEvents lstResults As System.Windows.Forms.ListBox
    '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 cmdFindDevice As System.Windows.Forms.Button
    Friend WithEvents cmdSendAndReceiveViaInterruptTransfers As System.Windows.Forms.Button
    Public WithEvents fraControlOutTransfer As System.Windows.Forms.GroupBox
    Friend WithEvents cmdControlWriteTransfer As System.Windows.Forms.Button
    Public WithEvents cboControlOutByte1 As System.Windows.Forms.ComboBox
    Public WithEvents cboControlOutByte0 As System.Windows.Forms.ComboBox
    Friend WithEvents cmdControlReadTransfer As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Me.ToolTip1 = New System.Windows.Forms.ToolTip(Me.components)
        Me.tmrContinuousDataCollect = New System.Windows.Forms.Timer(Me.components)
        Me.fraControlInTransfer = New System.Windows.Forms.GroupBox
        Me.cmdControlReadTransfer = New System.Windows.Forms.Button
        Me.cmdSendandRecieveViaBulkTransfers = New System.Windows.Forms.Button
        Me.fraBulkTransfer = New System.Windows.Forms.GroupBox
        Me.txtBulkDataToSend = New System.Windows.Forms.TextBox
        Me.fraInterruptTransfer = New System.Windows.Forms.GroupBox
        Me.cmdSendAndReceiveViaInterruptTransfers = New System.Windows.Forms.Button
        Me.cboInterruptOutByte1 = New System.Windows.Forms.ComboBox
        Me.cboInterruptOutByte0 = New System.Windows.Forms.ComboBox
        Me.tmrDelay = New System.Windows.Forms.Timer(Me.components)
        Me.lstResults = New System.Windows.Forms.ListBox
        Me.cmdFindDevice = New System.Windows.Forms.Button
        Me.fraControlOutTransfer = New System.Windows.Forms.GroupBox
        Me.cboControlOutByte1 = New System.Windows.Forms.ComboBox
        Me.cboControlOutByte0 = New System.Windows.Forms.ComboBox
        Me.cmdControlWriteTransfer = New System.Windows.Forms.Button
        Me.fraControlInTransfer.SuspendLayout()
        Me.fraBulkTransfer.SuspendLayout()
        Me.fraInterruptTransfer.SuspendLayout()
        Me.fraControlOutTransfer.SuspendLayout()
        Me.SuspendLayout()
        '
        'tmrContinuousDataCollect
        '
        Me.tmrContinuousDataCollect.Interval = 1
        '
        'fraControlInTransfer
        '
        Me.fraControlInTransfer.BackColor = System.Drawing.SystemColors.Control
        Me.fraControlInTransfer.Controls.Add(Me.cmdControlReadTransfer)
        Me.fraControlInTransfer.Font = New System.Drawing.Font("Arial", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.fraControlInTransfer.ForeColor = System.Drawing.SystemColors.ControlText
        Me.fraControlInTransfer.Location = New System.Drawing.Point(237, 27)
        Me.fraControlInTransfer.Name = "fraControlInTransfer"
        Me.fraControlInTransfer.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.fraControlInTransfer.Size = New System.Drawing.Size(148, 94)
        Me.fraControlInTransfer.TabIndex = 7
        Me.fraControlInTransfer.TabStop = False
        Me.fraControlInTransfer.Text = "Control IN Transfer"
        '
        'cmdControlReadTransfer
        '
        Me.cmdControlReadTransfer.Font = New System.Drawing.Font("Arial", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.cmdControlReadTransfer.Location = New System.Drawing.Point(35, 28)
        Me.cmdControlReadTransfer.Name = "cmdControlReadTransfer"
        Me.cmdControlReadTransfer.Size = New System.Drawing.Size(71, 36)
        Me.cmdControlReadTransfer.TabIndex = 12
        Me.cmdControlReadTransfer.Text = "Send"
        Me.cmdControlReadTransfer.UseVisualStyleBackColor = True
        '
        'cmdSendandRecieveViaBulkTransfers
        '
        Me.cmdSendandRecieveViaBulkTransfers.BackColor = System.Drawing.SystemColors.Control
        Me.cmdSendandRecieveViaBulkTransfers.Cursor = System.Windows.Forms.Cursors.Default
        Me.cmdSendandRecieveViaBulkTransfers.Font = New System.Drawing.Font("Arial", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.cmdSendandRecieveViaBulkTransfers.ForeColor = System.Drawing.SystemColors.ControlText
        Me.cmdSendandRecieveViaBulkTransfers.Location = New System.Drawing.Point(256, 24)
        Me.cmdSendandRecieveViaBulkTransfers.Name = "cmdSendandRecieveViaBulkTransfers"
        Me.cmdSendandRecieveViaBulkTransfers.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.cmdSendandRecieveViaBulkTransfers.Size = New System.Drawing.Size(71, 36)
        Me.cmdSendandRecieveViaBulkTransfers.TabIndex = 8
        Me.cmdSendandRecieveViaBulkTransfers.Text = "Send"
        Me.cmdSendandRecieveViaBulkTransfers.UseVisualStyleBackColor = False
        '
        'fraBulkTransfer
        '
        Me.fraBulkTransfer.BackColor = System.Drawing.SystemColors.Control
        Me.fraBulkTransfer.Controls.Add(Me.txtBulkDataToSend)
        Me.fraBulkTransfer.Controls.Add(Me.cmdSendandRecieveViaBulkTransfers)
        Me.fraBulkTransfer.Font = New System.Drawing.Font("Arial", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.fraBulkTransfer.ForeColor = System.Drawing.SystemColors.ControlText
        Me.fraBulkTransfer.Location = New System.Drawing.Point(16, 139)
        Me.fraBulkTransfer.Name = "fraBulkTransfer"
        Me.fraBulkTransfer.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.fraBulkTransfer.Size = New System.Drawing.Size(341, 89)
        Me.fraBulkTransfer.TabIndex = 4
        Me.fraBulkTransfer.TabStop = False
        Me.fraBulkTransfer.Text = "Bulk Transfers"
        '
        'txtBulkDataToSend
        '
        Me.txtBulkDataToSend.AcceptsReturn = True
        Me.txtBulkDataToSend.BackColor = System.Drawing.SystemColors.Window
        Me.txtBulkDataToSend.Cursor = System.Windows.Forms.Cursors.IBeam
        Me.txtBulkDataToSend.Font = New System.Drawing.Font("Arial", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.txtBulkDataToSend.ForeColor = System.Drawing.SystemColors.WindowText
        Me.txtBulkDataToSend.Location = New System.Drawing.Point(16, 19)
        Me.txtBulkDataToSend.MaxLength = 0
        Me.txtBulkDataToSend.Multiline = True
        Me.txtBulkDataToSend.Name = "txtBulkDataToSend"
        Me.txtBulkDataToSend.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.txtBulkDataToSend.ScrollBars = System.Windows.Forms.ScrollBars.Both
        Me.txtBulkDataToSend.Size = New System.Drawing.Size(224, 59)
        Me.txtBulkDataToSend.TabIndex = 5
        Me.txtBulkDataToSend.Text = "bulk transfer test data"
        '
        'fraInterruptTransfer
        '
        Me.fraInterruptTransfer.BackColor = System.Drawing.SystemColors.Control
        Me.fraInterruptTransfer.Controls.Add(Me.cmdSendAndReceiveViaInterruptTransfers)
        Me.fraInterruptTransfer.Controls.Add(Me.cboInterruptOutByte1)
        Me.fraInterruptTransfer.Controls.Add(Me.cboInterruptOutByte0)
        Me.fraInterruptTransfer.Font = New System.Drawing.Font("Arial", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.fraInterruptTransfer.ForeColor = System.Drawing.SystemColors.ControlText
        Me.fraInterruptTransfer.Location = New System.Drawing.Point(379, 139)
        Me.fraInterruptTransfer.Name = "fraInterruptTransfer"
        Me.fraInterruptTransfer.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.fraInterruptTransfer.Size = New System.Drawing.Size(180, 89)
        Me.fraInterruptTransfer.TabIndex = 1
        Me.fraInterruptTransfer.TabStop = False
        Me.fraInterruptTransfer.Text = "Interrupt Transfers"
        '
        'cmdSendAndReceiveViaInterruptTransfers
        '
        Me.cmdSendAndReceiveViaInterruptTransfers.Font = New System.Drawing.Font("Arial", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.cmdSendAndReceiveViaInterruptTransfers.Location = New System.Drawing.Point(98, 24)
        Me.cmdSendAndReceiveViaInterruptTransfers.Name = "cmdSendAndReceiveViaInterruptTransfers"
        Me.cmdSendAndReceiveViaInterruptTransfers.Size = New System.Drawing.Size(71, 36)
        Me.cmdSendAndReceiveViaInterruptTransfers.TabIndex = 7
        Me.cmdSendAndReceiveViaInterruptTransfers.Text = "Send"
        Me.cmdSendAndReceiveViaInterruptTransfers.UseVisualStyleBackColor = True
        '
        'cboInterruptOutByte1
        '
        Me.cboInterruptOutByte1.BackColor = System.Drawing.SystemColors.Window
        Me.cboInterruptOutByte1.Cursor = System.Windows.Forms.Cursors.Default
        Me.cboInterruptOutByte1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
        Me.cboInterruptOutByte1.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.cboInterruptOutByte1.ForeColor = System.Drawing.SystemColors.WindowText
        Me.cboInterruptOutByte1.Location = New System.Drawing.Point(8, 56)
        Me.cboInterruptOutByte1.Name = "cboInterruptOutByte1"
        Me.cboInterruptOutByte1.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.cboInterruptOutByte1.Size = New System.Drawing.Size(74, 22)
        Me.cboInterruptOutByte1.TabIndex = 3
        '
        'cboInterruptOutByte0
        '
        Me.cboInterruptOutByte0.BackColor = System.Drawing.SystemColors.Window
        Me.cboInterruptOutByte0.Cursor = System.Windows.Forms.Cursors.Default
        Me.cboInterruptOutByte0.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
        Me.cboInterruptOutByte0.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.cboInterruptOutByte0.ForeColor = System.Drawing.SystemColors.WindowText
        Me.cboInterruptOutByte0.Location = New System.Drawing.Point(8, 24)
        Me.cboInterruptOutByte0.Name = "cboInterruptOutByte0"
        Me.cboInterruptOutByte0.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.cboInterruptOutByte0.Size = New System.Drawing.Size(72, 22)
        Me.cboInterruptOutByte0.TabIndex = 2
        '
        'tmrDelay
        '
        Me.tmrDelay.Interval = 1
        '
        'lstResults
        '
        Me.lstResults.BackColor = System.Drawing.SystemColors.Window
        Me.lstResults.Cursor = System.Windows.Forms.Cursors.Default
        Me.lstResults.Font = New System.Drawing.Font("Arial", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lstResults.ForeColor = System.Drawing.SystemColors.WindowText
        Me.lstResults.HorizontalScrollbar = True
        Me.lstResults.ItemHeight = 16
        Me.lstResults.Location = New System.Drawing.Point(16, 248)
        Me.lstResults.Name = "lstResults"
        Me.lstResults.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.lstResults.Size = New System.Drawing.Size(543, 196)
        Me.lstResults.TabIndex = 0
        '
        'cmdFindDevice
        '
        Me.cmdFindDevice.Font = New System.Drawing.Font("Arial", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.cmdFindDevice.Location = New System.Drawing.Point(446, 44)
        Me.cmdFindDevice.Name = "cmdFindDevice"
        Me.cmdFindDevice.Size = New System.Drawing.Size(102, 59)
        Me.cmdFindDevice.TabIndex = 11
        Me.cmdFindDevice.Text = "Find My Device"
        '
        'fraControlOutTransfer
        '
        Me.fraControlOutTransfer.BackColor = System.Drawing.SystemColors.Control
        Me.fraControlOutTransfer.Controls.Add(Me.cboControlOutByte1)
        Me.fraControlOutTransfer.Controls.Add(Me.cboControlOutByte0)
        Me.fraControlOutTransfer.Controls.Add(Me.cmdControlWriteTransfer)
        Me.fraControlOutTransfer.Font = New System.Drawing.Font("Arial", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.fraControlOutTransfer.ForeColor = System.Drawing.SystemColors.ControlText
        Me.fraControlOutTransfer.Location = New System.Drawing.Point(16, 25)
        Me.fraControlOutTransfer.Name = "fraControlOutTransfer"
        Me.fraControlOutTransfer.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.fraControlOutTransfer.Size = New System.Drawing.Size(193, 96)
        Me.fraControlOutTransfer.TabIndex = 12
        Me.fraControlOutTransfer.TabStop = False
        Me.fraControlOutTransfer.Text = "Control OUT Transfer"
        '
        'cboControlOutByte1
        '
        Me.cboControlOutByte1.BackColor = System.Drawing.SystemColors.Window
        Me.cboControlOutByte1.Cursor = System.Windows.Forms.Cursors.Default
        Me.cboControlOutByte1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
        Me.cboControlOutByte1.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.cboControlOutByte1.ForeColor = System.Drawing.SystemColors.WindowText
        Me.cboControlOutByte1.Location = New System.Drawing.Point(16, 58)
        Me.cboControlOutByte1.Name = "cboControlOutByte1"
        Me.cboControlOutByte1.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.cboControlOutByte1.Size = New System.Drawing.Size(67, 22)
        Me.cboControlOutByte1.TabIndex = 15
        '
        'cboControlOutByte0
        '
        Me.cboControlOutByte0.BackColor = System.Drawing.SystemColors.Window
        Me.cboControlOutByte0.Cursor = System.Windows.Forms.Cursors.Default
        Me.cboControlOutByte0.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
        Me.cboControlOutByte0.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.cboControlOutByte0.ForeColor = System.Drawing.SystemColors.WindowText
        Me.cboControlOutByte0.Location = New System.Drawing.Point(16, 30)
        Me.cboControlOutByte0.Name = "cboControlOutByte0"
        Me.cboControlOutByte0.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.cboControlOutByte0.Size = New System.Drawing.Size(67, 22)
        Me.cboControlOutByte0.TabIndex = 14
        '
        'cmdControlWriteTransfer
        '
        Me.cmdControlWriteTransfer.Font = New System.Drawing.Font("Arial", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.cmdControlWriteTransfer.Location = New System.Drawing.Point(102, 30)
        Me.cmdControlWriteTransfer.Name = "cmdControlWriteTransfer"
        Me.cmdControlWriteTransfer.Size = New System.Drawing.Size(71, 36)
        Me.cmdControlWriteTransfer.TabIndex = 13
        Me.cmdControlWriteTransfer.Text = "Send"
        Me.cmdControlWriteTransfer.UseVisualStyleBackColor = True
        '
        'frmMain
        '
        Me.ClientSize = New System.Drawing.Size(579, 469)

⌨️ 快捷键说明

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