请问如何区别HID设备?
每个Hid设备都有Guid吗?或者类似GUID,能辨别出某一个设备。
谢谢!注:我用SetupDiGetDeviceRegistryProperty 或者 TJvHidDevice.PnPInfo.FClassGUID 取出两个设备的Guid,是相等的。

解决方案 »

  1.   

    同一种设备的guid好像本来就是相等的吧。具体还可以按vid和pid进一步区分。
      

  2.   

    to jennyvenus:
      恩 是的 供应商ID 和 产品ID 我前面已经用来校验了。
    我目前的情况是 同一种USB HID设备 电脑里可以插好多个.
    我想在他们之间区分。
      

  3.   

    to jennyvenus:
      那像我这种情况,我想判断用户选择后 是该往哪个设备去发指令 通过什么能定位出来 用户选择的是哪个设备呢?usb也可以跟com口一样 区分开来 是com1啊 还是com2吗?如果是的话 能否给点提示?谢谢
      

  4.   

    SetupDiEnumDeviceInterfaces可以吗?
      

  5.   

    我现在的做法是这样的,在枚举时,如果是某种特定的设备,比如我自己的设备,我在枚举时就使用createfile打开了,然后按枚举数量存储到全局的变量中,假设是handle[ 0 ], handle[ 1 ], ....., handle[ x ]中,在列表显示时,分别按照枚举顺序列为 "设备 0","设备 1",...... "设备 x",这样用户选择之后,我就直接使用handle[ x ]进行读写。
      

  6.   

    to jennyvenus:
      非常感谢你的回答,我也清晰了很多。但我现在的问题是两设备取出来的句柄是一样的。但我是用得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;
      

  7.   

    而他在WriteFile函数,又重新打开了下设备。这样说的话 那就是这个HidFileHandle句柄 在中间间断我是无法使用了 自己写的话 有点麻烦 而且肯定没有那个控件封装得好 郁闷
    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;
      

  8.   

    俺想他那个打开又关闭应该是做一些判断吧,不同设备的PnPInfo.DevicePath是有差异的,抱歉,俺的代码都是抄别人的,所知就只有这些了。