Comments (4)
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.
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.
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.
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)
- Operation not supported or unimplemented on this platform HOT 3
- usb4java stopped receiving usb events intermittently HOT 3
- javax.usb.UsbException: Pipe is still busy
- Threading
- Properties File not found
- Attached event is not received for the device that has lengthy serial number HOT 2
- Support for USB Isochronous Transfer mode
- Ignoring problematic device: javax.usb.UsbPlatformException: USB error 5: Can't open device Bus 001 Device 002: ID 0c45:64ce: Entity not found
- getActiveUsbConfiguration returns null
- Overflow while getting descriptors HOT 4
- High-level API introduces large and unpredictable performance penalty HOT 1
- Properties file javax.usb.properties not found error HOT 9
- Make package local classes public HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from usb4java-javax.