首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Usb4java备用设置

Usb4java备用设置
EN

Stack Overflow用户
提问于 2014-07-22 15:17:58
回答 1查看 714关注 0票数 2

它有一个活动配置,该配置有一个接口。

默认情况下,IDLE处于活动状态。

我的问题是,我如何才能激活PROF2设置?

代码语言:javascript
复制
bNumConfigurations:   0x01
bNumInterfaces:       0x01

[IDLE]
bInterfaceNumber:     0x00
bAlternateSetting:    0x00

[PROF1]
bInterfaceNumber:     0x00
bAlternateSetting:    0x01

[PROF2]
bInterfaceNumber:     0x00
bAlternateSetting:    0x02

代码...

代码语言:javascript
复制
UsbConfiguration config = (UsbConfiguration) device.getActiveUsbConfiguration();    
UsbInterface iface = config.getUsbInterface((byte)0x00);    
UsbInterface alt = iface.getSetting((byte)0x02);                // <= Setting is not active.
UsbEndpoint endpoint = alt.getUsbEndpoint((byte)0x83);    
UsbPipe pipe = endpoint.getUsbPipe();    
pipe.open();                                                    // <= Pipe is not active.
EN

回答 1

Stack Overflow用户

发布于 2016-03-02 13:23:05

我认为这里的问题在于,高级API根本没有提供一种方法来将活动配置或备用设置设置为默认设置以外的其他设置。

不过,低级API会...下面是我的用法::

代码语言:javascript
复制
// Iterate over the devices using low-level API to match a device + config combo from a high-level API
DeviceList list = new DeviceList();
LibUsb.getDeviceList(null, list);
for (Device d : list) {
    DeviceDescriptor descriptor = new DeviceDescriptor();
    LibUsb.getDeviceDescriptor(d, descriptor);
    if (descriptor.idVendor() == device.getUsbDeviceDescriptor().idVendor() &&
            descriptor.idProduct() == device.getUsbDeviceDescriptor().idProduct()) {
        Context context = new Context();
        LibUsb.init(context);
        DeviceHandle handle = new DeviceHandle();
        LibUsb.open(d, handle);
        LibUsb.setConfiguration(handle, 0x02); // or cfg.getUsbConfigurationDescriptor().bConfigurationValue()
        LibUsb.setInterfaceAltSetting(handle, 0x00, 0x02);
        LibUsb.claimInterface(handle, ifc);    // valid test, can't claim unless active
        LibUsb.releaseInterface(handle, ifc);
        LibUsb.close(handle);
        LibUsb.exit(context);
        return; // break, etc
    }
}
LibUsb.freeDeviceList(list, true); // usually in a finally block

当放置在助手函数中时,此逻辑应该对设置活动配置有效。

根据libusb开发人员的说法,只要设备没有拔出,配置就会保持活动状态。这是per https://github.com/libusb/libusb/issues/158#issuecomment-190501281

最后,如果您还没有这样做,我建议您通过命令行LIBUSB_DEBUG=4设置DEBUG,以从libusb获得原始输出。这对我的故障排除工作有很大帮助。在这种情况下,您应该会看到类似以下内容:

代码语言:javascript
复制
[21.987087] [0000d903] libusb: debug [libusb_set_configuration] configuration 2
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24881120

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档