Update of /cvsroot/javax-usb/javax-usb-libusb/src/com/mcreations/usb/windows
In directory sc8-pr-cvs17.sourceforge.net:/tmp/cvs-serv350
Modified Files:
WindowsDeviceOsImp.java
Log Message:
changed sendRequest so that set reports work by adding further checking on bmRequest. Also when sending a control out, the wLength arg is now correctly sent
Index: WindowsDeviceOsImp.java
===================================================================
RCS file: /cvsroot/javax-usb/javax-usb-libusb/src/com/mcreations/usb/windows/WindowsDeviceOsImp.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** WindowsDeviceOsImp.java 5 Aug 2008 16:26:51 -0000 1.2
--- WindowsDeviceOsImp.java 7 Aug 2008 14:35:10 -0000 1.3
***************
*** 18,21 ****
--- 18,22 ----
import javax.usb.UsbDisconnectedException;
import javax.usb.UsbException;
+ import javax.usb.util.UsbUtil;
import net.sf.libusb.Libusb;
***************
*** 129,134 ****
throws UsbException
{
- if(log.isDebugEnabled())log.debug("syncSubmit() sending an irp" );
-
sendRequest(irp);
--- 130,133 ----
***************
*** 163,183 ****
{
// set configuration has its own libusb method
! if (cIrp.bRequest() == UsbConst.REQUEST_SET_CONFIGURATION)
{
! Libusb.usb_set_configuration(
! getHandle(),
! cIrp.wValue());
!
return;
}
! // FIXME timeout value hard-coded
! // int result = Libusb.usb_control_msg(handle,cIrp.bmRequestType(),cIrp.bRequest(),
! // cIrp.wValue(),cIrp.wIndex(),cIrp.getData(),5000);
! int result = Libusb.usb_control_msg(handle,cIrp.bmRequestType(),cIrp.bRequest(),
! cIrp.wValue(),cIrp.wIndex(),cIrp.getData(),JavaxUsb.getIoTimeout());
! cIrp.setActualLength(result);
! if(log.isDebugEnabled()) log.debug( "sendRequest() Libusb.usb_control_msg returned "+result);
}
finally
--- 162,201 ----
{
// set configuration has its own libusb method
! if( (cIrp.bRequest() == UsbConst.REQUEST_SET_CONFIGURATION) && (cIrp.bmRequestType() ==0) )
{
! Libusb.usb_set_configuration( getHandle(),cIrp.wValue());
return;
}
! byte[] data = cIrp.getData();
! if( (cIrp.bmRequestType() & UsbConst.REQUESTTYPE_DIRECTION_MASK) == UsbConst.REQUESTTYPE_DIRECTION_OUT)
! { // this patch is needed because cIrp.wLength is not used as the argument to usb_control_msg
! // for reads, this is ok as the transfer size is governed by the device,
! // but when sending data a specific length needs to be send
! // FIXME - generate a rule in the SWIG processing to allow control of the length argument
! if(log.isDebugEnabled()) log.debug("sendRequest() direction OUT Len: "+cIrp.wLength());
! byte[] data1 = cIrp.getData();
! data = new byte[cIrp.wLength()];
! for(int i =0;i<data.length;i++)
! {
! data[i]=data1[i];
! }
! }
+ if(log.isDebugEnabled()) log.debug( "sendRequest() bmRequestType: "+UsbUtil.toHexString(cIrp.bmRequestType())+
+ " bRequest: "+UsbUtil.toHexString(cIrp.bRequest())+
+ " wValue: "+UsbUtil.toHexString(cIrp.wValue())+
+ " wIndex: "+UsbUtil.toHexString(cIrp.wIndex())+
+ " wLength: "+UsbUtil.toHexString(cIrp.wLength()));
+
+ int result = Libusb.usb_control_msg(handle,cIrp.bmRequestType(),cIrp.bRequest(), cIrp.wValue(), cIrp.wIndex(),data ,JavaxUsb.getIoTimeout());
+ if(result >=0)
+ cIrp.setActualLength(result);
+ else
+ {
+ String msg = "usb_control_msg: " + Libusb.usb_strerror() +" errorno: " + result;
+ log.debug(msg);
+ throw new UsbException(msg);
+ }
}
finally
|