The variable "BufferInp(0)" always gives zero.
It is assumed that the device can be opened like a file ...
Code: Select all
#Include Once "Windows.bi"
Dim As HANDLE hEvent, RH, WH
Dim As String HID_DEVICE, VALUE, GUID
Dim As OVERLAPPED HIDOverlapped
Dim As UByte Get2HID(0 To 63)
Dim As UByte Put2HID(0 To 63)
Dim As Integer iBytesRead, TestR, TestW
GUID="{4d1e55b2-f16f-11cf-88cb-001111000030}"
VALUE="hid#vid_1781&pid_07d0#6&1c842270&5&0000" ' My HID Device.
HID_DEVICE="\\?\" & VALUE & "#" & GUID
WH=CreateFile( StrPtr( HID_DEVICE ) ,_
GENERIC_WRITE,_
FILE_SHARE_READ Or FILE_SHARE_WRITE,_
Null,_
OPEN_EXISTING,_
0,_
NULL )
RH=CreateFile( StrPtr( HID_DEVICE ) ,_
GENERIC_READ,_
FILE_SHARE_READ Or FILE_SHARE_WRITE,_
NULL,_
OPEN_EXISTING,_
FILE_FLAG_OVERLAPPED,_
NULL )
If ( WH = INVALID_HANDLE_VALUE ) Or ( RH = INVALID_HANDLE_VALUE ) Then
Print "ERROR!"
Sleep
End
Else
Locate 3,1: Print "Device = "; Hex(RH), Hex(WH)
EndIf
Put2HID(0) = 169 'Load this value to send.
TestW=WriteFile (WH, @Put2HID(0), 8, @iBytesRead, 0)
TestR=ReadFile (RH, @Get2HID(0), 8, @iBytesRead, @HIDOverlapped)
Locate 5, 1: Print TestW, TestR
Locate 4, 1: Print "Result :"; Get2HID(0); " "
CloseHandle(RH)
CloseHandle(WH)
Sleep
End
Code: Select all
Device = 18F2550 ' Use a device with full speed USB capabilities
XTAL = 48' Set the oscillator speed to 48MHz(using a 20MHz crystal)
REMINDERS = 1
ALL_DIGITAL = 1
USB_DESCRIPTOR = "HIDclass.inc"
Dim PP0 As Byte SYSTEM ' USBPOLL status return
Dim Buffer[20] As Byte
Dim Aux As Byte
DelayMS 500 ' Wait for things to stabilise
Clear ' Clear all RAM before we start
Repeat
USBPoll ' Wait for the USB interface to become attached
Until PP0 = 6
' ----------------------------------------------------
While 1 = 1
GoSub Get
GoSub Put
Wend
End
Get:
Repe0:
USBIn 3, Buffer, 8, Repe0
Return
Put:
Repe1:
USBOut 3, Buffer, 8, Repe1
Return