Skip to content

Commit

Permalink
adding pull req 34 (https://github.com/OpenNI/OpenNI/pulls) as it fixes
Browse files Browse the repository at this point in the history
a problem with the latest Sensor unstable where the USB interface cannot
be claimed if XnSensorServer is already running
  • Loading branch information
rbrusu committed Dec 29, 2012
1 parent 6680aa9 commit d80f5dc
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -13,7 +13,7 @@ endif

DISTRO=$(shell lsb_release -sc)

OPENNI_PACKAGE_NAME=ros-openni-dev-${OPENNI_VERSION}~${DISTRO}_$(ARCH)${BUILD_NUMBER}
OPENNI_PACKAGE_NAME=openni-dev-${OPENNI_VERSION}~${DISTRO}_$(ARCH)${BUILD_NUMBER}
OPENNI_REDISTNAME=OpenNI-Bin-Dev-Linux-${OPENNI_ARCH}-v${OPENNI_VERSION}

all: debian
Expand Down
46 changes: 41 additions & 5 deletions Source/OpenNI/Linux/XnUSBLinux.cpp
Expand Up @@ -36,8 +36,6 @@
#include <XnLog.h>
#include <XnOSCpp.h>
#include "XnListT.h"


//---------------------------------------------------------------------------
// Types
//---------------------------------------------------------------------------
Expand Down Expand Up @@ -151,7 +149,7 @@ XnStatus xnUSBAsynchThreadAddRef()
if (nRetVal != 0)
{
xnLogWarning(XN_MASK_USB, "USB events thread: Failed to set thread priority to critical. This might cause loss of data...");
printf("Warning: USB events thread - failed to set priority. This might cause loss of data...\n");
//printf("Warning: USB events thread - failed to set priority. This might cause loss of data...\n");
}
}

Expand Down Expand Up @@ -398,12 +396,50 @@ XN_C_API XnStatus xnUSBOpenDeviceImpl(libusb_device* pDevice, XN_USB_DEV_HANDLE*
libusb_close(handle);
return (XN_STATUS_USB_SET_CONFIG_FAILED);
}
*/
*/

// Asking the kernel politely to detach every other driver form this device.
// If other drivers or programs are attached to the interface, it cannot be claimed.
xnLogVerbose(XN_MASK_USB, "Detaching other kernel drivers.");
rc = libusb_detach_kernel_driver(handle, 0);
if (rc == 0)
{
xnLogWarning (XN_MASK_USB, "Detach success. Drivers detached.");
}
else if (rc == LIBUSB_ERROR_NOT_FOUND)
{
xnLogWarning (XN_MASK_USB, "Detach success. No drivers were attached.");
}
else if (rc == LIBUSB_ERROR_INVALID_PARAM)
{
XN_LOG_ERROR_RETURN (XN_STATUS_USB_SET_CONFIG_FAILED, XN_MASK_USB, "Detach kernel driver error. The specified interface does not exist.");
}
else if (rc == LIBUSB_ERROR_NO_DEVICE)
{
XN_LOG_ERROR_RETURN (XN_STATUS_USB_SET_CONFIG_FAILED, XN_MASK_USB, "Detach kernel driver error. Device is disconnectd.");
}
else
{
XN_LOG_ERROR_RETURN (XN_STATUS_USB_SET_CONFIG_FAILED, XN_MASK_USB, "Detach kernel driver error. Unknown error.");
}

xnLogVerbose(XN_MASK_USB, "Claiming the interface.");
// claim the interface (you cannot open any end point before claiming the interface)
rc = libusb_claim_interface(handle, 0);
if (rc != 0)
{
libusb_close(handle);
if (rc == LIBUSB_ERROR_NOT_FOUND)
xnLogError (XN_MASK_USB, "Interface claim failed: The specified interface does not exist.");
else if (rc == LIBUSB_ERROR_BUSY)
xnLogError (XN_MASK_USB, "Interface claim failed: Another program or driver has claimed the interface.");
else if (rc == LIBUSB_ERROR_NO_DEVICE)
xnLogError (XN_MASK_USB, "Interface claim failed: Device disconnected.");
else if (rc == LIBUSB_ERROR_OTHER)
xnLogError(XN_MASK_USB, "Interface claim failed: Other error.");
else
xnLogError(XN_MASK_USB, "Interface claim failed: Unknown error.");

libusb_close (handle);
return (XN_STATUS_USB_SET_INTERFACE_FAILED);
}

Expand Down

0 comments on commit d80f5dc

Please sign in to comment.