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

Vista Problem with HidAfterReceive?

Started by moelski, September 02, 2009, 11:01:07 am

Previous topic - Next topic

moelski

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

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

September 03, 2009, 01:10:26 pm #2 Last Edit: September 03, 2009, 01:15:05 pm by hid1
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?

Roman Novgorodov

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

Hi Roman,

Quotesending 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