本文整理汇总了Java中org.usb4java.LibUsb.getBusNumber方法的典型用法代码示例。如果您正苦于以下问题:Java LibUsb.getBusNumber方法的具体用法?Java LibUsb.getBusNumber怎么用?Java LibUsb.getBusNumber使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.usb4java.LibUsb
的用法示例。
在下文中一共展示了LibUsb.getBusNumber方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getUSBAddress
import org.usb4java.LibUsb; //导入方法依赖的package包/类
/**
* USB address (bus/port)
*/
public String getUSBAddress()
{
if(mDevice != null)
{
StringBuilder sb = new StringBuilder();
sb.append("Bus:");
int bus = LibUsb.getBusNumber(mDevice);
sb.append(bus);
sb.append(" Port:");
int port = LibUsb.getPortNumber(mDevice);
sb.append(port);
return sb.toString();
}
return "UNKNOWN";
}
示例2: createId
import org.usb4java.LibUsb; //导入方法依赖的package包/类
/**
* Creates a device ID from the specified device.
*
* @param device
* The libusb device. Must not be null.
* @return The device id.
* @throws UsbPlatformException
* When device descriptor could not be read from the specified
* device.
*/
private DeviceId createId(final Device device) throws UsbPlatformException
{
if (device == null)
throw new IllegalArgumentException("device must be set");
final int busNumber = LibUsb.getBusNumber(device);
final int addressNumber = LibUsb.getDeviceAddress(device);
final int portNumber = LibUsb.getPortNumber(device);
final DeviceDescriptor deviceDescriptor = new DeviceDescriptor();
final int result = LibUsb.getDeviceDescriptor(device, deviceDescriptor);
if (result < 0)
{
throw ExceptionUtils.createPlatformException(
"Unable to get device descriptor for device " + addressNumber
+ " at bus " + busNumber, result);
}
return new DeviceId(busNumber, addressNumber, portNumber,
new SimpleUsbDeviceDescriptor(deviceDescriptor));
}
示例3: UsbDevice
import org.usb4java.LibUsb; //导入方法依赖的package包/类
public UsbDevice(final Device device) {
dev = LibUsb.refDevice(device);
devDesc = new DeviceDescriptor();
LibUsb.getDeviceDescriptor(dev, devDesc);
devVID = devDesc.idVendor();
devPID = devDesc.idProduct();
devDID = devDesc.bcdDevice();
busAddr = LibUsb.getBusNumber(dev);
devAddr = LibUsb.getDeviceAddress(dev);
}
示例4: main
import org.usb4java.LibUsb; //导入方法依赖的package包/类
/**
* Main method.
*
* @param args
* Command-line arguments (Ignored)
*/
public static void main(String[] args)
{
// Create the libusb context
Context context = new Context();
// Initialize the libusb context
int result = LibUsb.init(context);
if (result < 0)
{
throw new LibUsbException("Unable to initialize libusb", result);
}
// Read the USB device list
DeviceList list = new DeviceList();
result = LibUsb.getDeviceList(context, list);
if (result < 0)
{
throw new LibUsbException("Unable to get device list", result);
}
try
{
// Iterate over all devices and list them
for (Device device: list)
{
int address = LibUsb.getDeviceAddress(device);
int busNumber = LibUsb.getBusNumber(device);
DeviceDescriptor descriptor = new DeviceDescriptor();
result = LibUsb.getDeviceDescriptor(device, descriptor);
if (result < 0)
{
throw new LibUsbException(
"Unable to read device descriptor", result);
}
System.out.format(
"Bus %03d, Device %03d: Vendor %04x, Product %04x%n",
busNumber, address, descriptor.idVendor(),
descriptor.idProduct());
}
}
finally
{
// Ensure the allocated device list is freed
LibUsb.freeDeviceList(list, true);
}
// Deinitialize the libusb context
LibUsb.exit(context);
}
示例5: dumpDevice
import org.usb4java.LibUsb; //导入方法依赖的package包/类
/**
* Dumps the specified device to stdout.
*
* @param device
* The device to dump.
*/
public static void dumpDevice(final Device device)
{
// Dump device address and bus number
final int address = LibUsb.getDeviceAddress(device);
final int busNumber = LibUsb.getBusNumber(device);
System.out.println(String
.format("Device %03d/%03d", busNumber, address));
// Dump port number if available
final int portNumber = LibUsb.getPortNumber(device);
if (portNumber != 0)
System.out.println("Connected to port: " + portNumber);
// Dump parent device if available
final Device parent = LibUsb.getParent(device);
if (parent != null)
{
final int parentAddress = LibUsb.getDeviceAddress(parent);
final int parentBusNumber = LibUsb.getBusNumber(parent);
System.out.println(String.format("Parent: %03d/%03d",
parentBusNumber, parentAddress));
}
// Dump the device speed
System.out.println("Speed: "
+ DescriptorUtils.getSpeedName(LibUsb.getDeviceSpeed(device)));
// Read the device descriptor
final DeviceDescriptor descriptor = new DeviceDescriptor();
int result = LibUsb.getDeviceDescriptor(device, descriptor);
if (result < 0)
{
throw new LibUsbException("Unable to read device descriptor",
result);
}
// Try to open the device. This may fail because user has no
// permission to communicate with the device. This is not
// important for the dumps, we are just not able to resolve string
// descriptor numbers to strings in the descriptor dumps.
DeviceHandle handle = new DeviceHandle();
result = LibUsb.open(device, handle);
if (result < 0)
{
System.out.println(String.format("Unable to open device: %s. "
+ "Continuing without device handle.",
LibUsb.strError(result)));
handle = null;
}
// Dump the device descriptor
System.out.print(descriptor.dump(handle));
// Dump all configuration descriptors
dumpConfigurationDescriptors(device, descriptor.bNumConfigurations());
// Close the device if it was opened
if (handle != null)
{
LibUsb.close(handle);
}
}