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

nrHID memory stream problem.

Started by hid1, July 22, 2009, 06:21:36 am

Previous topic - Next topic

hid1

July 22, 2009, 06:21:36 am Last Edit: July 22, 2009, 06:24:01 am by hid1
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..
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
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?


Roman Novgorodov

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

Thank you for quick reply. No problem with code below.
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

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

July 22, 2009, 10:31:16 am #4 Last Edit: July 22, 2009, 10:43:41 am by hid1
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.

Quotei := nrHid1.DeviceIndex;
 nrHid1.WMDeviceChange(Msg);
 if i < nrHid1.DeviceCount then
 begin
   nrHid1.DeviceIndex := i;
 end;

Roman Novgorodov

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

hello ,   It works very well.  Thank you .