Code Monkey home page Code Monkey logo

Comments (4)

siochs avatar siochs commented on July 19, 2024

Additional info:
I looked a bit into Usb4Java and was able to retrieve the physical path with the following code:

                        ByteBuffer path = BufferUtils.allocateByteBuffer(8);
                        result = LibUsb.getPortNumbers(device, path);
                        if (result > 0)
                        {
                            for (int i = 0; i < result; i++)
                            {                                
                                System.out.print(path.get(i));
                                if (i + 1 < result) System.out.print("-");
                            }
                            System.out.println("");
                        }                        

So when attaching a thumb drive between two different usb jacks it prints me for example 1-2 or 1-4.
It took a look into getPortNumbers(device, path); which dervies from libusb_get_port_numbers from LibUsb core.c. Basically, libusb_get_port_numbers does nothing elese then descending the device tree and places the according port number in a byte array:

...
		port_numbers[i] = dev->port_number;
		dev = dev->parent_dev;
...

Then, I tried to mimick that behaviour with Usb4Java-Javax:

        UsbPort port = usbDevice.getParentUsbPort();
        while (port != null)
        {
            System.out.print(port.getPortNumber());
            port = port.getUsbHub().getParentUsbPort();
            if (port != null) System.out.print("-");
        }

However, this does not work as expected since this allways gives me 1-2, independet of the port I attach the thumb drive to. Is this a bug or do I oversee something?

from usb4java-javax.

Andrei-Pozolotin avatar Andrei-Pozolotin commented on July 19, 2024

perhaps it is easier to hack around package/protected name space and cast
UsbDevice -> AbstractDevice to get access to bus/addr/port triple from DeviceId

see:

from usb4java-javax.

siochs avatar siochs commented on July 19, 2024

Yeah, this is what I ended up with. I added an Usb4JavaJavaxLibraryWrapper as part of the package org.usb4java.javax and wrote some casting functions like

public int getBusNumberFromUsbDevice(UsbDevice usbDevice)
    {
        DeviceId deviceId = ((AbstractDevice) usbDevice).getId();
        return deviceId.getBusNumber();        
    }

from usb4java-javax.

kayahr avatar kayahr commented on July 19, 2024

Changing the visibility of classes or methods is not an option here because this would break the compatibility to the javax.usb spec. But I guess this could be fixed properly by using the port numbers reported by libusb instead of creating virtual port numbers. I'm open for pull requests here because of lack of time and fading javax-usb knowledge.

from usb4java-javax.

Related Issues (14)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.