如何使用TJvHidDevice读取HID设备数据

如何使用TJvHidDevice读取HID设备数据

本文介绍了如何使用TJvHidDevice读取HID设备数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Delphi2010中使用 TJvHidDevice 来读取 HID设备数据。我想读取 InkTable t的墨水位置(X和Y)。我的设备名称为 DigiMemo ,它是笔和平板电脑的HID​​设备。
谢谢

How to read HID Device Data by using TJvHidDevice in Delphi2010. I want to read the Ink position (X and Y) of InkTablet. My Device name is DigiMemo, its a Pen and Tablet HID device.Thanks All

推荐答案

我用它通过PC上的USB蓝牙适配器读取PS3蓝光遥控器。 。您可以使用它来读取任何其他HID设备,只需对其进行一些实验即可检索每个操作的代码。

I use this to read the PS3 blu-ray remote through a USB bluetooth dongle on the pc. You can use it to read any other HID device, just need to experiment a little with it to retrieve the codes for each action.

function JvHidDeviceController1Enumerate(HidDev: TJvHidDevice; const Idx: Integer): Boolean;
procedure PS3Read(HidDev: TJvHidDevice; ReportID: Byte; const Data: Pointer; Size: Word);

PS3Dev: TJvHidDevice;
PS3Box: TGroupBox;
PS3BDRemote: TCheckBox;
ps3DemoLabel: TLabel;

function JvHidDeviceController1Enumerate(HidDev: TJvHidDevice; const Idx: Integer): Boolean;
Var  Dev: TJvHidDevice;
begin
  if HidDev.ProductName = 'BD Remote Control' then
  begin
   PS3Box.Caption:= 'PS3 - Status: found';
   JvHidDeviceController1.CheckOutByIndex(Dev, Idx);
   Dev.NumInputBuffers := 128;
   Dev.NumOverlappedBuffers := 128;
   Dev.OnData := PS3Read;
   PS3Dev:= Dev;
  end;
   Result := True;
end;

procedure test;
begin
 if not PS3BDRemote.Checked then
 begin
  if Assigned(PS3Dev) then
  begin
   JvHidDeviceController1.CheckIn(PS3Dev);
   PS3Dev.OnData := nil;
   PS3Dev:= nil;
  end;
  PS3Box.Caption:= 'PS3 - Disabled';
 end
 else
 begin
  if not Assigned(PS3Dev) then JvHidDeviceController1.Enumerate
   else PS3Box.Caption:= 'PS3 - Status: found';
 end;
end;

procedure PS3Read(HidDev: TJvHidDevice; ReportID: Byte; const Data: Pointer; Size: Word);
var I: Integer;
  Str: string;
begin
  Str := Format('RD %.2x  ', [ReportID]);
  for I := 0 to Size - 1 do
    Str := Str + Format('%.2x ', [Cardinal(PChar(Data)[I])]);
  MyKillChar(Str,' ',false);
  if Str = 'RD010000080BFFFFFFFFFF0103' then
  begin
   // enter was pressed, do stuff here (button down)
   Exit;
  end;
  if Str = 'RD01000000FFFFFFFFFFFF0003' then
  begin
   // enter was pressed, do stuff here (button up)
   Exit;
  end;
  ps3DemoLabel.Caption:= Str;
  Logs.Memo1.lines.add(str);
end;

这篇关于如何使用TJvHidDevice读取HID设备数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 17:38