void ClientUSBInDataEndpoint::Shutdown() { Disconnect(); xnUSBCloseEndPoint(m_hEndpoint); m_hEndpoint = NULL; m_hUSBDevice = NULL; }
XnStatus XnSensorIO::CloseDevice() { XnStatus nRetVal; xnLogVerbose(XN_MASK_DEVICE_SENSOR, "Shutting down USB depth read thread..."); xnUSBShutdownReadThread(m_pSensorHandle->DepthConnection.UsbEp); if (m_pSensorHandle->DepthConnection.UsbEp != NULL) { nRetVal = xnUSBCloseEndPoint(m_pSensorHandle->DepthConnection.UsbEp); XN_IS_STATUS_OK(nRetVal); m_pSensorHandle->DepthConnection.UsbEp = NULL; } xnLogVerbose(XN_MASK_DEVICE_SENSOR, "Shutting down USB image read thread..."); xnUSBShutdownReadThread(m_pSensorHandle->ImageConnection.UsbEp); if (m_pSensorHandle->ImageConnection.UsbEp != NULL) { nRetVal = xnUSBCloseEndPoint(m_pSensorHandle->ImageConnection.UsbEp); XN_IS_STATUS_OK(nRetVal); m_pSensorHandle->ImageConnection.UsbEp = NULL; } if (m_pSensorHandle->MiscConnection.bIsOpen) { xnLogVerbose(XN_MASK_DEVICE_SENSOR, "Shutting down USB misc read thread..."); xnUSBShutdownReadThread(m_pSensorHandle->MiscConnection.UsbEp); if (m_pSensorHandle->MiscConnection.UsbEp != NULL) { nRetVal = xnUSBCloseEndPoint(m_pSensorHandle->MiscConnection.UsbEp); XN_IS_STATUS_OK(nRetVal); m_pSensorHandle->MiscConnection.UsbEp = NULL; } } if (m_pSensorHandle->ControlConnection.bIsBulk) { if (m_pSensorHandle->ControlConnection.ControlInConnectionEp != NULL) { nRetVal = xnUSBCloseEndPoint(m_pSensorHandle->ControlConnection.ControlInConnectionEp); XN_IS_STATUS_OK(nRetVal); m_pSensorHandle->ControlConnection.ControlInConnectionEp = NULL; } if (m_pSensorHandle->ControlConnection.ControlOutConnectionEp != NULL) { nRetVal = xnUSBCloseEndPoint(m_pSensorHandle->ControlConnection.ControlOutConnectionEp); XN_IS_STATUS_OK(nRetVal); m_pSensorHandle->ControlConnection.ControlOutConnectionEp = NULL; } } if (m_pSensorHandle->USBDevice != NULL) { nRetVal = xnUSBCloseDevice(m_pSensorHandle->USBDevice); XN_IS_STATUS_OK(nRetVal); m_pSensorHandle->USBDevice = NULL; } xnLogVerbose(XN_MASK_DEVICE_SENSOR, "Device closed successfully"); // All is good... return (XN_STATUS_OK); }
XnStatus XnSensorIO::OpenDevice(const XnChar* strPath, XnBool bLeanInit) { XnStatus nRetVal; XnUSBDeviceSpeed DevSpeed; xnLogVerbose(XN_MASK_DEVICE_IO, "Connecting to USB device..."); // try to open the device xnLogVerbose(XN_MASK_DEVICE_IO, "Trying to open sensor '%s'...", strPath); nRetVal = xnUSBOpenDeviceByPath(strPath, &m_pSensorHandle->USBDevice); XN_IS_STATUS_OK(nRetVal); if (!bLeanInit) { nRetVal = xnUSBGetDeviceSpeed(m_pSensorHandle->USBDevice, &DevSpeed); XN_IS_STATUS_OK(nRetVal); if (DevSpeed != XN_USB_DEVICE_HIGH_SPEED) { XN_LOG_WARNING_RETURN(XN_STATUS_USB_UNKNOWN_DEVICE_SPEED, XN_MASK_DEVICE_IO, "Device is not high speed!"); } } // on older firmwares, control was sent over BULK endpoints. Check if this is the case xnLogVerbose(XN_MASK_DEVICE_IO, "Trying to open endpoint 0x4 for control out (for old firmwares)..."); nRetVal = xnUSBOpenEndPoint(m_pSensorHandle->USBDevice, 0x4, XN_USB_EP_BULK, XN_USB_DIRECTION_OUT, &m_pSensorHandle->ControlConnection.ControlOutConnectionEp); if (nRetVal == XN_STATUS_USB_ENDPOINT_NOT_FOUND || nRetVal == XN_STATUS_USB_WRONG_ENDPOINT_TYPE || nRetVal == XN_STATUS_USB_WRONG_ENDPOINT_DIRECTION) { // this is not the case. use regular control endpoint (0) m_pSensorHandle->ControlConnection.bIsBulk = FALSE; } else { XN_IS_STATUS_OK(nRetVal); xnLogVerbose(XN_MASK_DEVICE_IO, "Opening endpoint 0x85 for control in..."); nRetVal = xnUSBOpenEndPoint(m_pSensorHandle->USBDevice, 0x85, XN_USB_EP_BULK, XN_USB_DIRECTION_IN, &m_pSensorHandle->ControlConnection.ControlInConnectionEp); XN_IS_STATUS_OK(nRetVal); m_pSensorHandle->ControlConnection.bIsBulk = TRUE; } nRetVal = XnDeviceEnumeration::IsSensorLowBandwidth(strPath, &m_bIsLowBandwidth); XN_IS_STATUS_OK(nRetVal); xnLogInfo(XN_MASK_DEVICE_IO, "Connected to USB device%s", m_bIsLowBandwidth ? " (LowBand)" : ""); // check if we're currently on BULK interfaces or ISO ones XN_USB_EP_HANDLE hEP; nRetVal = xnUSBOpenEndPoint(m_pSensorHandle->USBDevice, 0x82, XN_USB_EP_BULK, XN_USB_DIRECTION_IN, &hEP); if (nRetVal == XN_STATUS_USB_WRONG_ENDPOINT_TYPE) { m_interface = XN_SENSOR_USB_INTERFACE_ISO_ENDPOINTS; } else { m_interface = XN_SENSOR_USB_INTERFACE_BULK_ENDPOINTS; xnUSBCloseEndPoint(hEP); } strcpy(m_strDeviceName, strPath); return XN_STATUS_OK; }