Author Topic: Vista Problem with HidAfterReceive?  (Read 1902 times)

moelski

  • Full Member
  • ***
  • Posts: 122
    • View Profile
Vista Problem with HidAfterReceive?
« on: September 02, 2009, 02:01:07 pm »
Hi Roman,

I wrote an application which reads a lot of data (~6000 64Byte packages) from a HID device.
This is the code I use for HidAfterReceive:

procedure TForm1.HidAfterReceive(Com: TObject; Buffer: Pointer;
  Received: Cardinal);
var s : string;
    i : integer;
begin
  s := '';
  Inc(TeleCountr);

  for i := 0 to Received - 1 do
    s := s + PAnsiChar(Buffer);

  Incoming.Add(S);
  Edit1.Text := IntToStr(TeleCountr) + ' ' + StringToHex(s);
end;


incoming is a StringList where i want to add the receiving reports.
incoming and TeleCountr are global variables. 

If I move around the window while I receive data the receiving will stop on Vista (maybe on Win7, too).

If I use this code instead:
  s := 'HID Report is received: ' + IntToStr(Received) + ' bytes ';
  for i := 0 to Received - 1
    do s := s + IntToHex(Byte(PAnsiChar(Buffer)),2) + ' ';
  Memo1.Lines.Add(s);

all works fine. Do you have any idea what causes this problem ?

moelski

  • Full Member
  • ***
  • Posts: 122
    • View Profile
Thread problems ?
« Reply #1 on: September 03, 2009, 06:23:26 am »
Hi Roman,

yesterday I figured out that it is not a Vista / Win 7 Problem.
If I add the captured data in HidAfterReceive to an Edit:
Edit1.Text := IntToStr(TeleCountr) + ' ' + StringToHex(s);

then the data receivings hangs if I move the application at the desktop.

Is the receiving of data Thread based? And is it possible that HidAfterReceive is part of the thread?
This could explain the results I got ...

Hope on any information.

Greetz Dominik

hid1

  • Jr. Member
  • **
  • Posts: 66
    • View Profile
Re: Vista Problem with HidAfterReceive?
« Reply #2 on: September 03, 2009, 04:10:26 pm »
I'm sure, it is absoultely Thread based. and no problem with non visual usage.

Store received data in byte array or memory stream. and  use a timer for get data  to visual result. Will no problem.

ps:  Byte array or memory stream not variable of The Form. but belongs same unit (..Var section before implementation)





And question to Roman, nrHID SharedMode true or false, what is the advantage?
« Last Edit: September 03, 2009, 04:15:05 pm by hid1 »

Roman Novgorodov

  • Engineer
  • Administrator
  • Hero Member
  • *****
  • Posts: 994
  • we will win
    • View Profile
    • Forums.nrCommLib.Com
Re: Vista Problem with HidAfterReceive?
« Reply #3 on: September 09, 2009, 04:19:46 am »
Hello

Thank you for your information and I'm sorry if my answer is too late.

Yes, OnAfterReceive event is called by another thread (it is not main app thread)

You can accumulate needed data into buffer and refresh visial control from main thread by sending special windows messsaegs or by timer or by any other ways

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

  • Full Member
  • ***
  • Posts: 122
    • View Profile
Re: Vista Problem with HidAfterReceive?
« Reply #4 on: September 11, 2009, 04:20:19 am »
Hi Roman,

Quote
sending special windows messsaegs
Would it be possible to get a simple example?

I think it would also a good idea to add this into te HID Demo.

Greetz Dominik