[DUG] USB device information

Tom Munro Glass gentoo at tmgcon.com
Fri Jul 22 11:32:32 NZST 2005


OK, I've managed to get to the point where I've got a device path, and I 
understand that I'm meant to open that with CreateFile. Unfortunately this 
isn't working, I get the message "A device attached to the system is not 
functioning". 

If I manage to get CreateFile to work, what do I do next to retrieve the 
details from the device, I'd guess a DeviceIOControl call but I don't know 
what arguments to use.

If anyone can provide more details, I'd be grateful. By the way, I need this 
to work on Win2K if that makes any difference.

Tom

On Thu, 21 Jul 2005 16:06, Phil Middlemiss wrote:
> Here is some code that we use to scan for Garmin USB GPS devices. You
> will have to adapt it to your purposes, but it should give you an idea
> of the routines you need to use, and the order in which you need to use
> them:
>
>     { scan for USB devices }
>     deviceinfoset := SetupDiCreateDeviceInfoList(nil, 0);
>     if (DWORD(deviceinfoset) <> INVALID_HANDLE_VALUE) then
>       try
>       // Retrieve the device information set for the interface class.
>       guid := GUID_DEVINTERFACE_GRMNUSB;
>       aguid := @GUID_DEVINTERFACE_GRMNUSB;
>       newdeviceinfoset := SetupDiGetClassDevsEx(aguid, nil, 0,
> DIGCF_PRESENT or DIGCF_DEVICEINTERFACE,
>         deviceinfoset, nil, nil);
>       if(DWORD(newdeviceinfoset) <> INVALID_HANDLE_VALUE) then
>         try
>         { enumerate the devices }
>         aindex := 0;
>         while True do
>           begin
>           infodata.cbSize := SizeOf(TSPDevInfoData);
>           { for each device }
>           if SetupDiEnumDeviceInfo(newdeviceinfoset, aindex, infodata) then
>             begin
>             pinfodata := @infodata;
>             bindex := 0;
>             while True do
>               begin
>               { for each interface }
>               interfacedata.cbSize := SizeOf(TSPDeviceInterfaceData);
>               if SetupDiEnumDeviceInterfaces(newdeviceinfoset,
> pinfodata, guid, bindex, interfacedata) then
>                 begin
>                 pinterfacedata := @interfacedata;
>                 preqsize := @reqsize;
>                 { get the buffer size }
>                 if (not
> SetupDiGetDeviceInterfaceDetail(newdeviceinfoset, pinterfacedata, nil, 0,
>                 preqsize, nil)) and (GetLastError =
> ERROR_INSUFFICIENT_BUFFER) then
>                   begin
>                   { allocate the buffer }
>                   pdetaildata := AllocMem(reqsize);
>                   pdetaildata.cbSize :=
> SizeOf(TSPDeviceInterfaceDetailData);
>                   { get the details }
>                     try
>                     if SetupDiGetDeviceInterfaceDetail(newdeviceinfoset,
> pinterfacedata, pdetaildata, Cardinal(reqsize),
>                     preqsize, pinfodata) then
>                       begin
>                       { check if the device has already been found }
>                       apath := PChar(@pdetaildata.DevicePath);
>                       alreadyfound := False;
>                       for i := 0 to High(foundevices) do
>                         begin
>                         alreadyfound := foundevices[i].path = apath;
>                         if alreadyfound then
>                           begin
>                           foundevices[i].found := True;
>                           break;
>                           end;
>                         end;
>                       if alreadyfound then
>                         begin
>                         Inc(bindex);
>                         continue;
>                         end;
>                       { add the device }
>
>                       <snip>
>
>                     finally
>                     FreeMem(pdetaildata);
>                     end;
>                   end;
>                 end
>               else
>                 begin
>                 anerror := GetLastError;
>                 if anerror = ERROR_NO_MORE_ITEMS then
>                   break;
>                 end;
>               Inc(bindex);
>               end;
>             end
>           else
>             begin
>             anerror := GetLastError;
>             if anerror = ERROR_NO_MORE_ITEMS then
>               break;
>             end;
>           Inc(aindex);
>           end;
>         finally
>         SetupDiDestroyDeviceInfoList(newdeviceinfoset);
>         end;
>       finally
>         SetupDiDestroyDeviceInfoList(deviceinfoset);
>       end;
>
> _______________________________________________
> Delphi mailing list
> Delphi at ns3.123.co.nz
> http://ns3.123.co.nz/mailman/listinfo/delphi


More information about the Delphi mailing list