在我的 delphi 应用程序中,我使用 TJvHidDevice 从 USB 设备写入和读取报告。
设备信息如下
Bus Type: USB
Device Type: Human Interface Device
Power Drawn: 100 milliamps @ 5.0 volts
Endpoint 0: Type=CTL Class=03 SubClass=00 Protocol=00 MaxPacket=8
Endpoint 1 OUT: Type=INT Class=03 SubClass=00 Protocol=00 MaxPacket=40
Endpoint 2 IN: Type=INT Class=03 SubClass=00 Protocol=00 MaxPacket=40
Hardware ID: USB\Vid_0483&Pid_5750&Rev_0200
Data Read: 572 bytes
Data Written: 384 bytes
Utilization: 100%
它有三个端点,当我向它发送报告时,它将与端点 2 一起输出报告。我的代码是
报告结构
TReport = packed record
ReportID: byte;
Data: array[0..64] of byte;
end;
签出设备
procedure TfrmMain.HidDevsDeviceChange(Sender: TObject);
begin
if HidDevs.CheckOutByID(FHidDev, USB_VID, USB_PID) then
begin
FHidDev.NumInputBuffers := 65;
FHidDev.NumOverlappedBuffers := 65;
FUsbDevice.Device := FHidDev;
FHidDev.OnData:=OnRead;
end;
end;
OnRead Enent
procedure TfrmMain.OnRead(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])]);
AddLog('Received: ');
SetLogColor(clPurple);
AddLog(Str, False);
end;
我可以写报告
if not FDevice.SetOutputReport(FBuffer, FDevice.Caps.OutputReportByteLength) then
但是,在SetOutputReport之后没有任何反应。如果我使用GetInputReport而不是OnRead,则会出现错误:31,如果使用readFile,应用程序将挂起。为什么,我该怎么办?