Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Programmieren allgemein (https://www.delphipraxis.net/40-programmieren-allgemein/)
-   -   IsCheckedOut in der JvHidControllerClass (https://www.delphipraxis.net/165259-ischeckedout-der-jvhidcontrollerclass.html)

schwa226 20. Dez 2011 17:09

IsCheckedOut in der JvHidControllerClass
 
Hallo!

Da ich nicht weiterkomme muss ich hier mal nachfragen!

Ich arbeite mit einem HID USB Device.
In der OnArrival Methode vom JvHidDeviceController kommt nun beim Starten eins nach dem anderen Device rein.
Wenn nun meins dabei ist mache ich ein Checkout des Devices.

Delphi-Quellcode:
procedure TMainForm.OnArrival(HidDev: TJvHidDevice);
var
  i : integer;
begin
  if ((HidDev.Attributes.VendorID = VendorID) AND
    (HidDev.Attributes.ProductID = ProductID) AND
    (HidDev.ProductName = ProductName )) then
  begin

    //store device:
    HIDDevice := HidDev;
    //device found, lets do the init:
    if HIDDevice.CheckOut then
      begin
        //set feature type
        HIDDevice.ReportTypeParam := HidP_Feature;
        HIDDevice.UsagePageParam := HID_USAGE_PAGE_GENERIC;
        HIDDevice.LinkCollectionParam := $01; // CollectionType=Application
        HIDDevice.UsageParam := HID_USAGE_CONSUMER_UNDEFINED;
      end;
  end;
end;
Starte ich nun ein zweites mal meine Anwendung wird wieder ein Checkout ohne Probleme durchgeführt und das Device ist von beiden Anwendungen in Verwendung.

Das Problem ist jetzt, wenn ich zwei gleiche USB Devices angeschlossen haben werden beide geöffnet.
Das IsCheckedOut gilt nur für das eine Programm. Wie kann ich aber das Device als "belegt" markieren, damit die zweite Anwendung es nicht auch noch öffnet?

DonAlfredo 21. Dez 2011 12:44

AW: IsCheckedOut in der JvHidControllerClass
 
I hope you can read English ... my German writing is very bad ... !!

I have had the same problem.
An application with more than 10 identical USB-devices.

Normally, you could use the serial number of a device, but sometimes these are all similar.

I used the loaction of a device, on arrival.
Each USB device has a unique location: hub, port.

With this location, you can very reliable distinguish between devices !!
Two devices will NEVER have the same location.

Registry-entry: "SYSTEM\CurrentControlSet\Enum\USB\" ; LocationInformation.

You will need some extra code to use this method.

Good luck, Alfred.

schwa226 23. Dez 2011 08:14

AW: IsCheckedOut in der JvHidControllerClass
 
Thx for this tipp.

I also was testing it to identify the device by the serial number.
But I have a self programed AVR V-USB device. So I need to have different firmwares for different serial numbers.

The idea to take a look to the hub/port where the device is connected sounds good.

But anyway I will need to rewrite a lot of code because than I will need a list where I store the data of the device. Now I have only a single HIDDevice. I f the same device is getting plugged in the HIDDevice will be overwritten...

DonAlfredo 24. Dez 2011 06:51

AW: IsCheckedOut in der JvHidControllerClass
 
Well,

If you write your own firmware, this makes life easier.

I would advice against a different USB-serial.
This would mean special firmware for each device.
Which will be hard to maintain.

My suggestion:

Make use of a flag inside your USB-device.
Mark the device as being in use after arrival and checkout.
On arrival, check the in-use-flag of the device.
If in use, then skip (checkin), and go to the next one.



About your (correct) remark about the hub/port usage:
I maintain a list of devices inside the registry.
This list is checked on every device-arrival.


Alle Zeitangaben in WEZ +1. Es ist jetzt 02:19 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz