Author Topic: nrHID memory stream problem.  (Read 3219 times)

hid1

  • Jr. Member
  • **
  • Posts: 66
    • View Profile
nrHID memory stream problem.
« on: July 22, 2009, 09:21:36 am »
I have , custom made HID device. this  device sends byte stream to pc.
with another component and my application I can get data to memory stream . excellent result.

But I with  nrComm Lib VCL (Win32) HID component. data mising.

no problem with JvHidController..
Code: [Select]
procedure TMainForm.ShowRead(HidDev: TJvHidDevice; ReportID: Byte;
  const Data: Pointer; Size: Word);
begin

  ms.WriteBuffer(data^, size);

end;

But problem with  nrComm Lib VCL (Win32) HID component(latest) and this code
Code: [Select]
procedure TForm1.nrHid1AfterReceive(Com: TObject; Buffer: Pointer;
  Received: Cardinal);
var i :integer;
s:string;
begin
   ms.WriteBuffer(buffer^,Received);
end;

with nrComm HID, zero bytes added to memorystream, which broke device signal. every 1ms (= nrHid1AfterReceive event) adds 1 zero byte to the stream

Your suggestion?

« Last Edit: July 22, 2009, 09:24:01 am by hid1 »

Roman Novgorodov

  • Engineer
  • Administrator
  • Hero Member
  • *****
  • Posts: 994
  • we will win
    • View Profile
    • Forums.nrCommLib.Com
Re: nrHID memory stream problem.
« Reply #1 on: July 22, 2009, 09:50:22 am »
Hello

The first byte can be HID report ID.
It seems like JvHidController extracts this byte before call event.
TnrHid gives data as is.

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

hid1

  • Jr. Member
  • **
  • Posts: 66
    • View Profile
Re: nrHID memory stream problem.
« Reply #2 on: July 22, 2009, 10:06:24 am »
Thank you for quick reply. No problem with code below.
Code: [Select]
procedure TForm1.nrHid1AfterReceive(Com: TObject; Buffer: Pointer;
  Received: Cardinal);
var
  i: integer;
  s: string;
  t:tmemorystream;  //temp memorystream
begin
    t:=tmemorystream.Create;
    t.WriteBuffer(buffer^,Received);
    t.Position:=1;
    ms.CopyFrom(t,received-1);
    t.Free;
end;



I want to make  seperate thread to inform application about device "plugged"
this is possible without  this?
procedure WMDeviceChange(var Msg: TMessage); message WM_DEVICECHANGE;

Another mechanism which communicate HID services etc, can detect device plugged or removed?

I need it becouse, mouse detection etc excellent. but  my HID device detection slow. sometime cannot detect. I thought WMDeviceChange procedure cannot work for everytime ?

I wish HID only  component available from you. I  purchased license (yesterday) only for HID.


Thank you again


Roman Novgorodov

  • Engineer
  • Administrator
  • Hero Member
  • *****
  • Posts: 994
  • we will win
    • View Profile
    • Forums.nrCommLib.Com
Re: nrHID memory stream problem.
« Reply #3 on: July 22, 2009, 10:47:31 am »
Hello

Thank you for purchasing.

You can try to use another window handle (instead visible form) in Win32 system call RegisterDeviceNotification(...) http://msdn.microsoft.com/en-us/library/aa363431(VS.85).aspx.

But anyway you need handle a windows message. It is ordinary broadcast Windows notification about hardware changes.

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

hid1

  • Jr. Member
  • **
  • Posts: 66
    • View Profile
Re: nrHID memory stream problem.
« Reply #4 on: July 22, 2009, 01:31:16 pm »
Manual (or timered) refresh  nrHid  device list possible?  


without WMDeviceChange or RegisterDeviceNotification:
My device unplugged. Application starts. then device connect. But not shown on the list. so nrHid  cannot open it

Is it possible to manual (or timered) refresh   the list?

I think nrHid1.WMDeviceChange(Msg) may be enough. But I don't know what can I write for Msg;
WM_DEVICECHANGE not accepted.

Quote
 i := nrHid1.DeviceIndex;
  nrHid1.WMDeviceChange(Msg);
  if i < nrHid1.DeviceCount then
  begin
    nrHid1.DeviceIndex := i;
  end;
« Last Edit: July 22, 2009, 01:43:41 pm by hid1 »

Roman Novgorodov

  • Engineer
  • Administrator
  • Hero Member
  • *****
  • Posts: 994
  • we will win
    • View Profile
    • Forums.nrCommLib.Com
Re: nrHID memory stream problem.
« Reply #5 on: July 22, 2009, 02:02:25 pm »
Hello

The TnrHid.Update() method refreshes device list.

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

hid1

  • Jr. Member
  • **
  • Posts: 66
    • View Profile
Re: nrHID memory stream problem.
« Reply #6 on: July 22, 2009, 02:07:17 pm »
hello ,   It works very well.  Thank you .