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

📄 frmmain.frm

📁 基于sy2100 ez-usb开发板的程序
💻 FRM
📖 第 1 页 / 共 2 页
字号:
VERSION 5.00
Begin VB.Form frmMain 
   Caption         =   "EZ-USB DevBd as Generic HID"
   ClientHeight    =   3045
   ClientLeft      =   4770
   ClientTop       =   4530
   ClientWidth     =   3975
   FillStyle       =   0  'Solid
   LinkTopic       =   "Form1"
   ScaleHeight     =   3045
   ScaleWidth      =   3975
   Begin VB.CommandButton cmdAcquire 
      Caption         =   "Acquire"
      Height          =   375
      Left            =   1200
      TabIndex        =   5
      Top             =   1080
      Width           =   1455
   End
   Begin VB.TextBox tbPID 
      Height          =   285
      Left            =   2040
      TabIndex        =   4
      Text            =   "PID"
      Top             =   480
      Width           =   615
   End
   Begin VB.TextBox tbVID 
      Height          =   285
      Left            =   1200
      TabIndex        =   3
      Text            =   "VID"
      Top             =   480
      Width           =   615
   End
   Begin VB.TextBox tb7SEG 
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   24
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   615
      Left            =   1800
      TabIndex        =   2
      Top             =   2400
      Width           =   495
   End
   Begin VB.CommandButton cmdDPBUT 
      Caption         =   "dp"
      Height          =   255
      Left            =   120
      TabIndex        =   1
      Top             =   2640
      Width           =   735
   End
   Begin VB.HScrollBar hsRate 
      Height          =   255
      Left            =   120
      Max             =   30
      Min             =   1
      TabIndex        =   0
      Top             =   2040
      Value           =   1
      Width           =   3735
   End
   Begin VB.Timer tmrRWData 
      Left            =   360
      Top             =   2280
   End
   Begin VB.Timer tmrDelay 
      Enabled         =   0   'False
      Left            =   120
      Top             =   11400
   End
   Begin VB.Frame Frame1 
      Caption         =   "Acquire Device"
      Height          =   1815
      Left            =   1080
      TabIndex        =   6
      Top             =   120
      Width           =   1695
      Begin VB.TextBox tbMsg 
         Height          =   285
         Left            =   120
         TabIndex        =   13
         Top             =   1440
         Width           =   1455
      End
      Begin VB.Label Label1 
         Caption         =   "PID(hex)"
         Height          =   255
         Left            =   960
         TabIndex        =   8
         Top             =   720
         Width           =   615
      End
      Begin VB.Label VID 
         Caption         =   "VID(hex)"
         Height          =   255
         Left            =   120
         TabIndex        =   7
         Top             =   720
         Width           =   615
      End
   End
   Begin VB.Label Label5 
      Caption         =   "f4"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   3600
      TabIndex        =   12
      Top             =   2760
      Width           =   160
   End
   Begin VB.Label Label4 
      Caption         =   "f3"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   3240
      TabIndex        =   11
      Top             =   2760
      Width           =   160
   End
   Begin VB.Label Label3 
      Caption         =   "f2"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   2880
      TabIndex        =   10
      Top             =   2760
      Width           =   160
   End
   Begin VB.Label Label2 
      Caption         =   "f1"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   2520
      TabIndex        =   9
      Top             =   2760
      Width           =   160
   End
   Begin VB.Shape but 
      BorderColor     =   &H00000000&
      BorderWidth     =   2
      FillColor       =   &H0000FF00&
      FillStyle       =   0  'Solid
      Height          =   255
      Index           =   3
      Left            =   3600
      Shape           =   3  'Circle
      Top             =   2520
      Width           =   195
   End
   Begin VB.Shape but 
      BorderColor     =   &H00000000&
      BorderWidth     =   2
      FillColor       =   &H0000FF00&
      FillStyle       =   0  'Solid
      Height          =   255
      Index           =   2
      Left            =   3240
      Shape           =   3  'Circle
      Top             =   2520
      Width           =   195
   End
   Begin VB.Shape but 
      BorderColor     =   &H00000000&
      BorderWidth     =   2
      FillColor       =   &H0000FF00&
      FillStyle       =   0  'Solid
      Height          =   255
      Index           =   1
      Left            =   2880
      Shape           =   3  'Circle
      Top             =   2520
      Width           =   195
   End
   Begin VB.Shape but 
      BorderColor     =   &H00000000&
      BorderWidth     =   2
      FillColor       =   &H0000FF00&
      FillStyle       =   0  'Solid
      Height          =   255
      Index           =   0
      Left            =   2520
      Shape           =   3  'Circle
      Top             =   2520
      Width           =   195
   End
   Begin VB.Shape shDP 
      BorderColor     =   &H00000000&
      BorderWidth     =   3
      FillColor       =   &H000000FF&
      FillStyle       =   0  'Solid
      Height          =   255
      Left            =   1200
      Shape           =   3  'Circle
      Top             =   2640
      Width           =   255
   End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

'Project: VBhid.vbp
'
Dim Capabilities As HIDP_CAPS
Dim DataString As String
Dim DetailData As Long
Dim DetailDataBuffer() As Byte
Dim DeviceAttributes As HIDD_ATTRIBUTES
Dim DevicePathName As String
Dim DeviceInfoSet As Long
Dim ErrorString As String
Dim HidDevice As Long
Dim LastDevice As Boolean
Dim MyDeviceDetected As Boolean
Dim MyDeviceInfoData As SP_DEVINFO_DATA
Dim MyDeviceInterfaceDetailData As SP_DEVICE_INTERFACE_DETAIL_DATA
Dim MyDeviceInterfaceData As SP_DEVICE_INTERFACE_DATA
Dim Needed As Long
Dim OutputReportData(7) As Byte
Dim PreparsedData As Long
Dim Result As Long
Dim Timeout As Boolean
Dim dp As Byte              ' 7-seg decimal point
Dim busy As Byte            ' busy with a HID report
'Set these to match the values in the device's firmware.
Const MyVendorID = &H547
Const MyProductID = &H7450
'_____________________________________________________________
Private Sub Startup()
busy = 0                        ' initially no HID reports being processed
tmrRWData.Enabled = False
tmrRWData.Interval = 10         ' send/receive HID report every 10 msec
tbVID.Text = Hex$(MyVendorID)
tbPID.Text = Hex$(MyProductID)
End Sub
'_____________________________________________________________
Private Sub cmdAcquire_Click()  ' look for HID device with prescribed VID/PID
Dim DeviceDetected As Boolean
DeviceDetected = FindTheHid
If DeviceDetected = True Then
    Call GetDeviceCapabilities      ' learn device capabilities (need buffer size)
    tbMsg.Text = "Device Found"
    tmrRWData.Enabled = True     ' enable timer
Else
    tbMsg.Text = "Device Not found"
End If
End Sub
'_____________________________________________________________
Private Sub ReadAndWriteToDevice()
    busy = 1
    Call WriteReport
    Call ReadReport
    busy = 0
End Sub
'_____________________________________________________________
Function FindTheHid() As Boolean
'Makes a series of API calls to locate the desired HID-class device.
'Returns True if the device is detected, False if not detected.

Dim Count As Integer
Dim GUIDString As String
Dim HidGuid As GUID
Dim MemberIndex As Long

LastDevice = False
MyDeviceDetected = False

Result = HidD_GetHidGuid(HidGuid)

'******************************************************************************
'SetupDiGetClassDevs
'Returns: a handle to a device information set for all installed devices.
'Requires: the HidGuid returned in GetHidGuid.
'******************************************************************************

DeviceInfoSet = SetupDiGetClassDevs _
    (HidGuid, _
    vbNullString, _
    0, _
    (DIGCF_PRESENT Or DIGCF_DEVICEINTERFACE))
    
DataString = GetDataString(DeviceInfoSet, 32)

'******************************************************************************
'SetupDiEnumDeviceInterfaces
'On return, MyDeviceInterfaceData contains the handle to a
'SP_DEVICE_INTERFACE_DATA structure for a detected device.
'Requires:
'the DeviceInfoSet returned in SetupDiGetClassDevs.
'the HidGuid returned in GetHidGuid.
'An index to specify a device.
'******************************************************************************
'Begin with 0 and increment until no more devices are detected.
MemberIndex = 0
Do
'The cbSize element of the MyDeviceInterfaceData structure must be set to

⌨️ 快捷键说明

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