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

📄 easyusb_demo.frm

📁 在软件开发环境中能和USB通讯,通讯代码。压缩包没有密码。
💻 FRM
字号:
VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "EasyUSB Demo-赛先生科技"
   ClientHeight    =   4080
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   4680
   LinkTopic       =   "Form1"
   Picture         =   "EasyUSB_Demo.frx":0000
   ScaleHeight     =   4080
   ScaleWidth      =   4680
   StartUpPosition =   3  'Windows Default
   Begin VB.CheckBox Check1 
      Caption         =   "LED8"
      Height          =   255
      Index           =   7
      Left            =   240
      TabIndex        =   7
      Top             =   3600
      Width           =   855
   End
   Begin VB.CheckBox Check1 
      Caption         =   "LED7"
      Height          =   255
      Index           =   6
      Left            =   240
      TabIndex        =   6
      Top             =   3120
      Width           =   855
   End
   Begin VB.CheckBox Check1 
      Caption         =   "LED6"
      Height          =   255
      Index           =   5
      Left            =   240
      TabIndex        =   5
      Top             =   2640
      Width           =   855
   End
   Begin VB.CheckBox Check1 
      Caption         =   "LED5"
      Height          =   255
      Index           =   4
      Left            =   240
      TabIndex        =   4
      Top             =   2160
      Width           =   855
   End
   Begin VB.CheckBox Check1 
      Caption         =   "LED4"
      Height          =   255
      Index           =   3
      Left            =   240
      TabIndex        =   3
      Top             =   1200
      Width           =   855
   End
   Begin VB.CheckBox Check1 
      Caption         =   "LED3"
      Height          =   255
      Index           =   2
      Left            =   240
      TabIndex        =   2
      Top             =   1680
      Width           =   855
   End
   Begin VB.CheckBox Check1 
      Caption         =   "LED2"
      Height          =   255
      Index           =   1
      Left            =   240
      TabIndex        =   1
      Top             =   720
      Width           =   855
   End
   Begin VB.Timer Timer1 
      Interval        =   100
      Left            =   4200
      Top             =   120
   End
   Begin VB.CheckBox Check1 
      Caption         =   "LED1"
      Height          =   255
      Index           =   0
      Left            =   240
      TabIndex        =   0
      Top             =   240
      Width           =   855
   End
   Begin VB.Label Label4 
      Caption         =   "Key4"
      Height          =   375
      Left            =   3360
      TabIndex        =   11
      Top             =   3000
      Width           =   615
   End
   Begin VB.Label Label3 
      Caption         =   "Key3(INT)"
      Height          =   375
      Left            =   3360
      TabIndex        =   10
      Top             =   2280
      Width           =   975
   End
   Begin VB.Label Label2 
      Caption         =   "Key2"
      Height          =   375
      Left            =   3360
      TabIndex        =   9
      Top             =   1440
      Width           =   615
   End
   Begin VB.Label Label1 
      Caption         =   "Key1"
      Height          =   255
      Left            =   3360
      TabIndex        =   8
      Top             =   600
      Width           =   615
   End
   Begin VB.Image Image1 
      Height          =   480
      Index           =   3
      Left            =   2640
      Picture         =   "EasyUSB_Demo.frx":0BC2
      Top             =   2880
      Width           =   480
   End
   Begin VB.Image Image1 
      Height          =   480
      Index           =   2
      Left            =   2640
      Picture         =   "EasyUSB_Demo.frx":1804
      Top             =   2160
      Width           =   480
   End
   Begin VB.Image Image1 
      Height          =   480
      Index           =   1
      Left            =   2640
      Picture         =   "EasyUSB_Demo.frx":2446
      Top             =   1320
      Width           =   480
   End
   Begin VB.Image Image1 
      Height          =   480
      Index           =   0
      Left            =   2640
      Picture         =   "EasyUSB_Demo.frx":3088
      Top             =   480
      Width           =   480
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False


Option Explicit
'以下是EasyUSB_DLL的函数定义
Private Declare Function EasyUSB_OpenDevice Lib "EasyUSB_dll.dll" (ByVal a As Long) As Long
Private Declare Sub EasyUSB_CloseDevice Lib "EasyUSB_dll.dll" ()
Private Declare Sub EasyUSB_Set_DetectInsert Lib "EasyUSB_dll.dll" ()
Private Declare Sub EasyUSB_Cancel_DetectInsert Lib "EasyUSB_dll.dll" ()
Private Declare Sub EasyUSB_Set8LED Lib "EasyUSB_dll.dll" (ByVal a As Byte)
Private Declare Function EasyUSB_GetInput Lib "EasyUSB_dll.dll" () As Byte


Dim LED As Byte '标识LED的明暗状态
Dim Key As Byte '当前按键状态
Dim KeyLast As Byte '记录按键状态
Dim Mask As Variant '用来取Bit的面罩


'*****************************************
'程序初始化
Private Sub Form_Load()

'Mask数组初始化
Mask = Array(&H1, &H2, &H4, &H8, &H10, &H20, &H40, &H80)
LED = 255
EasyUSB_Set8LED (255) '灯全部关掉

EasyUSB_OpenDevice (hWnd)


End Sub
'*****************************************
'退出处理
Public Sub Form_UnLoad(Cancel As Integer)

EasyUSB_Set8LED (255) '灯全部关掉

EasyUSB_CloseDevice

End Sub



Private Sub Check1_Click(Index As Integer)
'对Index所指的bit进行取反
Dim tmp As Byte

If (Mask(Index) And LED) = 0 Then

LED = (LED Or Mask(Index))

Else

tmp = (Mask(Index) Xor 255) '该字节反相
LED = (LED And tmp)

End If

EasyUSB_Set8LED (LED)






End Sub

Private Sub Timer1_Timer()

Key = EasyUSB_GetInput

If Key <> KeyLast Then '如果按键没有变化,则不重新显示按键图片。有变化,则进入下面
KeyLast = Key

    '用图片显示Key1状态
    If (Key And 1) = 0 Then
        Image1(0).Picture = LoadPicture("icon_Down.bmp")
    Else
        Image1(0).Picture = LoadPicture("icon_Up.bmp")
    End If
    
    '用图片显示Key2状态
    If (Key And 2) = 0 Then
        Image1(1).Picture = LoadPicture("icon_Down.bmp")
    Else
        Image1(1).Picture = LoadPicture("icon_Up.bmp")
    End If
    
    '用图片显示Key3状态
    If (Key And 4) = 0 Then
        Image1(2).Picture = LoadPicture("icon_Down.bmp")
    Else
        Image1(2).Picture = LoadPicture("icon_Up.bmp")
    End If
    
    '用图片显示Key4状态
    If (Key And 8) = 0 Then
        Image1(3).Picture = LoadPicture("icon_Down.bmp")
    Else
        Image1(3).Picture = LoadPicture("icon_Up.bmp")
    End If
    
    

End If

End Sub

⌨️ 快捷键说明

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