本文整理汇总了Java中org.usb4java.LibUsb.getDeviceDescriptor方法的典型用法代码示例。如果您正苦于以下问题:Java LibUsb.getDeviceDescriptor方法的具体用法?Java LibUsb.getDeviceDescriptor怎么用?Java LibUsb.getDeviceDescriptor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.usb4java.LibUsb
的用法示例。
在下文中一共展示了LibUsb.getDeviceDescriptor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findDevice
import org.usb4java.LibUsb; //导入方法依赖的package包/类
public Device findDevice(short vendorId, short productId) {
// Read the USB device list
DeviceList list = new DeviceList();
int result = LibUsb.getDeviceList(null, list);
if (result < 0) throw new LibUsbException("Unable to get device list", result);
try {
// Iterate over all devices and scan for the right one
for (Device device: list) {
DeviceDescriptor descriptor = new DeviceDescriptor();
result = LibUsb.getDeviceDescriptor(device, descriptor);
if (result != LibUsb.SUCCESS) throw new LibUsbException("Unable to read device descriptor", result);
if (descriptor.idVendor() == vendorId && descriptor.idProduct() == productId) return device;
}
} finally {
// Ensure the allocated device list is freed
LibUsb.freeDeviceList(list, true);
}
// Device not found
return null;
}
示例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: findAllDevices
import org.usb4java.LibUsb; //导入方法依赖的package包/类
/**
* List all Devices on the Computer with a specific vid and pid value
*
* @param vid short
* @param pid short
* @return Vector<Device>
* @author yassir
*/
private Vector<Device> findAllDevices(short vid, short pid) {
Vector<Device> v_dev = new Vector<Device>();
try {
// Iterate over all devices and scan for the right one
for (Device device : allDevices) {
DeviceDescriptor descriptor = new DeviceDescriptor();
int result = LibUsb.getDeviceDescriptor(device, descriptor);
if (result != LibUsb.SUCCESS)
throw new LibUsbException(
"Unable to read device descriptor", result);
if (descriptor.idVendor() == vid
&& descriptor.idProduct() == pid)
v_dev.add(device); // return device;
}
} catch (Exception e) {
e.printStackTrace();
}
return v_dev;
}
示例4: dumpDaplugWinUSB
import org.usb4java.LibUsb; //导入方法依赖的package包/类
/**
* Get All informations and print it to screen form a specific Device
* @param device Device
* @return String
* @author yassir
*/
public static String dumpDaplugWinUSB(Device device) {
DeviceDescriptor des = new DeviceDescriptor();
LibUsb.getDeviceDescriptor(device, des);
String res = " vid : " + des.idVendor()
+ "\n pid : " + des.idProduct()
+ "\n Manufacturer : " + des.iManufacturer()
+ "\n bcdevice : " + des.bcdDevice()
+ "\n bcdUSB : " + des.bcdUSB()
+ "\n serial : " + des.iSerialNumber()
+ "\n bDescriptorType : " + des.bDescriptorType()
+ "\n bDeviceClass : " + des.bDeviceClass()
+ "\n bDeviceProtocol : " + des.bDeviceProtocol()
+ "\n bDeviceSubClass : " + des.bDeviceSubClass()
+ "\n bLength : " + des.bLength()
+ "\n bMaxPacketSize0 : " + des.bMaxPacketSize0()
+ "\n bNumConfigurations : " + des.bNumConfigurations()
+ "\n getBuffer : " + des.getBuffer()
+ "\n getPointer : " + device.getPointer()
+ "\n hashCode : " + des.hashCode();
return res;
}
示例5: getPath
import org.usb4java.LibUsb; //导入方法依赖的package包/类
/**
* Create List all Device with their path. It's an other way to list devices by their path.
* Please Notice that this path is something created specifically for this case.
*
* @return Vector<String> List of all device path
* @author yassir
*/
public Vector<String> getPath() {
Vector<String> v_res = new Vector<String>();
for(Device device : allDevices) {
DeviceDescriptor des = new DeviceDescriptor();
LibUsb.getDeviceDescriptor(device, des);
int i = 0;
if (PRODUCT_ID == des.idProduct() && VENDOR_ID == des.idVendor()) {
StringBuilder sb = new StringBuilder();
sb.append("Dongle ").append(i).append(",WINUSB").append(",").append(device.getPointer()).append(",").append("Plug-up");
v_res.addElement(sb.toString());
i++;
}
}
return v_res;
}
示例6: openDaplugWinusb
import org.usb4java.LibUsb; //导入方法依赖的package包/类
/**
* Open DaplugDongle with a specific vendor_id and product_id
* @param vid short the product vendor_id
* @param pid short the product product_id
* @return Vector<String> open Daplug Dongle
* @author yassir
*/
private Vector<Device> openDaplugWinusb(short vid, short pid) {
Vector<Device> v_dev = new Vector<Device>();
for (Device device : allDevices) {
DeviceDescriptor descriptor = new DeviceDescriptor();
int result = LibUsb.getDeviceDescriptor(device, descriptor);
if (result != LibUsb.SUCCESS)
throw new LibUsbException(
"Unable to read device descriptor", result);
if (descriptor.idVendor() == vid
&& descriptor.idProduct() == pid) {
v_dev.add(device);
}
}
return v_dev;
}
示例7: getDevices
import org.usb4java.LibUsb; //导入方法依赖的package包/类
public Device[] getDevices(int vendor_id, int product_id){
DeviceList usb_device_list = new DeviceList();
int result = LibUsb.getDeviceList(context, usb_device_list);
if (result < 0){
throw new LibUsbException("Unable to get device list", result);
}
ArrayList<Device> ps3_device_list = new ArrayList<Device>();
try {
for (Device usb_device : usb_device_list) {
DeviceDescriptor descriptor = new DeviceDescriptor();
result = LibUsb.getDeviceDescriptor(usb_device, descriptor);
if (result != LibUsb.SUCCESS){
throw new LibUsbException("Unable to read device descriptor", result);
}
if(descriptor.idVendor() == vendor_id && descriptor.idProduct() == product_id){
DeviceHandle handle = new DeviceHandle();
result = LibUsb.open(usb_device, handle);
if (result != LibUsb.SUCCESS){
throw new LibUsbException("Unable to open USB device", result);
}
LibUsb.close(handle);
LibUsb.refDevice(usb_device);
ps3_device_list.add(usb_device);
}
}
} finally {
LibUsb.freeDeviceList(usb_device_list, true);
}
return ps3_device_list.toArray(new Device[ps3_device_list.size()]);
}
示例8: buildCompatibleDevicesList
import org.usb4java.LibUsb; //导入方法依赖的package包/类
private List<Device> buildCompatibleDevicesList() {
final List<Device> compatibleDevicesListLocal = new ArrayList<>();
final DeviceList devList = new DeviceList();
LibUsb.getDeviceList(null, devList);
final DeviceDescriptor devDesc = new DeviceDescriptor();
for (final Device dev : devList) {
LibUsb.getDeviceDescriptor(dev, devDesc);
final ImmutablePair<Short, Short> vidPid = new ImmutablePair<>(devDesc.idVendor(), devDesc.idProduct());
// Check that the device is not already bound to any other driver.
final DeviceHandle devHandle = new DeviceHandle();
int status = LibUsb.open(dev, devHandle);
if (status != LibUsb.SUCCESS) {
continue; // Skip device.
}
status = LibUsb.kernelDriverActive(devHandle, 0);
LibUsb.close(devHandle);
if (((status == LibUsb.ERROR_NOT_SUPPORTED) || (status == LibUsb.SUCCESS))
&& vidPidToClassMap.containsKey(vidPid)) {
// This is a VID/PID combination we support, so let's add the
// device to the compatible
// devices list and increase its reference count.
compatibleDevicesListLocal.add(LibUsb.refDevice(dev));
}
}
LibUsb.freeDeviceList(devList, true);
return compatibleDevicesListLocal;
}
示例9: buildCompatibleDevicesList
import org.usb4java.LibUsb; //导入方法依赖的package包/类
private List<Device> buildCompatibleDevicesList() {
final List<Device> compatibleDevicesListLocal = new ArrayList<>();
final DeviceList devList = new DeviceList();
LibUsb.getDeviceList(null, devList);
final DeviceDescriptor devDesc = new DeviceDescriptor();
for (final Device dev : devList) {
LibUsb.getDeviceDescriptor(dev, devDesc);
final ImmutablePair<Short, Short> vidPid = new ImmutablePair<>(devDesc.idVendor(), devDesc.idProduct());
// Check that the device is not already bound to any other driver.
final DeviceHandle devHandle = new DeviceHandle();
int status = LibUsb.open(dev, devHandle);
if (status != LibUsb.SUCCESS) {
continue; // Skip device.
}
status = LibUsb.kernelDriverActive(devHandle, 0);
LibUsb.close(devHandle);
if (((status == LibUsb.ERROR_NOT_SUPPORTED) || (status == LibUsb.SUCCESS)) && vidPidToClassMap.containsKey(vidPid)) {
// This is a VID/PID combination we support, so let's add the
// device to the compatible
// devices list and increase its reference count.
compatibleDevicesListLocal.add(LibUsb.refDevice(dev));
}
}
LibUsb.freeDeviceList(devList, true);
return compatibleDevicesListLocal;
}
示例10: getDevicesList
import org.usb4java.LibUsb; //导入方法依赖的package包/类
private static List<UsbDevice> getDevicesList() {
final List<UsbDevice> usbDevices = new ArrayList<>();
final DeviceList list = new DeviceList();
if (LibUsb.getDeviceList(null, list) > 0) {
final Iterator<Device> devices = list.iterator();
while (devices.hasNext()) {
final Device dev = devices.next();
final DeviceDescriptor devDesc = new DeviceDescriptor();
LibUsb.getDeviceDescriptor(dev, devDesc);
if (Flashy.supportedVidPids.containsKey(devDesc.idVendor())) {
final Map<Short, Class<? extends Controller>> pids = Flashy.supportedVidPids
.get(devDesc.idVendor());
if (pids.containsKey(devDesc.idProduct())) {
usbDevices.add(new UsbDevice(dev));
}
}
}
LibUsb.freeDeviceList(list, true);
}
return (usbDevices);
}
示例11: 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);
}
示例12: findYubikey
import org.usb4java.LibUsb; //导入方法依赖的package包/类
/**
* Searches for the yubikey device and returns it. If there are
* multiple yubikeys attached then this simple demo only returns
* the first one.
*
* @return The yubikey USB device or null if not found.
*/
public static Device findYubikey(short[] pids){
// Read the USB device list
DeviceList list = new DeviceList();
int result = LibUsb.getDeviceList(null, list);
if (result < 0){
throw new RuntimeException("Unable to get device list. Result=" + result);
}
try{
// Iterate over all devices and scan for the missile launcher
for (Device device: list){
DeviceDescriptor descriptor = new DeviceDescriptor();
result = LibUsb.getDeviceDescriptor(device, descriptor);
debug(descriptor.dump());
if (result < 0){
throw new RuntimeException("Unable to read device descriptor. Result=" + result);
}
if (descriptor.idVendor() == VENDOR_ID && contains(pids, descriptor.idProduct())) {
debug("Found device:"+device.toString());
return device;
}
}
}
finally{
// Ensure the allocated device list is freed
//LibUsb.freeDeviceList(list, true);
LibUsb.freeDeviceList(list, false);
}
// No yubikey found
return null;
}
示例13: processEvent
import org.usb4java.LibUsb; //导入方法依赖的package包/类
@Override
public int processEvent(Context context, Device device, int event,
Object userData)
{
DeviceDescriptor descriptor = new DeviceDescriptor();
int result = LibUsb.getDeviceDescriptor(device, descriptor);
if (result != LibUsb.SUCCESS)
throw new LibUsbException("Unable to read device descriptor",
result);
System.out.format("%s: %04x:%04x%n",
event == LibUsb.HOTPLUG_EVENT_DEVICE_ARRIVED ? "Connected" :
"Disconnected",
descriptor.idVendor(), descriptor.idProduct());
return 0;
}
示例14: findMissileLauncher
import org.usb4java.LibUsb; //导入方法依赖的package包/类
/**
* Searches for the missile launcher device and returns it. If there are
* multiple missile launchers attached then this simple demo only returns
* the first one.
*
* @return The missile launcher USB device or null if not found.
*/
public static Device findMissileLauncher()
{
// Read the USB device list
DeviceList list = new DeviceList();
int result = LibUsb.getDeviceList(null, list);
if (result < 0)
{
throw new RuntimeException(
"Unable to get device list. Result=" + result);
}
try
{
// Iterate over all devices and scan for the missile launcher
for (Device device: list)
{
DeviceDescriptor descriptor = new DeviceDescriptor();
result = LibUsb.getDeviceDescriptor(device, descriptor);
if (result < 0)
{
throw new RuntimeException(
"Unable to read device descriptor. Result=" + result);
}
if (descriptor.idVendor() == VENDOR_ID
&& descriptor.idProduct() == PRODUCT_ID) return device;
}
}
finally
{
// Ensure the allocated device list is freed
LibUsb.freeDeviceList(list, true);
}
// No missile launcher found
return null;
}
示例15: processEvent
import org.usb4java.LibUsb; //导入方法依赖的package包/类
@Override
public int processEvent(Context context, Device device, int event,
Object userData) {
DeviceDescriptor descriptor = new DeviceDescriptor();
int result = LibUsb.getDeviceDescriptor(device, descriptor);
if (result != LibUsb.SUCCESS) {
throw new LibUsbException("Unable to read device descriptor",
result);
}
Keyboard.KeyboardModel[] keyboardModel = Keyboard.getKeyboardModel();
if ((keyboardModel.length > 1) || (keyboardModel[0] != Keyboard.KeyboardModel.NoLogiKeyboard)) { //check if there is any keyboard connected
if ((event == LibUsb.HOTPLUG_EVENT_DEVICE_ARRIVED) && (descriptor.idVendor() == 0x046d)
&& Arrays.asList(keyboardsProductNumbers).contains(String.format("%04x", descriptor.idProduct()))) {
System.out.format("%s: %04x:%04x%n",
event == LibUsb.HOTPLUG_EVENT_DEVICE_ARRIVED
? "Connected" : "Disconnected",
descriptor.idVendor(), descriptor.idProduct());
if (keyboardModel.length > 1) {
//display dialog msg to indicate that program only supports one keyboard connected at a time
System.err.println("Only one keyboard is allowed at a time.");
return 0;
}
if (usbCurrently.equals("unplugged")) {
usbCurrently = "plugged";
if (status.equals("Running")) {
switch (keyboardModel[0]) {
case Logi910Spectrum:
case Logi910Spark:
case Logi810Spectrum:
case Logi610Orion:
case Logi410AtlasSpectrum:
LogiGSKService.gKeyboard = new GKeyboard(keyboardModel[0]);
LogiGSKService.gKeyboard = IOOperations.loadCurrentKeyboardObjectFromFile(keyboardModel[0]);
if (LogiGSKService.gKeyboard.getEffect() != null) {
resetEffect();
} else {
loadColoursToPhysicalKeyboard(gKeyboard.getKeyColourMap());
}
break;
case NoLogiKeyboard:
break;
default:
break;
}
}
}
}
} else if ((event == LibUsb.HOTPLUG_EVENT_DEVICE_LEFT) && (keyboardModel.length == 1) && (keyboardModel[0] == Keyboard.KeyboardModel.NoLogiKeyboard)) {
usbCurrently = "unplugged";
stopGKeyboardEffects();
} else if ((keyboardModel.length == 1) && (keyboardModel[0] == Keyboard.KeyboardModel.NoLogiKeyboard)) {
usbCurrently = "unplugged";
System.out.println("No connected Keyboard");
stopGKeyboardEffects();
}
return 0;
}