Author Topic: TnrHid always read from first device  (Read 921 times)

mschmelz

  • Newbie
  • *
  • Posts: 4
    • View Profile
TnrHid always read from first device
« on: December 05, 2013, 09:47:38 am »
Hi,
I use TnrHid to talk to my custom devices.
In my setup now, I  have 2 devices hooked to USB,
DeviceCount shows 2, DeviceIndexes are 3 and 4.
Now I want to send/receive data to the devices.
First , I set DeviceIndex to select the device ( here 3 or 4).
Then I use SendData command,
the returned data from device indicates  that I always read from  device with index 3.
What dio I have to do to really activate communication to other device ?
It seems setting DeviceIndex is not enough....

Thanks for any hint !
MIchael


Roman Novgorodov

  • Engineer
  • Administrator
  • Hero Member
  • *****
  • Posts: 994
  • we will win
    • View Profile
    • Forums.nrCommLib.Com
Re: TnrHid always read from first device
« Reply #1 on: December 05, 2013, 11:58:11 am »
Hello

Hmmm....  I don't understand...

One instance of TnrHid Opens only one device that pointed by DeviceIndex property.
If you call SendData() it sends data to DeviceIndex device and
you see reply from DeviceIndex device in AfterReceive event.
You can not see reply from anything else in AfterReceive event.

If you want to change DeviceIndex you need reopen hid device.

How do you see that reply from something else DeviceIndex?

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.

mschmelz

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: TnrHid always read from first device
« Reply #2 on: December 06, 2013, 07:02:49 am »
Hi, thanks for your first answer.

I do 2 steps, first I list all devices and put my custom devices in list:

Int32 TLog32Hid::GetCount()
{   /// scan USB bus for HID devies with this VID/PID
   Int32 i;
   Hid->Update();
   memset(FList,0,64*sizeof(Int32));
   FCount=0;
   for(i=0;i<Hid->DeviceCount;i++)
   { // check all entries
      Hid->DeviceIndex=i;
      if((Hid->HidDevice->VendorId==FVid)&&(Hid->HidDevice->ProductId==FPid))
         FList[FCount++]=i;
   }
   return FCount;
}



This works very nice, I can select each device and get VID and PID to select my deivces.

Next I want to select on device to talk  to:

Hid->DeviceIndex=...(valid index)
Hid->Active=true;
Hid->SendData(... (something)



Communication works for the first device selected.

But if I try this second time to select other Device,no change,
still the first selected device responds.

Which commands do I have to issue to connect to other Device ?


Roman Novgorodov

  • Engineer
  • Administrator
  • Hero Member
  • *****
  • Posts: 994
  • we will win
    • View Profile
    • Forums.nrCommLib.Com
Re: TnrHid always read from first device
« Reply #3 on: December 06, 2013, 10:22:14 am »
Hello

Please try HIDDemo, select correct device from list combo edit  and try to send data and see reply in log
Does it works correct?

Also you can try to Close device before change DeviceIndex

Code: [Select]
Hid->Active=false;
Hid->DeviceIndex=...(valid index)
Hid->Active=true;
nrHid1.HidDevice.Xxxx // also you can check selected device VENDORID and etc ehere in debut output....
Hid->SendData(... (something)

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.