No announcement yet.

USB DeviceIoControl and No HID

  • Filter
  • Time
  • Show
Clear All
new posts

    Nicely Done Pierre

    I found a few of my external hubs, but they show up in control panel as "General Purpose USB Hub", but unfortunately does not show up in your code. (I am guessing just a function call not accounted for, but looking through the code to see if I can spot it)

    Just for details, 1 external hub is a Micro Innovations 4 port hub(not powered), and the other is a powered D-Link DSB-H4 external hub.

    If you need more, let me know and I will see if I can find it in the properties.
    Engineer's Motto: If it aint broke take it apart and fix it

    "If at 1st you don't succeed... call it version 1.0"

    "Half of Programming is coding"....."The other 90% is DEBUGGING"

    "Document my code????" .... "WHYYY??? do you think they call it CODE? "


      Thank Cliff,

      I have no external USB hub here so if you feel like
      checking wat's wrong with the external HUB detection
      then a good place to start could be just after this line...
      <<NodeConnection.ConnectionIndex = PortIndex>>
      Last edited by Pierre Bellisle; 23 Mar 2008, 06:27 PM.


        Guys just this

        I downloaded the progggies and run then on my machine,
        The compiled one PBCC proggies has other output then the PBW wich i compiled myself.

        The PBCC one his output is correct for my USB-devices who are on my 4 ports usb-hub! and totally missed on the Win progie!

        (the pbc one used the original id-list)

        Hmm so wondering the proggie could be just fine but the list is not maintained so that every update of the list has the same things on the same pos???

        Hope this helps a bit
        To Ask or Not To Ask ?


          Thank Adrian,

          Good to know that the CC version can get devices through your USB HUB.

          Seem's that more work have to be done on the Win version.

          The id-list is responsible only for 2 lines,
          "Vendor(Linux id)" and "Product(Linux id)",
          so that should'nt be the problem.

          I'll try to update the code if I can borrow a HUB...



            Thank you very much (merci beaucoup ) Pierre for your code.

            With your software you gave me helped solve a BIG problem, but how to find the right hd letter to the USB key ?, each time i move my usb key to another computer, it's not the same hd letter, my software is the same but not my hd letter.

            The purpose is simple, the usb key is used as a log file and datas files, it's the same main software but i have to upload the datas and download the logs.

            I am not familiar with usb device, i can tell to the software wait for the key and after that how to detect the letter?, but now i see the light

            Thank you for you answer.



              Salut Guy,

              Telling that a device is a disk
              when "Interface class = Storage" is a start.
              Getting the coresponding drive letter will need more work I guess.

              Here you get 2 more programs that may help you to acheive that...

              Mounted devices from registry

              Get volume information and path name

              Have fun


                Both USB digger for PB-Cc and PB-Win have been updated to work with external HUB.

                USB digger for Console compiler

                USB digger for Windows compiler

                Linux ids table


                  Many thanks Pierre and Cliff,
                  Your work is much appreciated as I too have to code software that talks directly to USB devices sometime in the future.
                  Best Regards
                  Gary Barnes
                  The Control Key

                  If you are not part of the solution
                  then you are either a gas, solid, plasma or some other form of matter.


                    Hi Pierre,

                    Thank you very much for your answer, to night i tested your software wow !!! GOOD JOB .

                    I do some modifications for a usb key and automatic scanning with my software ... humm it's a beginning ...

                    I do a search on google, it's possible to do a usb sniffer with power basic or it's reseved only for "C" language ?

                    Have a nice day.



                      Its like breaking 100 or breaking 90 in golf....unsurmountable, but once you do you KNOWWwwwww you can do it again

                      I will be the 1st to admit if not for Pierre's help I would not have gotten as far as I have (hoping farther, but still researching)

                      Guy I was curious on your comment on the avenue you are attacking?

                      Personally my core idea is to be able to boil things down to a "Open File, Send to File, Read from File, Close File" point of view, but anyone that has even researched anything beyond HID, or just use the driver concept never got that far.

                      I know I am a glutton for punishment....but I am still learning
                      Engineer's Motto: If it aint broke take it apart and fix it

                      "If at 1st you don't succeed... call it version 1.0"

                      "Half of Programming is coding"....."The other 90% is DEBUGGING"

                      "Document my code????" .... "WHYYY??? do you think they call it CODE? "


                        thank for the thank, I'm glad to know that this code can help a little.

                        about sniffer, the tricky part is the USB driver.
                        I do not think that PB is the right tool for that.
                        Something interesting may be to use
                        Benoît Papillaut's USB sniffer driver
                        with your own program, his source code is aviable on the web.

                        if you find USB device that are not in the USB Linux list
                        it might be kind to send the id Vendor, id Product,
                        Manufacturer string and Product string info to Stephen Gowdy
                        so he can update it. His email is on the fourth line of the file.
                        Last edited by Pierre Bellisle; 18 Apr 2008, 12:01 AM.


                          Hi everyone,

                          Pierre: I download the software of Benoît Papillaut's USB sniffer, and
                          try it, i would like to see the raw data on usb key ... wow, also i
                          download "pdf" usb 2.0 protocol it's lot more complicate than a sd card
                          with spi protocol .

                          Cliff: "Guy I was curious on your comment on the avenue you are attacking?"

                          Detecting the letter, the easy way is before starting my software is to
                          insert the usb key and after that i verified for a new hd letter by the
                          program, but it's not usefull for me, i dont know if it's possible to
                          using windows interrupt like a microcontroler (atmel atmega).

                          But interrupt will be very hot for me! i know how to do that with microcontroler
                          but not with windows. I can tell to my software when flag and when the usb
                          key is ready, software check usb key and do the rest of job and the same
                          thing when i disconnect de key.

                          The second way is polling my software to check a new hd letter and
                          after that i check the serial number of the usb key and now i
                          can do what i needed to do, i have to take care of the rest of the task
                          of my software unless crash of others communications with hardware devices.

                          You know i'm not the best programmer, like your are, i used
                          powerbasic to communicate with my hardware (microcontroller with bascom
                          software) and it's not a business for me, just for fun! but powerbasic
                          it's easy, fast and i can talk to ethernet port by tcpip.

                          This post opened my eyes for one big thing, how to see the usb key
                          info! with that i can used the cheapest part to put a hardware device
                          for security license and backup datas and logs, no password needed you
                          dont have the key you can't do nothing except running the software,
                          the price of usb key! we dont talk ...

                          For the moment i tested few things with some success, of course after my job.

                          Thank you for your help and ideas, more heads ... more fun.



                            Not sure if this is what you meant (but as close to an "Interrupt" as I can think of.

                            Pierre has code here (as well as others) that can be found in the Pb Source Code Forums That I think you meant by "Interrupt" (aka: not wasting extra processing time waiting for an event, but be notified when the event happens", which is what I would want if working with a microcontroller, or any software involved if I can help it)

                            Since I can not locate Pierre's example at the moment, check the below (you will be AMAZED!!!!
                            #COMPILE EXE '#Win 804#
                            #REGISTER NONE
                            #DIM ALL
                            #INCLUDE "Win32Api.Inc" '2003-05-27
                            GLOBAL hList AS DWORD
                            %Listbox = 101
                            %Button  = 201
                            'From DBT.H - Equates for WM_DEVICECHANGE and BroadcastSystemMessage
                            %WM_DEVICECHANGE             = &H0219
                            'DEV_BROADCAST_HDR Structure
                            %DBT_DEVTYP_OEM              = 0 'OEM- or IHV-defined device type.
                            %DBT_DEVTYP_VOLUME           = 2 'Logical volume
                            %DBT_DEVTYP_PORT             = 3 'Port device (serial or parallel).
                            %DBT_DEVTYP_DEVICEINTERFACE  = 5 'Class of devices.
                            %DBT_DEVTYP_HANDLE           = 6 'File system handle.
                            '%WM_DEVICECHANGE/CBWPARAM specifies the event/CBLPARAM specifies data
                            %DBT_DEVNODES_CHANGED        = &H0007& 'Device has been added or removed CBLPARAM = zero
                            %DBT_QUERYCHANGECONFIG       = &H0017& '
                            %DBT_CONFIGCHANGED           = &H0018& '
                            %DBT_CONFIGCHANGECANCELED    = &H0019& '
                            %DBT_DEVICEARRIVAL           = &H8000& 'System detected a new device
                            %DBT_DEVICEQUERYREMOVE       = &H8001& 'Wants to remove, may fail
                            %DBT_DEVICEQUERYREMOVEFAILED = &H8002& 'Removal aborted
                            %DBT_DEVICEREMOVEPENDING     = &H8003& 'About to remove, still available
                            %DBT_DEVICEREMOVECOMPLETE    = &H8004& 'Device is gone
                            %DBT_DEVICETYPESPECIFIC      = &H8005& 'Type specific event
                            %DBT_CUSTOMEVENT             = &H8006& '
                            %DBT_USERDEFINED             = &HFFFF& '
                            'Drive or media, networked or not
                            %DBTF_MEDIA                  = 1     'Media comings and goings
                            %DBTF_NET                    = 2     'Network volume
                            TYPE DEV_BROADCAST_HDR
                              dbch_size       AS DWORD
                              dbch_devicetype AS DWORD
                              dbch_reserved   AS DWORD
                            END TYPE
                            TYPE DEV_BROADCAST_OEM
                              dbco_size       AS DWORD 'Specifies the size of this structure, in bytes.
                              dbco_devicetype AS DWORD 'Set to the device type DBT_DEVTYPE_OEM.
                              dbco_reserved   AS DWORD 'Reserved; do not use.
                              dbco_identifier AS DWORD 'An OEM-specific identifier for the device.
                              dbco_suppfunc   AS DWORD 'An OEM-specific function value. Possible values depend on the device.
                            END TYPE
                            TYPE DEV_BROADCAST_VOLUME
                              dbch_size       AS DWORD 'Specifies the size of this structure, in bytes.
                              dbch_devicetype AS DWORD 'Set to the device type DBT_DEVTYP_VOLUME.
                              dbch_reserved   AS DWORD 'Reserved; do not use.
                              dbcv_unitmask   AS DWORD 'Logical drive, bit 0 is A:, bit 1 is B:...
                              dbcv_flags      AS WORD  'Specifies whether drive or media is affected.
                                                       'This parameter can be one of the following values.
                                                       ' %DBTF_MEDIA Change affects media in drive. If not set,
                                                       '             change affects physical device or drive.
                            END TYPE                   ' %DBTF_NET   Indicated logical volume is a network volume.
                            TYPE DEV_BROADCAST_PORT
                              dbcp_size       AS DWORD 'Specifies the size of this structure, in bytes.
                              dbcp_devicetype AS DWORD 'Set to the device type DBT_DEVTYP_PORT.
                              dbcp_reserved   AS DWORD 'Reserved; do not use.
                              dbcp_name(0)    AS BYTE  'A null-terminated string specifying the friendly name of the port/device.
                            END TYPE
                            TYPE DEV_BROADCAST_DEVICEINTERFACE
                              dbcc_size       AS DWORD 'Specifies the size, in bytes, of this structure.
                              dbcc_devicetype AS DWORD 'Set to the device type DBT_DEVTYP_DEVICEINTERFACE
                              dbcc_reserved   AS DWORD 'Reserved; do not use.
                              dbcc_classguid  AS DWORD 'A globally unique identifier (GUID) for the interface device class.
                              dbcc_name(0)    AS BYTE  'A null-terminated string specifying the name of the device.
                            END TYPE
                            TYPE DEV_BROADCAST_HANDLE
                              dbch_size       AS DWORD 'Specifies the size, in bytes, of this structure.
                              dbch_devicetype AS DWORD 'Set to the DBT_DEVTYP_HANDLE device type.
                              dbch_reserved   AS DWORD 'Reserved; do not use.
                              dbch_handle     AS DWORD 'Handle specified in the call to the RegisterDeviceNotification function.
                              dbch_hdevnotify AS DWORD 'Handle to device notification, returned by the RegisterDeviceNotification.
                              'The following are valid only for DBT_CUSTOMEVENT
                              dbch_eventguid  AS GUID  'A globally unique identifier (GUID) for the custom event.
                              dbch_nameoffset AS LONG  'The offset of an optional string buffer.
                              dbch_data(0)    AS BYTE  'Optional binary data.
                            END TYPE
                            FUNCTION LA(sItem AS STRING) AS LONG 'ListAdd
                             LOCAL LastItem AS LONG
                             LastItem = SendMessage(hList, %LB_ADDSTRING, 0, BYVAL STRPTR(sItem))
                             SendMessage hList, %LB_SETCURSEL, LastItem, 0  'Select an item and scroll it to view
                             SendMessage hList, %LB_SETCURSEL, -1, 0        'UnHighlight item
                            END FUNCTION
                            CALLBACK FUNCTION DlgProc
                             LOCAL Device_HDR    AS DEV_BROADCAST_HDR POINTER
                             LOCAL Device_Volume AS DEV_BROADCAST_VOLUME POINTER
                             LOCAL sDriveLetter  AS STRING
                             LOCAL sBuffer       AS STRING
                             SELECT CASE AS LONG CBMSG
                               CASE %WM_DEVICECHANGE
                                 SELECT CASE CBWPARAM
                                     IF CBWPARAM = %DBT_DEVICEARRIVAL THEN
                                       LA "%DBT_DEVICEARRIVAL"
                                       LA "%DBT_DEVICEREMOVECOMPLETE"
                                     END IF
                                     Device_HDR = CBLPARAM
                                     SELECT CASE @Device_HDR.dbch_devicetype
                                       CASE %DBT_DEVTYP_OEM             'OEM- or IHV-defined device type.
                                         IF CBWPARAM = %DBT_DEVICEARRIVAL THEN
                                           sBuffer = "%DBT_DEVTYP_OEM inserted."
                                           sBuffer = "%DBT_DEVTYP_OEM removed."
                                         END IF
                                         LA sBuffer
                                       CASE %DBT_DEVTYP_VOLUME          'Logical volume
                                         Device_Volume = CBLPARAM
                                         IF (@Device_Volume.dbcv_flags AND %DBTF_MEDIA) THEN
                                           sBuffer = "Media "
                                           sBuffer = "Physical device "
                                         END IF
                                         IF (@Device_Volume.dbcv_flags AND %DBTF_NET) THEN
                                           sBuffer = "Networked " & sBuffer
                                         END IF
                                         sDriveLetter = CHR$((26 - INSTR(BIN$(@Device_Volume.dbcv_unitmask, 26), "1")) + 65) & ":"
                                         IF CBWPARAM = %DBT_DEVICEARRIVAL THEN
                                           sBuffer = sBuffer & sDriveLetter & " inserted."
                                           sBuffer = sBuffer & sDriveLetter & " removed."
                                         END IF
                                         LA sBuffer
                                       CASE %DBT_DEVTYP_PORT            'Port device (serial or parallel).
                                         IF CBWPARAM = %DBT_DEVICEARRIVAL THEN
                                           sBuffer = "%DBT_DEVTYP_PORT inserted."
                                           sBuffer = "%DBT_DEVTYP_PORT removed."
                                         END IF
                                         LA sBuffer
                                       CASE %DBT_DEVTYP_DEVICEINTERFACE 'Class of devices.
                                         sBuffer = "%DBT_DEVTYP_DEVICEINTERFACE"
                                         LA sBuffer
                                       CASE %DBT_DEVTYP_HANDLE          'File system handle.
                                         sBuffer = "%DBT_DEVTYP_HANDLE"
                                         LA sBuffer
                                     END SELECT
                                   CASE %DBT_DEVNODES_CHANGED        'Device has been added or removed CBLPARAM = zero
                                     LA "%DBT_DEVNODES_CHANGED"
                                   CASE %DBT_QUERYCHANGECONFIG       '
                                     LA "%DBT_QUERYCHANGECONFIG"
                                   CASE %DBT_CONFIGCHANGED           '
                                     LA "%DBT_CONFIGCHANGED"
                                   CASE %DBT_CONFIGCHANGECANCELED    '
                                     LA "%DBT_CONFIGCHANGECANCELED"
                                   CASE %DBT_DEVICEARRIVAL           'System detected a new device
                                     LA "%DBT_DEVICEARRIVAL"
                                   CASE %DBT_DEVICEQUERYREMOVE       'Wants to remove, may fail
                                     LA "%DBT_DEVICEQUERYREMOVE"
                                   CASE %DBT_DEVICEQUERYREMOVEFAILED 'Removal aborted
                                     LA "%DBT_DEVICEQUERYREMOVEFAILED"
                                   CASE %DBT_DEVICEREMOVEPENDING     'About to remove, still available
                                     LA "%DBT_DEVICEREMOVEPENDING"
                                   CASE %DBT_DEVICEREMOVECOMPLETE    'Device is gone
                                     LA "%DBT_DEVICEREMOVECOMPLETE"
                                   CASE %DBT_DEVICETYPESPECIFIC      'Type specific event
                                     LA "%DBT_DEVICETYPESPECIFIC"
                                   CASE %DBT_CUSTOMEVENT             '
                                     LA "%DBT_CUSTOMEVENT"
                                   CASE %DBT_USERDEFINED             '
                                     LA "%DBT_USERDEFINED"
                                   CASE ELSE
                                     LA "%WM_DEVICECHANGE " & HEX$(CBWPARAM)
                                 END SELECT
                              END SELECT
                            END FUNCTION
                            FUNCTION PBMAIN()
                             LOCAL hDlg AS DWORD
                             DIALOG NEW %HWND_DESKTOP ,"WM_DEVICECHANGE - notify", , , 200, 200, _
                               %WS_CAPTION OR %WS_MINIMIZEBOX OR %WS_SYSMENU, %WS_EX_TOPMOST TO hDlg
                             SetClassLong hDlg, %GCL_HICON, LoadIcon(BYVAL %NULL, BYVAL %IDI_INFORMATION) 'Set a nice icon
                             CONTROL ADD LISTBOX, hDlg, %Listbox, , 5, 5, 190, 190, %LBS_NOTIFY OR %WS_TABSTOP OR %WS_VSCROLL, %WS_EX_LEFT
                             hList = GetDlgItem(hDlg, %ListBox)
                             LA "Insert or remove a device"
                             DIALOG SHOW MODAL hDlg CALL DlgProc
                            END FUNCTION
                            Pretty sweet huh? A wealth of knowledge in one simple example, easily expanded on....( Pierre for that one)

                            Hmmm the more I think of it...the more I wonder if combining 2 of Pierre's examples isnt EXACTLY what you need?
                            Engineer's Motto: If it aint broke take it apart and fix it

                            "If at 1st you don't succeed... call it version 1.0"

                            "Half of Programming is coding"....."The other 90% is DEBUGGING"

                            "Document my code????" .... "WHYYY??? do you think they call it CODE? "


                              Hi Cliff,

                              I am amazed by your knowledge, I offer the coffee for people who use powerbasic, you are simply amazing.

                              I think it's time for me to go school... very big defference between professionals and beginners.

                              I dont exactly what kind of job you do, Cliff and Pierre, but i can tell you only one thing THANK YOU

                              Now i know what i have to do for the next days (my spare time) ... reading, understanding your examples, writing code, testing software.

                              You know what, this code give me the letter of de usb key, wow, i can't asking more

                              Thank you for your answers ...