TnrHid always read from first device

Started by mschmelz, December 05, 2013, 08:47:38 am

Previous topic - Next topic

mschmelz

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

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

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

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


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.