Rework
This commit is contained in:
@@ -9,16 +9,11 @@ uses
|
||||
type
|
||||
TWinUsbInterfaceHandle = THandle;
|
||||
|
||||
|
||||
|
||||
TWinUsbDriver = class( TUsbDriver)
|
||||
|
||||
public
|
||||
class procedure Scan( ScanCallback: TScanCallback); override;
|
||||
|
||||
|
||||
|
||||
|
||||
protected
|
||||
fWinUsbHandle : TWinUsbInterfaceHandle;
|
||||
|
||||
@@ -36,10 +31,14 @@ type
|
||||
function GetAssociatedInterface
|
||||
(
|
||||
InterfaceIndex : byte;
|
||||
var InterfaceHandle): boolean; override;
|
||||
var InterfaceHandle
|
||||
): boolean; override;
|
||||
|
||||
function QueryInterfaceSettings( AlternateSettingNumber : byte;
|
||||
var AlternateSettingDescriptor : TUsbAlternateSettingDescriptor): boolean; override;
|
||||
function QueryInterfaceSettings
|
||||
(
|
||||
AlternateSettingNumber : byte;
|
||||
var AlternateSettingDescriptor : TUsbAlternateSettingDescriptor
|
||||
): boolean; override;
|
||||
|
||||
function QueryPipe
|
||||
(
|
||||
@@ -91,9 +90,6 @@ type
|
||||
public
|
||||
procedure AfterConstruction; override;
|
||||
procedure BeforeDestruction; override;
|
||||
|
||||
|
||||
|
||||
end;
|
||||
|
||||
implementation
|
||||
@@ -243,17 +239,17 @@ end;
|
||||
procedure TWinUsbDriver.BeforeDestruction;
|
||||
begin
|
||||
Close;
|
||||
|
||||
fWinUsbHandle := INVALID_HANDLE_VALUE;
|
||||
fDeviceHandle := INVALID_HANDLE_VALUE;
|
||||
|
||||
inherited;
|
||||
end;
|
||||
|
||||
// ================================================================================================
|
||||
// Open
|
||||
//
|
||||
// Note:
|
||||
// fDevicePath is in the form:
|
||||
// 'USB\VID_04B4&PID_8613\6&26c545a4&0&1#Cypress FX2
|
||||
//
|
||||
// it must be converted into:
|
||||
// DevicePath must be in the form of:
|
||||
// \\?\USB#VID_04B4&PID_8613#6&26c545a4&0&1#{CDDE880F-898A-4DAB-B0EA-51FBA32C1D82}
|
||||
// ================================================================================================
|
||||
procedure TWinUsbDriver.Open;
|
||||
@@ -270,13 +266,14 @@ begin
|
||||
// Prepare device path
|
||||
// ---------------------------------------------------------------
|
||||
// strip device description
|
||||
i := Pos('#', path);
|
||||
{ i := Pos('#', path);
|
||||
|
||||
if i > 0 then
|
||||
path := Copy( path, 1, i-1);
|
||||
|
||||
path := ReplaceStr(path,'\','#');
|
||||
path := '\\?\'+path+'#'+GuidToString(fDriverID);
|
||||
path := '\\?\'+path+'#'+fInterfaceGuid;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// open
|
||||
@@ -546,9 +543,9 @@ var
|
||||
s : string;
|
||||
|
||||
begin
|
||||
dsc := CreateComObject( CLSID_FunctionDiscovery) as IFunctionDiscovery;
|
||||
|
||||
try
|
||||
dsc := CreateComObject( CLSID_FunctionDiscovery) as IFunctionDiscovery;
|
||||
|
||||
cat := FCTN_CATEGORY_PNP;
|
||||
hr := dsc.GetInstanceCollection(cat, nil, true, fcts);
|
||||
|
||||
@@ -562,18 +559,14 @@ begin
|
||||
begin
|
||||
if 'WinUSB' = propv.pwszVal then
|
||||
begin
|
||||
// \\?\USB#VID_04B4&PID_8613#6&26c545a4&0&1#{CDDE880F-898A-4DAB-B0EA-51FBA32C1D82}
|
||||
|
||||
props.GetValue( PKEY_Device_InstanceId, propv);
|
||||
s := propv.pwszVal;
|
||||
|
||||
props.GetValue( PKEY_Device_DeviceDesc, propv);
|
||||
s := s +'#'+ propv.pwszVal;
|
||||
s := StringReplace( propv.pwszVal, '\', '#', [rfReplaceAll]);
|
||||
s := Uppercase('\\?\' +s +'#' +fInterfaceGuid);
|
||||
|
||||
ScanCallback( s);
|
||||
|
||||
// if Map.ContainsKey( s) then
|
||||
// Map.Remove( s);
|
||||
//
|
||||
// Map.Add( s, TUsbDeviceInfo.Create(s, self))
|
||||
ScanCallback( s)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -635,9 +628,8 @@ initialization
|
||||
// The device path must look like this:
|
||||
// \\?\USB#VID_04B4&PID_8613#6&26c545a4&0&1#Cypress-FX2
|
||||
// --------------------------------------------------------------------------------
|
||||
TWinUsbDriver.fDriverID := StringToGuid('{CDDE880F-898A-4DAB-B0EA-51FBA32C1D82}');
|
||||
|
||||
RegisterDriver( TWinUsbDriver);
|
||||
// TWinUsbDriver.fDriverID := StringToGuid('{CDDE880F-898A-4DAB-B0EA-51FBA32C1D82}');
|
||||
// RegisterDriver( TWinUsbDriver);
|
||||
end;
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user