请问如何区别HID设备?
每个Hid设备都有Guid吗?或者类似GUID,能辨别出某一个设备。
谢谢!注:我用SetupDiGetDeviceRegistryProperty 或者 TJvHidDevice.PnPInfo.FClassGUID 取出两个设备的Guid,是相等的。
每个Hid设备都有Guid吗?或者类似GUID,能辨别出某一个设备。
谢谢!注:我用SetupDiGetDeviceRegistryProperty 或者 TJvHidDevice.PnPInfo.FClassGUID 取出两个设备的Guid,是相等的。
恩 是的 供应商ID 和 产品ID 我前面已经用来校验了。
我目前的情况是 同一种USB HID设备 电脑里可以插好多个.
我想在他们之间区分。
那像我这种情况,我想判断用户选择后 是该往哪个设备去发指令 通过什么能定位出来 用户选择的是哪个设备呢?usb也可以跟com口一样 区分开来 是com1啊 还是com2吗?如果是的话 能否给点提示?谢谢
非常感谢你的回答,我也清晰了很多。但我现在的问题是两设备取出来的句柄是一样的。但我是用得TJvHidDevice.FHidFileHandle 。看了下它的源码 也是通过CreateFile来打开设备。只是让我迷惑得是 他在TJvHidDevice 构造函数里 最后一句用了CloseFile 所以导致所有的句柄都是INVALID_HANDLE_VALUE的值了。不知道为什么 他要这么处理,不敢乱改。而我现在还想用这个控件。不知道 是否有办法?谢谢。constructor TJvHidDevice.CtlCreate(const APnPInfo: TJvHidPnPInfo; const Controller: TJvHidDeviceController);
begin
inherited Create; FHidFileHandle := CreateFile(PChar(PnPInfo.DevicePath), GENERIC_READ or GENERIC_WRITE,
FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, 0);
FHasReadWriteAccess := HidFileHandle <> INVALID_HANDLE_VALUE;
// Win2000 hack
if not HasReadWriteAccess then
FHidFileHandle := CreateFile(PChar(PnPInfo.DevicePath), 0,
FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, 0);
if HidFileHandle <> INVALID_HANDLE_VALUE then
begin
FAttributes.Size := SizeOf(THIDDAttributes);
if not HidD_GetAttributes(HidFileHandle, FAttributes) then
raise EControllerError.Create(RsEDeviceCannotBeIdentified);
end
else
raise EControllerError.Create(RsEDeviceCannotBeOpened);
// the file is closed to stop using up resources
CloseFile; //这句
end;
function TJvHidDevice.WriteFile(var Report; ToWrite: DWORD; var BytesWritten: DWORD): Boolean;
begin
Result := False;
if OpenFile then
Result := Windows.WriteFile(HidFileHandle, Report, ToWrite, BytesWritten, nil);
end;
function TJvHidDevice.OpenFile: Boolean;
begin
// check if open allowed (propagates this state)
if IsAccessible then
if HidFileHandle = INVALID_HANDLE_VALUE then // if not already opened
begin
FHidFileHandle := CreateFile(PChar(PnPInfo.DevicePath), GENERIC_READ or GENERIC_WRITE,
FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, 0);
FHasReadWriteAccess := HidFileHandle <> INVALID_HANDLE_VALUE;
// Win2000 hack
if not HasReadWriteAccess then
FHidFileHandle := CreateFile(PChar(PnPInfo.DevicePath), 0,
FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, 0);
if HidFileHandle <> INVALID_HANDLE_VALUE then
begin
if NumInputBuffers <> 0 then
HidD_SetNumInputBuffers(HidFileHandle, NumInputBuffers);
HidD_GetNumInputBuffers(HidFileHandle, FNumInputBuffers);
end;
end;
Result := HidFileHandle <> INVALID_HANDLE_VALUE;
end;