2014-07-22 7 views
2

USB를 통해 통신해야하는 장치가 있습니다.Usb4java 대체 설정

활성 구성이 1 개이며 인터페이스가 1 개입니다.

더 많은 대체 설정 (IDLE, PROF1, PROF2)이 인터페이스에 있습니다. 기본적으로 IDLE은 활성화되어 있습니다.

제 질문은, 어떻게 PROF2 설정을 활성화시킬 수 있습니까?

bNumConfigurations: 0x01 
bNumInterfaces:  0x01 

[IDLE] 
bInterfaceNumber:  0x00 
bAlternateSetting: 0x00 

[PROF1] 
bInterfaceNumber:  0x00 
bAlternateSetting: 0x01 

[PROF2] 
bInterfaceNumber:  0x00 
bAlternateSetting: 0x02 

코드 ...

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. 
+0

사용중인 라이브러리를 알려 주시면 쉽게 알 수 있습니다. – Andy

+0

http://usb4java.org/ – robert

답변

2

여기 문제가 높은 수준의 API는 단순히 활성 구성 또는 다른 무언가로 대체 설정 중 하나를 설정하는 방법을 제공하지 않는다는 것입니다 생각 기본값보다.

낮은 수준의 API

하지만 ... 여기에 내가 무엇을 사용 ::

도우미 함수에 배치
// 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 devs에 따르면 장치가 분리되지 않은 한 구성이 활성 상태로 유지됩니다. 이것은 https://github.com/libusb/libusb/issues/158#issuecomment-190501281입니다.

마지막으로 아직 수행하지 않은 경우 에서 원시 출력을 얻으려면 명령 줄 LIBUSB_DEBUG=4을 통해 DEBUG를 설정하는 것이 좋습니다. 이것은 내 문제 해결 노력에 상당히 도움이되었습니다. 이 경우 다음 줄이 표시되어야합니다.

[21.987087] [0000d903] libusb: debug [libusb_set_configuration] configuration 2