• Welcome to Forum.Deepsoftware.Com. Please login or sign up.
 

HidD_GetInputReport - no Feedback in buffer

Started by moelski, June 07, 2009, 01:15:04 pm

Previous topic - Next topic

moelski

Hi !

Actually I´m writing some code to communicate with a USB HID Device.
This one : http://www.elv.de/USB-Schaltinterface-USB-SI1,-Komplettbausatz/x.aspx/cid_74/detail_10/detail2_24914

Communication works from my PC to the device but I´m not able to get the feedback from the device.
I use this code:
procedure TForm1.Communicate(Command : Byte);
var lIn  : Array [0..35] of Byte;
    lOut : Array [0..35] of Byte;
    i    : Integer;
begin
  nrHid1.Active := True;
  for i := 0 to 35 do lOut[i] := $0;

  // Senden
  lIn[0] := $01;            // Report ID   0x01       Datenrichtung vom Host zum HID-Device
  case Command of
    3 : begin               // AN
          lIn[1] := $02;    // Länge
          lIn[2] := $F1;    // Code
          lIn[3] := $01;    // Param AN
          for i := 4 to 35 do  lIn[i] := $0;
        end;
  end;
  nrHid1.WriteReport(@lIn, 36);

  HidD_GetInputReport(nrHid1.HidDevice.Handle, @lout, 36);
  if lout[2] = $90 then begin
    case lout[3] of
      $00 : Memo1.Lines.Add('Kein Fehler');
      $01 : Memo1.Lines.Add('Befehl ungültig');
      $02 : Memo1.Lines.Add('Manuelle Schaltung');
      $10 : Memo1.Lines.Add('Unbegrenzt Aus');
      $11 : Memo1.Lines.Add('Unbegrenzt An');
    end;
  end;

  nrHid1.Active := False;
end;


I use an USB analyzer to see the data which is send from and to the device. I can see that the correct data is send to the computer. But I never get data in lout. I also tried ReadReport but this results in a hanging application. The report length is ok - it´s always 36.

Do you have any idea what´s going wrong here?

Greetz Dominik

btw: I´m a registred user of nrcomm Pro. You send me the latest version 8.26 some days ago.

Roman Novgorodov

Hello

Thank you for detail information.

Possible an incoming data is available in OnAfterReceive event.
Did you try the HIDDemo? Does it show the incoming reports after your command?

Roman Novgorodov
DeepSoftware llc - The professional components for Delphi/CBuilder/.NET. The high quality custom software development.
Forums.nrCommLib.Com - DeepSoftware Tech Support Forum.

moelski

Hi Roman,

Ok OnAfterReceive works.
But why is it not possi ble to get the feedback directly via ReadReport?

The problem I see with OnAfterReceive is that it is another procedure. So you have to synchronize the uestion and the answer to / from your usb device if you need the feedback immediately.

Roman Novgorodov

Hello

Unfortunately, the latest release of TnrHID component reads the incoming data internally and places it to paramas of OnAfterReceive event.
We will extends component functionality in the future.

I see that you use the HidD_GetInputReport() system call instead call the TnrHid.SetOutputReport() method.
You are real programmer :-)
therefore I can recommend the following:
Create your own handle over CreateFile() system call.
You can use nrHid1.HidDevice.NameSymbolic property as file name string.
After that use HidD_GetInputReport() and HidD_SetOutputReport() with new handler.

Roman Novgorodov
DeepSoftware llc - The professional components for Delphi/CBuilder/.NET. The high quality custom software development.
Forums.nrCommLib.Com - DeepSoftware Tech Support Forum.

moelski

Hi Roman,

QuoteCreate your own handle over CreateFile() system call.

Ok I tried to use nrHid1.HidDevice.Handle. But with that handle I got no feedback from the device.

I will try your solution the evening.

And one additional question ... What is the purpose of the Feature Report.
And how can I use SendChar / SendString with USB HID. This makes no sense to me.

Greetz Dominik

btw: The Smliy images in the message post window are gone. I only see "missed images" instead of smilies.

Roman Novgorodov

Hi

You can't use nrHid1.HidDevice.Handle because it is already used by internal TnrHid thread and all incoming data will be read by this thread.
You need a new original handle for call HidD_GetInputReport() function.

Feature Reports specify configuration data of HID device.

You can see TnrHID.SendString() usage in HIDDemo project.

SendChar() sends a single char to HID device. But I don't think that it will be success because the ID report is needed always. This method is implemented for compatible with nrComm Lib class hierarchy :-)

I don't see "missed images" anywere ... We will check ...

Roman Novgorodov
DeepSoftware llc - The professional components for Delphi/CBuilder/.NET. The high quality custom software development.
Forums.nrCommLib.Com - DeepSoftware Tech Support Forum.

moelski

hi Roman,

Thx for the information. Niw it is more clear to me.

I took a deeper look into the sources and I saw that you use "WriteFile" when I call "nrHid1.WriteReport".
Why don´t you use DeviceIOControl?

I tried this code before nrcomm:
DeviceHandle := CreateFile ('\\?\hid#vid_1b1f&pid_c00a#6&4c197d7&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}',
                            Generic_write, File_Share_write, nil,
open_existing, 0, 0);
lIn.bFunction := 01;
bResult := DeviceIoControl(DeviceHandle, $04, @lIn, sizeof(lIn),
  @lOut, sizeof (lOut), nBytes, nil);
CloseHandle (DeviceHandle);

But I never got this working. I think it´s because of my wrong code.
But all samples I found on the web use DeviceIOControl.

Sorry for my additional questions, but I want to get a better understanding of USB communication :-)

Greetz Dominik

Roman Novgorodov

Hello

Please check that DeviceHandle is not INVALID_HANDLE_VALUE.

If handle is valid you can use your code for prepare buffer and call following I/O operations:

  HidD_SetOutputReport(DeviceHandle, @lIn, 36); // or WriteFile()
  HidD_GetInputReport(DeviceHandle, @lout, 36); // or ReadFile()

The DeviceIoControl() call us not needed here. :-)

Roman Novgorodov
DeepSoftware llc - The professional components for Delphi/CBuilder/.NET. The high quality custom software development.
Forums.nrCommLib.Com - DeepSoftware Tech Support Forum.