Author Topic: Hid in service - MORE  (Read 1201 times)


  • Newbie
  • *
  • Posts: 15
    • View Profile
Hid in service - MORE
« on: February 09, 2012, 12:02:20 am »
Hi Roman,

Ok I got the 9.29 update and I have been working on a service demo program to connect with these scales.  I have a couple of questions.

First the way I have decided to try this is based on your response in my other thread.  I have a main TnrHID component.  I call update on that component.  I then have a routine that looks through the devices and identifies the scales from the other devices.  This all works great.  I can see the scales and the serial numbers.

What I then do is for each scale I create a small object.  Inside that object I have a TnrHID component created at runtime as the object is created.  I locate the scale I want for this device and select it using DeviceIndex on the private TnrHID.  I also set the OnAfterReceive to an event handler. I also store in the tag for the TnrHID the index of the object in a small array of objects.

Once I've located all my scales (currently 2 in this setup) I loop through the objects and for each that has a Hid component I tell it to go active.

My assumption was that each would be a thread since there is a thread priority.  I've set that to lowest since I don't need data all that fast.  However for one of the scales I get about 60 calls per second to OnAfterReceive.  The data is valid.  For the other scale (its Hid component is also active at the same time) I am not getting any calls.

This brings me to my first question.  I assume it is ok to have multiple TnrHID components each in active state on a different device right?   If so then I must assume my second scale is not working or is configured wrong so I'll check that.

My second question is on the rate of OnAfterReceive calls.  I need to have 6 scales attached.  If my plan meets with your suggestions of having 6 small objects each with it's own Hid component in active state on a different device,  I really don't need data that quickly and the computer these will be connected to might be a busy computer.  Is there anyway to slow down the data rate?  IE if I got 3 calls a second I'd be happy.  What happens if I were to put a sleep in the OnAfterReceive call?

Anyway please verify that my plan of using 6 Hid components in active state is valid.  Or please suggest a better way to read all scales.  I had considered just using 1 Hid component and changing the device index, going active for a period of time, then deactive and changing to the next scale.  What would be the best way?


Roman Novgorodov

  • Engineer
  • Administrator
  • Hero Member
  • *****
  • Posts: 1008
  • we will win
    • View Profile
    • Forums.nrCommLib.Com
Re: Hid in service - MORE
« Reply #1 on: February 16, 2012, 05:00:55 pm »

You need to create an one instance of TnrHid for every monitored HID device at runtime.
Every copy of TnrHid will create separated internal thread for monitor incoming data and call even handlers.

To change DeviceIndex and Active is not good idea, you can miss data.

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