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

📄 usbio.frm

📁 6个用VB和DELPHI编写的FOR USB驱动程序
💻 FRM
📖 第 1 页 / 共 5 页
字号:
         TabIndex        =   113
         Top             =   360
         Width           =   3255
         Begin VB.TextBox DeviceInstanceField 
            Height          =   285
            Left            =   2640
            MaxLength       =   3
            TabIndex        =   110
            Text            =   "0"
            Top             =   480
            Width           =   375
         End
         Begin VB.CommandButton OpenDevice 
            Caption         =   "Open Device"
            Height          =   495
            Left            =   120
            TabIndex        =   111
            Top             =   360
            Width           =   975
         End
         Begin VB.CommandButton CloseDevice 
            Caption         =   "Close Device"
            Height          =   495
            Left            =   120
            TabIndex        =   112
            Top             =   960
            Width           =   975
         End
         Begin VB.Label DeviceInstanceLabel 
            Caption         =   "Device Instance"
            Height          =   255
            Left            =   1200
            TabIndex        =   155
            Top             =   480
            Width           =   1335
         End
      End
      Begin VB.Frame EnumerateFrame 
         Caption         =   "Enumerate"
         Height          =   1575
         Left            =   240
         TabIndex        =   107
         Top             =   360
         Width           =   2415
         Begin VB.CommandButton NumberOfDevices 
            Caption         =   "Enumerate Devices"
            Height          =   495
            Left            =   360
            TabIndex        =   109
            Top             =   360
            Width           =   1695
         End
         Begin VB.TextBox NumberOfDevicesField 
            Height          =   285
            Left            =   1800
            Locked          =   -1  'True
            TabIndex        =   108
            TabStop         =   0   'False
            Top             =   1080
            Width           =   375
         End
         Begin VB.Label NumberOfDevicesLabel 
            Caption         =   "Number of Devices"
            Height          =   255
            Left            =   240
            TabIndex        =   154
            Top             =   1080
            Width           =   1455
         End
      End
   End
   Begin VB.Frame Frame1 
      Caption         =   "Dummy"
      Enabled         =   0   'False
      Height          =   135
      Index           =   0
      Left            =   9000
      TabIndex        =   187
      Top             =   5520
      Visible         =   0   'False
      Width           =   375
   End
   Begin ComctlLib.TabStrip TabStrip1 
      Height          =   5775
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   8895
      _ExtentX        =   15690
      _ExtentY        =   10186
      _Version        =   327682
      BeginProperty Tabs {0713E432-850A-101B-AFC0-4210102A8DA7} 
         NumTabs         =   8
         BeginProperty Tab1 {0713F341-850A-101B-AFC0-4210102A8DA7} 
            Caption         =   "Device"
            Key             =   ""
            Object.Tag             =   ""
            ImageVarType    =   2
         EndProperty
         BeginProperty Tab2 {0713F341-850A-101B-AFC0-4210102A8DA7} 
            Caption         =   "Descriptor"
            Key             =   ""
            Object.Tag             =   ""
            ImageVarType    =   2
         EndProperty
         BeginProperty Tab3 {0713F341-850A-101B-AFC0-4210102A8DA7} 
            Caption         =   "Interface"
            Key             =   ""
            Object.Tag             =   ""
            ImageVarType    =   2
         EndProperty
         BeginProperty Tab4 {0713F341-850A-101B-AFC0-4210102A8DA7} 
            Caption         =   "Read"
            Key             =   ""
            Object.Tag             =   ""
            ImageVarType    =   2
         EndProperty
         BeginProperty Tab5 {0713F341-850A-101B-AFC0-4210102A8DA7} 
            Caption         =   "Write"
            Key             =   ""
            Object.Tag             =   ""
            ImageVarType    =   2
         EndProperty
         BeginProperty Tab6 {0713F341-850A-101B-AFC0-4210102A8DA7} 
            Caption         =   "Feature"
            Key             =   ""
            Object.Tag             =   ""
            ImageVarType    =   2
         EndProperty
         BeginProperty Tab7 {0713F341-850A-101B-AFC0-4210102A8DA7} 
            Caption         =   "Class or Vendor Request"
            Key             =   ""
            Object.Tag             =   ""
            ImageVarType    =   2
         EndProperty
         BeginProperty Tab8 {0713F341-850A-101B-AFC0-4210102A8DA7} 
            Caption         =   "Other"
            Key             =   ""
            Object.Tag             =   ""
            ImageVarType    =   2
         EndProperty
      EndProperty
   End
End
Attribute VB_Name = "USBIOCOMForm"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False

'(c) 2001-2002 Thesycon Systemsoftware & Consulting GmbH
'
'This is a sample program for the USBIOCOM interface. It
'requires the registered USBIOCOM interface and the USBIO
'device driver. Furthermore, an USB test device is required.
'
'An USB mouse or keyboard can be used as test device for example.
'Note: The test device cannot be used as a Windows input device at the same time.
'
'For detailed information on the USBIOCOM interface refer to the
'documentation in usbiocom.pdf. For information on the USBIO
'device driver an its API refer to usbioman.pdf.
'
'For latest updates visit http://www.thesycon.de
'
'
'How to use this sample application:
'1. Connect an USB device with at least one IN endpoint to the PC.
'
'2. Use the USBIO install wizard to install the USBIO device driver
'for this device.
'
'3. Make sure that the USBIOCOM interface is registered on the PC.
'Normally, this is done during installation. You can run the command
'>regsvr32 usbiocom.dll
'to register the USBIOCOM interface manually.
'
'4. Run this application and carry out the following actions:
'a) press "Number of Devices" ->  Number of devices should be at least 1
'b) press "Open Device"
'c) switch to the "Interface" page
'd) enter interface and alternate setting, press "Add Interface"
'e) press "Set Configuration"
'f) enter the endpoint address, add 128 (80 hex) for IN endpoints
'g) press "Bind"
'h) switch to the "Read" page
'i) press "Start Read"
'j) press keys on the keyboard or move the mouse
'k) press "Stop Read", the file should contain the received data
'
'


' We define global variables that hold the instances of the USBIO COM object.
' We need to use the "WithEvents" attribute.

' This one represents the USB device.
Dim WithEvents USBDevice As USBIOCOMLib.USBIOInterface
Attribute USBDevice.VB_VarHelpID = -1

' This one represents a data pipe (USB endpoint).
' Note: To keep it simple we use one data pipe only.
' However, if more that one endpoint shall be used then one instance
' is required for each of them.
Dim WithEvents USBPipe As USBIOCOMLib.USBIOInterface
Attribute USBPipe.VB_VarHelpID = -1

' The USBIOCOM_ERR_CODES enum is defined in the USBIOCOM Type Library.
Dim status As USBIOCOMLib.USBIOCOM_ERR_CODES

'define an array of bytes used for read and write operations
Dim buffer() As Byte
Dim intbuffer() As Long
Dim intbuffer2() As Long
Dim buf() As Byte

Dim mintCurFrame As Integer

Dim fileopen As Boolean

Dim tempbuf(7) As Byte
Dim UserId As Long
Dim writing As Boolean
Dim reading As Boolean
Dim BufferSize As Long
Dim BufferCount As Long
Dim ErrorCount As Long
Dim IsIsoFlag As Boolean
Dim WriteToFile As Boolean
Dim fifosize As Long
Dim wBufferSize As Long
Dim wBufferCount As Long
Dim wErrorCount As Long
Dim wIsIsoFlag As Boolean
Dim ReadFromFile As Boolean
Dim wBufferValue As Long
Dim WriteStatus As Boolean


' *****************************************************
' Enumeration Page
' *****************************************************

'enumerate devices
Private Sub NumberOfDevices_Click()
    'number of devices, -1 in case of an error
    Dim Devices As Long
    ' Enumerate the available devices.
    ' We use the USBIO default GUID here.
    ' In production-level code a custom GUID should be used which is defined in usbio.inf.
    USBDevice.EnumerateDevices "{325ddf96-938c-11d3-9e34-0080c82727f4}", Devices
    NumberOfDevicesField.Text = Devices
End Sub

'open device
Private Sub OpenDevice_Click()
    USBDevice.OpenDevice Val(DeviceInstanceField.Text), status
    If status <> USBIO_ERR_SUCCESS Then
        MsgBox (USBDevice.ErrorText(status))
    Else
        USBPipe.OpenDevice Val(DeviceInstanceField.Text), status
        Call error(status)
    End If
End Sub

'close device
Private Sub CloseDevice_Click()
    USBDevice.CloseDevice
    USBPipe.CloseDevice
End Sub

'get driver information
Private Sub GetVersion_Click()
    Dim APIVersion As Long
    Dim DriverVersion As Long
    Dim DriverBuildNumber As Long
    Dim Flags As Long
    'get driver info
    USBDevice.GetDriverInfo APIVersion, DriverVersion, DriverBuildNumber, Flags, status
    If status <> USBIO_ERR_SUCCESS Then
        MsgBox (USBDevice.ErrorText(status))
    Else
        'output driver info
        APIVersionField.Text = Hex(APIVersion)
        DriverVersionField.Text = DriverVersion \ 256 & "." & DriverVersion Mod 256
        DriverBuildNumberField.Text = DriverBuildNumber
        FlagsField.Text = Flags
        DemoVersionField.Text = USBDevice.IsDemoVersion
        CheckedBuildVersionField.Text = USBDevice.IsCheckedBuild
    End If
End Sub

'get request timeout
Private Sub GetRequestTimeout_Click()
    GetRequestTimeoutField.Text = USBDevice.DeviceRequestTimeout
End Sub

'set request timeout
Private Sub SetRequestTimeout_Click()
    USBDevice.DeviceRequestTimeout = Val(SetRequestTimeoutField.Text)
End Sub

'get device options
Private Sub GetDeviceOptions_Click()
    GetDeviceOptionsField.Text = USBDevice.DeviceOptions
End Sub

'set device options
Private Sub SetDeviceOptions_Click()
    USBDevice.DeviceOptions = Val(SetDeviceOptionsField.Text)
End Sub

'DisablePnPNotificationButton_Click
Private Sub DisablePnPNotificationButton_Click()
    ' We use the USBIO default GUID here.
    ' In production-level code a custom GUID should be used which is defined in usbio.inf.
    USBDevice.DisablePnPNotification "{325ddf96-938c-11d3-9e34-0080c82727f4}", status
    Call error(status)
End Sub

'EnablePnPNotificationButton_Click
Private Sub EnablePnPNotificationButton_Click()
    ' We use the USBIO default GUID here.
    ' In production-level code a custom GUID should be used which is defined in usbio.inf.
    USBDevice.EnablePnPNotification "{325ddf96-938c-11d3-9e34-0080c82727f4}", status
    Call error(status)
End Sub

'PnP add Notification Event
Private Sub USBDevice_PnPAddNotification(ByVal Obj As Object)
    MsgBox "Device added"
End Sub

'PnP remove Notification Event
Private Sub USBDevice_PnPRemoveNotification(ByVal Obj As Object)
    MsgBox "Device removed"
End Sub


' *****************************************************
' Descriptor Page
' *****************************************************

'get string descriptor
Private Sub GetStringDescriptor_Click()
    Dim Descriptor(256) As Byte
    Dim ByteCount As Long
    ByteCount = 256
    ' call USBIOCOM object
                USBDevice.GetStringDescriptor Descriptor, ByteCount, Val(GetStringDescriptorIndexField.Text), 0, status
    If status <> USBIO_ERR_SUCCESS Then
        MsgBox (USBDevice.ErrorText(status))
    Else
        GetStringDescriptorField.Text = ""
        GetStringDescriptorLengthField.Text = Descriptor(0)
        GetStringDescriptorTypeField.Text = Descriptor(1)
        ' display the descriptor in a readable format
        For n = 2 To ByteCount
            If Val(GetStringDescriptorIndexField.Text) = 0 Then
                If Descriptor(n) < 16 Then
                    GetStringDescriptorField.Text = GetStringDescriptorField.Text & "0" & Hex(Descriptor(n)) & " "
                Else
                    GetStringDescriptorField.Text = GetStringDescriptorField.Text & Hex(Descriptor(n)) & " "
                End If
            Else
                GetStringDescriptorField.Text = GetStringDescriptorField.Text & Chr(Descriptor(n))
            End If
        Next n
    End If
End Sub

'get descriptor
Private Sub GetDescriptor_Click()
    Dim ByteCount As Long
    ByteCount = Val(

⌨️ 快捷键说明

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