As many of you know, for months now I have been researching USB and how it works, what it takes to communicate, and if communicating with the correct device.
On top of trying to make it "Simple" for someone else to follow. (good luck there
)
Anyways, I am hoping someone can clear my head and point out what I am doing wrong? (Even if its just a generic DeviceIoControl on a plain text file? (please no more examples about scuzzy drives, hard drives etc..) As I am trying to get my head wrapped around the "Kindergarten" phase of generic concepts.)
Where I am stuck is getting a Descriptor, so I can learn about the device I am looking at. (Yes I know this is easily done on Device attach/Detach etc...but I am looking at if my program runs after the device is attached, and determine if it is the one that I need to talk to)
Anyways, Sample Code below, and real code I hope to post soon.
(Real code currently returns either invalid handle, incorrect parameter, or does not support) but if I can get just 1 known device to work correctly then I am sure I can figure out why or why not the others do or don't
Any help you can give will be GREATLY appreciated
On top of trying to make it "Simple" for someone else to follow. (good luck there

Anyways, I am hoping someone can clear my head and point out what I am doing wrong? (Even if its just a generic DeviceIoControl on a plain text file? (please no more examples about scuzzy drives, hard drives etc..) As I am trying to get my head wrapped around the "Kindergarten" phase of generic concepts.)
Where I am stuck is getting a Descriptor, so I can learn about the device I am looking at. (Yes I know this is easily done on Device attach/Detach etc...but I am looking at if my program runs after the device is attached, and determine if it is the one that I need to talk to)
Anyways, Sample Code below, and real code I hope to post soon.
(Real code currently returns either invalid handle, incorrect parameter, or does not support) but if I can get just 1 known device to work correctly then I am sure I can figure out why or why not the others do or don't
Any help you can give will be GREATLY appreciated

Code:
#COMPILE EXE #DIM ALL #INCLUDE "WIN32API.INC" 'Define Windows OS variables and functions '*** Got from Docs but may be wrong %BMREQUEST_STANDARD = 0 %BMREQUEST_TO_DEVICE = 0 %USB_DEVICE_DESCRIPTOR_TYPE = &H01 TYPE USB_SETUP_PACKET bmRequest AS BYTE bRequest AS BYTE wValue AS WORD wIndex AS WORD wLength AS WORD END TYPE TYPE USB_DESCRIPTOR_REQUEST ConnectionIndex AS DWORD SetupPacket AS USB_SETUP_PACKET END TYPE %USB_REQUEST_GET_DESCRIPTOR = &H06 TYPE USB_DEVICE_DESCRIPTOR bLength AS BYTE bDescriptorType AS BYTE bcdUSB AS WORD bDeviceClass AS BYTE bDeviceSubClass AS BYTE bDeviceProtocol AS BYTE bMaxPacketSize0 AS BYTE idVendor AS WORD idProduct AS WORD bcdDevice AS WORD iManufacturer AS BYTE iProduct AS BYTE iSerialNumber AS BYTE bNumConfigurations AS BYTE END TYPE FUNCTION PBMAIN () AS LONG LOCAL ErrFunc AS DWORD LOCAL ErrorBuff AS ASCIIZ * %MAX_PATH '*** DeviceIoControl Parameters LOCAL DevHndl AS DWORD 'handle to device of interest LOCAL dwIoControlCode AS DWORD 'control code of operation to perform ' LPVOID lpInBuffer, // pointer to buffer to supply input data LOCAL lpInBuffer AS USB_DESCRIPTOR_REQUEST LOCAL nInBufferSize AS DWORD 'size of input buffer ' LPVOID lpOutBuffer, // pointer to buffer to receive output data LOCAL lpOutBuffer AS USB_DEVICE_DESCRIPTOR LOCAL nOutBufferSize AS DWORD 'size of output buffer ' LPDWORD lpBytesReturned, // pointer to variable to receive output byte count LOCAL lpBytesReturned AS DWORD LOCAL OverlappedType AS Overlapped 'pointer to overlapped structure for asynchronous operation ' ErrFunc = CreateFile("COM1", %GENERIC_READ OR %GENERIC_WRITE, 0, BYVAL 0, %OPEN_EXISTING, %FILE_FLAG_OVERLAPPED, %NULL) 'Windows Friendly Name DevHndl = CreateFile("\\?\acpi#pnp0501#1#{86e0d1e0-8089-11d0-9ce4-08003e301f73}", %GENERIC_READ OR %GENERIC_WRITE, 0, BYVAL 0, %OPEN_EXISTING, %FILE_FLAG_OVERLAPPED, %NULL) 'Windows REAL Name '*********************************** ERROR CHECKING ************************************** ErrFunc = GetLastError() 'Check for the error FormatMessage %FORMAT_MESSAGE_FROM_SYSTEM, BYVAL %NULL, ErrFunc, %NULL, ErrorBuff, SIZEOF(ErrorBuff), BYVAL %NULL 'Format the message MSGBOX STR$(ErrFunc) + $TAB + ErrorBuff '******************************** END ERROR CHECKING ************************************* DevHndl = CloseHandle(DevHndl) 'Close Handle whether its valid or not '<--- Not sure if this does anything on a invalid handle? '*********************************** ERROR CHECKING ************************************** ErrFunc = GetLastError() 'Check for the error FormatMessage %FORMAT_MESSAGE_FROM_SYSTEM, BYVAL %NULL, ErrFunc, %NULL, ErrorBuff, SIZEOF(ErrorBuff), BYVAL %NULL 'Format the message MSGBOX STR$(ErrFunc) + $TAB + ErrorBuff '******************************** END ERROR CHECKING ************************************* ' OverLappedType.Offset = 0 ' OverLappedType.OffsetHigh = 0 ' OverLappedType.hEvent = 0 lpInBuffer.ConnectionIndex = 1 '<--- Tried 0 (like I think it should be but tried 1 just in case) lpInBuffer.SetupPacket.bmRequest = %BMREQUEST_STANDARD '<--- Not sure if correct, but tried for getting 1st peice of info lpInBuffer.SetupPacket.bRequest = %USB_REQUEST_GET_DESCRIPTOR '<--- Not sure if correct, but tried for getting 1st peice of info lpInBuffer.SetupPacket.wValue = %USB_DEVICE_DESCRIPTOR_TYPE '<--- Not sure if correct, but tried for getting 1st peice of info lpInBuffer.SetupPacket.wIndex = 0 '<--- Not sure if correct, but tried for getting 1st peice of info lpInBuffer.SetupPacket.wLength = SIZEOF(lpInBuffer.SetupPacket) '<--- Not sure if correct, but tried for getting 1st peice of info '*** Fill in info to be gotten dwIoControlCode = %USB_REQUEST_GET_DESCRIPTOR nInBufferSize = SIZEOF(lpInBuffer) nOutBufferSize = SIZEOF(lpOutBuffer) ' ErrFunc = DeviceIoControl(hDevice, dwIoControlCode, lpInBuffer, nInBufferSize, lpOutBuffer, nOutBufferSize, lpBytesReturned, OverlappedType) IF DevHndl <> %INVALID_HANDLE_VALUE THEN ErrFunc = DeviceIoControl(DevHndl, dwIoControlCode, lpInBuffer, nInBufferSize, lpOutBuffer, nOutBufferSize, lpBytesReturned, BYVAL %NULL) END IF '*********************************** ERROR CHECKING ************************************** ErrFunc = GetLastError() 'Check for the error FormatMessage %FORMAT_MESSAGE_FROM_SYSTEM, BYVAL %NULL, ErrFunc, %NULL, ErrorBuff, SIZEOF(ErrorBuff), BYVAL %NULL 'Format the message MSGBOX "Get Descriptor = " + STR$(ErrFunc) + $TAB + ErrorBuff '******************************** END ERROR CHECKING ************************************* END FUNCTION
Comment