Codigo:
DEFINE OSC 48
USBBufferSizeMax con 8 " maximum buffer size
USBBufferSizeTX con 8 " input
USBBufferSizeRX con 8 " output
" the USB buffer...
USBBuffer Var Byte[USBBufferSizeMax]
USBBufferCount Var Byte
dato var byte
" ************************************************************
" * main program loop - remember, you must keep the USB *
" * connection alive with a call to USBService every couple *
" * of milliseconds or so... *
" ************************************************************
PORTB = 0
TRISB = 0
usbinit " initialise USB...
ProgramStart:
gosub DoUSBIn
PORTB = USBBuffer[7]
goto ProgramStart
" ************************************************************
" * receive data from the USB bus *
" ************************************************************
DoUSBIn:
USBBufferCount = USBBufferSizeRX " RX buffer size
USBService " keep connection alive
USBIn 1, USBBuffer, USBBufferCount, DoUSBIn " read data, if available
return
Codigo:
" vendor and product IDs
Private Const VendorID = 6017
Private Const ProductID = 2000
" read and write buffers
Private Const BufferInSize = 8
Private Const BufferOutSize = 8
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
" ** 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
Private Sub Image4_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
BufferOut(8) = 27
hidWriteEx VendorID, ProductID, BufferOut(0)
End Sub
Private Sub Image4_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
BufferOut(8) = 0
hidWriteEx VendorID, ProductID, BufferOut(0)
End Sub
Private Sub Image1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
BufferOut(8) = 45
hidWriteEx VendorID, ProductID, BufferOut(0)
End Sub
Private Sub Image1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
BufferOut(8) = 0
hidWriteEx VendorID, ProductID, BufferOut(0)
End Sub
Private Sub Image3_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
BufferOut(8) = 43
hidWriteEx VendorID, ProductID, BufferOut(0)
End Sub
Private Sub Image3_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
BufferOut(8) = 0
hidWriteEx VendorID, ProductID, BufferOut(0)
End Sub
Private Sub Image2_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
BufferOut(8) = 29
hidWriteEx VendorID, ProductID, BufferOut(0)
End Sub
Private Sub Image2_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
BufferOut(8) = 0
hidWriteEx VendorID, ProductID, BufferOut(0)
End Sub