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.CommandButton Command1 
  17.       Caption         =   "Command1"
  18.       Height          =   615
  19.       Left            =   1440
  20.       TabIndex        =   0
  21.       Top             =   480
  22.       Width           =   975
  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 = 6017
  32. Private Const ProductID = 2000
  33. ' read and write buffers
  34. Private Const BufferInSize = 8
  35. Private Const BufferOutSize = 8
  36. Dim bufferin(0 To BufferInSize) As Byte
  37. Dim BufferOut(0 To BufferOutSize) As Byte
  38. Private Sub Command1_Click()
  39. hidReadEx VendorID, ProductID, BufferOut(0)
  40. End Sub
  41. ' ****************************************************************
  42. ' when the form loads, connect to the HID controller - pass
  43. ' the form window handle so that you can receive notification
  44. ' events...
  45. '*****************************************************************
  46. Private Sub Form_Load()
  47.    ' do not remove!
  48.    ConnectToHID (Me.hwnd)
  49. End Sub
  50. '*****************************************************************
  51. ' disconnect from the HID controller...
  52. '*****************************************************************
  53. Private Sub Form_Unload(Cancel As Integer)
  54.    DisconnectFromHID
  55. End Sub
  56. '*****************************************************************
  57. ' a HID device has been plugged in...
  58. '*****************************************************************
  59. Public Sub OnPlugged(ByVal pHandle As Long)
  60.    If hidGetVendorID(pHandle) = VendorID And hidGetProductID(pHandle) = ProductID Then
  61.       ' ** YOUR CODE HERE **
  62.    End If
  63. End Sub
  64. '*****************************************************************
  65. ' a HID device has been unplugged...
  66. '*****************************************************************
  67. Public Sub OnUnplugged(ByVal pHandle As Long)
  68.    If hidGetVendorID(pHandle) = VendorID And hidGetProductID(pHandle) = ProductID Then
  69.       ' ** YOUR CODE HERE **
  70.    End If
  71. End Sub
  72. '*****************************************************************
  73. ' controller changed notification - called
  74. ' after ALL HID devices are plugged or unplugged
  75. '*****************************************************************
  76. Public Sub OnChanged()
  77.    Dim DeviceHandle As Long
  78.    
  79.    ' get the handle of the device we are interested in, then set
  80.    ' its read notify flag to true - this ensures you get a read
  81.    ' notification message when there is some data to read...
  82.    DeviceHandle = hidGetHandle(VendorID, ProductID)
  83.    hidSetReadNotify DeviceHandle, True
  84. End Sub
  85. '*****************************************************************
  86. ' on read event...
  87. '*****************************************************************
  88. Public Sub OnRead(ByVal pHandle As Long)
  89.    
  90.    ' read the data (don't forget, pass the whole array)...
  91.    If hidRead(pHandle, bufferin(0)) Then
  92.       ' ** YOUR CODE HERE **
  93.       ' first byte is the report ID, e.g. BufferIn(0)
  94.       ' the other bytes are the data from the microcontrolller...
  95.    End If
  96. End Sub
  97. '*****************************************************************
  98. ' this is how you write some data...
  99. '*****************************************************************
  100. Public Sub WriteSomeData()
  101.    BufferOut(0) = 0   ' first by is always the report ID
  102.    BufferOut(1) = 10  ' first data item, etc etc
  103.    ' write the data (don't forget, pass the whole array)...
  104.    hidWriteEx VendorID, ProductID, BufferOut(0)
  105. End Sub
  106.