FormMain.frm
Upload User: wang202020
Upload Date: 2021-02-07
Package Size: 182k
Code Size: 4k
Category:

SCM

Development Platform:

HTML/CSS

  1. VERSION 5.00
  2. Begin VB.Form MainForm 
  3.    BorderStyle     =   3  'Fixed Dialog
  4.    Caption         =   "EasyHID Template"
  5.    ClientHeight    =   1485
  6.    ClientLeft      =   5490
  7.    ClientTop       =   4080
  8.    ClientWidth     =   3930
  9.    LinkTopic       =   "Form1"
  10.    MaxButton       =   0   'False
  11.    MinButton       =   0   'False
  12.    ScaleHeight     =   1485
  13.    ScaleWidth      =   3930
  14.    ShowInTaskbar   =   0   'False
  15.    StartUpPosition =   2  'CenterScreen
  16.    Begin VB.TextBox Text1 
  17.       Height          =   735
  18.       Left            =   1080
  19.       TabIndex        =   0
  20.       Text            =   "Text1"
  21.       Top             =   240
  22.       Width           =   855
  23.    End
  24. End
  25. Attribute VB_Name = "MainForm"
  26. Attribute VB_GlobalNameSpace = False
  27. Attribute VB_Creatable = False
  28. Attribute VB_PredeclaredId = True
  29. Attribute VB_Exposed = False
  30. ' vendor and product IDs
  31. Private Const VendorID = 6019
  32. Private Const ProductID = 2009
  33. ' read and write buffers
  34. Private Const BufferInSize = 16
  35. Private Const BufferOutSize = 16
  36. Dim BufferIn(0 To BufferInSize) As Byte
  37. Dim BufferOut(0 To BufferOutSize) As Byte
  38. ' ****************************************************************
  39. ' when the form loads, connect to the HID controller - pass
  40. ' the form window handle so that you can receive notification
  41. ' events...
  42. '*****************************************************************
  43. Private Sub Form_Load()
  44.    ' do not remove!
  45.    ConnectToHID (Me.hwnd)
  46. End Sub
  47. '*****************************************************************
  48. ' disconnect from the HID controller...
  49. '*****************************************************************
  50. Private Sub Form_Unload(Cancel As Integer)
  51.    DisconnectFromHID
  52. End Sub
  53. '*****************************************************************
  54. ' a HID device has been plugged in...
  55. '*****************************************************************
  56. Public Sub OnPlugged(ByVal pHandle As Long)
  57.    If hidGetVendorID(pHandle) = VendorID And hidGetProductID(pHandle) = ProductID Then
  58.       ' ** YOUR CODE HERE **
  59.    End If
  60. End Sub
  61. '*****************************************************************
  62. ' a HID device has been unplugged...
  63. '*****************************************************************
  64. Public Sub OnUnplugged(ByVal pHandle As Long)
  65.    If hidGetVendorID(pHandle) = VendorID And hidGetProductID(pHandle) = ProductID Then
  66.       ' ** YOUR CODE HERE **
  67.    End If
  68. End Sub
  69. '*****************************************************************
  70. ' controller changed notification - called
  71. ' after ALL HID devices are plugged or unplugged
  72. '*****************************************************************
  73. Public Sub OnChanged()
  74.    Dim DeviceHandle As Long
  75.    
  76.    ' get the handle of the device we are interested in, then set
  77.    ' its read notify flag to true - this ensures you get a read
  78.    ' notification message when there is some data to read...
  79.    DeviceHandle = hidGetHandle(VendorID, ProductID)
  80.    hidSetReadNotify DeviceHandle, True
  81. End Sub
  82. '*****************************************************************
  83. ' on read event...
  84. '*****************************************************************
  85. Public Sub OnRead(ByVal pHandle As Long)
  86.    
  87.    ' read the data (don't forget, pass the whole array)...
  88.    If hidRead(pHandle, BufferIn(0)) Then
  89.     Text1.Text = BufferIn(1)
  90.       ' ** YOUR CODE HERE **
  91.       ' first byte is the report ID, e.g. BufferIn(0)
  92.       ' the other bytes are the data from the microcontrolller...
  93.    End If
  94. End Sub
  95. '*****************************************************************
  96. ' this is how you write some data...
  97. '*****************************************************************
  98. Public Sub WriteSomeData()
  99.    BufferOut(0) = 0   ' first by is always the report ID
  100.    BufferOut(1) = 10  ' first data item, etc etc
  101.    ' write the data (don't forget, pass the whole array)...
  102.    hidWriteEx VendorID, ProductID, BufferOut(0)
  103. End Sub
  104.