FormMain.frm
资源名称:USBFM.zip [点击查看]
上传用户:wang202020
上传日期:2021-02-07
资源大小:182k
文件大小:4k
源码类别:
单片机开发
开发平台:
HTML/CSS
- VERSION 5.00
- Begin VB.Form MainForm
- BorderStyle = 3 'Fixed Dialog
- Caption = "EasyHID Template"
- ClientHeight = 1485
- ClientLeft = 5490
- ClientTop = 4080
- ClientWidth = 3930
- LinkTopic = "Form1"
- MaxButton = 0 'False
- MinButton = 0 'False
- ScaleHeight = 1485
- ScaleWidth = 3930
- ShowInTaskbar = 0 'False
- StartUpPosition = 2 'CenterScreen
- Begin VB.TextBox Text1
- Height = 735
- Left = 1080
- TabIndex = 0
- Text = "Text1"
- Top = 240
- Width = 855
- End
- End
- Attribute VB_Name = "MainForm"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = False
- Attribute VB_PredeclaredId = True
- Attribute VB_Exposed = False
- ' vendor and product IDs
- Private Const VendorID = 6019
- Private Const ProductID = 2009
- ' read and write buffers
- Private Const BufferInSize = 16
- Private Const BufferOutSize = 16
- Dim BufferIn(0 To BufferInSize) As Byte
- Dim BufferOut(0 To BufferOutSize) As Byte
- ' ****************************************************************
- ' when the form loads, connect to the HID controller - pass
- ' the form window handle so that you can receive notification
- ' events...
- '*****************************************************************
- Private Sub Form_Load()
- ' do not remove!
- ConnectToHID (Me.hwnd)
- End Sub
- '*****************************************************************
- ' disconnect from the HID controller...
- '*****************************************************************
- Private Sub Form_Unload(Cancel As Integer)
- DisconnectFromHID
- End Sub
- '*****************************************************************
- ' a HID device has been plugged in...
- '*****************************************************************
- Public Sub OnPlugged(ByVal pHandle As Long)
- If hidGetVendorID(pHandle) = VendorID And hidGetProductID(pHandle) = ProductID Then
- ' ** YOUR CODE HERE **
- End If
- End Sub
- '*****************************************************************
- ' a HID device has been unplugged...
- '*****************************************************************
- Public Sub OnUnplugged(ByVal pHandle As Long)
- If hidGetVendorID(pHandle) = VendorID And hidGetProductID(pHandle) = ProductID Then
- ' ** YOUR CODE HERE **
- End If
- End Sub
- '*****************************************************************
- ' controller changed notification - called
- ' after ALL HID devices are plugged or unplugged
- '*****************************************************************
- Public Sub OnChanged()
- Dim DeviceHandle As Long
- ' get the handle of the device we are interested in, then set
- ' its read notify flag to true - this ensures you get a read
- ' notification message when there is some data to read...
- DeviceHandle = hidGetHandle(VendorID, ProductID)
- hidSetReadNotify DeviceHandle, True
- End Sub
- '*****************************************************************
- ' on read event...
- '*****************************************************************
- Public Sub OnRead(ByVal pHandle As Long)
- ' read the data (don't forget, pass the whole array)...
- If hidRead(pHandle, BufferIn(0)) Then
- Text1.Text = BufferIn(1)
- ' ** YOUR CODE HERE **
- ' first byte is the report ID, e.g. BufferIn(0)
- ' the other bytes are the data from the microcontrolller...
- End If
- End Sub
- '*****************************************************************
- ' this is how you write some data...
- '*****************************************************************
- Public Sub WriteSomeData()
- BufferOut(0) = 0 ' first by is always the report ID
- BufferOut(1) = 10 ' first data item, etc etc
- ' write the data (don't forget, pass the whole array)...
- hidWriteEx VendorID, ProductID, BufferOut(0)
- End Sub
English
