XN_C_API XnStatus xnEnumerationErrorsToString(const XnEnumerationErrors* pErrors, XnChar* csBuffer, XnUInt32 nSize) { XnStatus nRetVal = XN_STATUS_OK; XnUInt32 nWritten = 0; csBuffer[0] = '\0'; nRetVal = xnOSStrAppend(csBuffer, "One or more of the following nodes could not be enumerated:\n\n", nSize); XN_IS_STATUS_OK(nRetVal); nWritten = xnOSStrLen(csBuffer); for (XnEnumerationErrorsIterator it = xnEnumerationErrorsGetFirst(pErrors); xnEnumerationErrorsIteratorIsValid(it); it = xnEnumerationErrorsGetNext(it)) { nRetVal = xnProductionNodeDescriptionToString(xnEnumerationErrorsGetCurrentDescription(it), csBuffer + nWritten, nSize - nWritten); XN_IS_STATUS_OK(nRetVal); nRetVal = xnOSStrAppend(csBuffer, ": ", nSize); XN_IS_STATUS_OK(nRetVal); nRetVal = xnOSStrAppend(csBuffer, xnGetStatusString(xnEnumerationErrorsGetCurrentError(it)), nSize); XN_IS_STATUS_OK(nRetVal); nRetVal = xnOSStrAppend(csBuffer, "\n", nSize); XN_IS_STATUS_OK(nRetVal); nWritten = xnOSStrLen(csBuffer); } return (XN_STATUS_OK); }
XnStatus XnSensorIO::IsSensorLowBandwidth(const XnConnectionString connectionString, XnBool* pbIsLowBandwidth) { XnConnectionString cpMatchString; *pbIsLowBandwidth = FALSE; #if (XN_PLATFORM == XN_PLATFORM_WIN32) // WAVI Detection: // Normal USB string: \\?\usb#vid_1d27&pid_0600#6&XXXXXXXX&0&2 // WAVI USB String: \\?\usb#vid_1d27&pid_0600#1&1d270600&2&3 // ^^^^^^^^ - VID/PID is always repeated here with the WAVI. // Regular USB devices will have the port/hub chain instead. if ((xnOSStrCaseCmp(connectionString, "\\\\?\\usb#vid_") >= 0) && (xnOSStrLen(connectionString) > 25)) { strncpy(&cpMatchString[0], &connectionString[12], 4); //VID strncpy(&cpMatchString[4], &connectionString[21], 4); //PID cpMatchString[8] = 0; if (strstr ((char*)connectionString,cpMatchString) != 0) { *pbIsLowBandwidth = TRUE; } } #endif return (XN_STATUS_OK); }
XnStatus FromElement(const TiXmlElement* pElement) { XnStatus nRetVal = XN_STATUS_OK; const XnChar* strVendor; nRetVal = xnXmlReadStringAttribute(pElement, XN_XML_LICENSE_VENDOR, &strVendor); XN_IS_STATUS_OK(nRetVal); const XnChar* strKey; nRetVal = xnXmlReadStringAttribute(pElement, XN_XML_LICENSE_KEY, &strKey); XN_IS_STATUS_OK(nRetVal); nRetVal = xnOSStrNCopy(this->strVendor, strVendor, xnOSStrLen(strVendor) + 1, sizeof(this->strVendor)); XN_IS_STATUS_OK(nRetVal); nRetVal = xnOSStrNCopy(this->strKey, strKey, xnOSStrLen(strKey) + 1, sizeof(this->strKey)); XN_IS_STATUS_OK(nRetVal); return (XN_STATUS_OK); }
void DeviceManager::EnumerateDevices() { XnStatus nRetVal = XN_STATUS_OK; xn::NodeInfoList deviceList; XnMapOutputMode mapMode; mapMode.nXRes = XN_VGA_X_RES; mapMode.nYRes = XN_VGA_Y_RES; mapMode.nFPS = 30; nRetVal = context_->EnumerateProductionTrees(XN_NODE_TYPE_DEVICE, NULL, deviceList, NULL); CHECK_RV(nRetVal, "Enumerate"); for(xn::NodeInfoList::Iterator iter = deviceList.Begin(); iter != deviceList.End(); ++iter) { xn::NodeInfo node = (*iter); SensorDevice* sensor = new SensorDevice(); char deviceName[256]; //Create Device Context in the global production tree nRetVal = context_->CreateProductionTree(node); CHECK_RV(nRetVal, "Create Device"); Query query; query.AddNeededNode(node.GetInstanceName()); xnOSMemCopy(deviceName, node.GetInstanceName(), xnOSStrLen(node.GetInstanceName())); sensor->SetDeviceName(deviceName); //Create Image and Depth generators for this device nRetVal = context_->CreateAnyProductionTree(XN_NODE_TYPE_IMAGE, &query, *(sensor->GetImageGenerator())); CHECK_RV(nRetVal, "Create Image Generator"); nRetVal = context_->CreateAnyProductionTree(XN_NODE_TYPE_DEPTH, &query, *(sensor->GetDepthGenerator())); CHECK_RV(nRetVal, "Create Depth Generator"); sensor->GetDepthGenerator()->SetMapOutputMode(mapMode); sensor->GetImageGenerator()->SetMapOutputMode(mapMode); //Align the RGB and Depth Cameras sensor->AlignSensors(); devices_.push_back(sensor); } context_->StartGeneratingAll(); }
OniStatus Context::deviceOpen(const char* uri, const char* mode, OniDeviceHandle* pDevice) { oni::implementation::Device* pMyDevice = NULL; const char* deviceURI = uri; if (xnOSStrLen(m_overrideDevice) > 0) deviceURI = m_overrideDevice; xnLogVerbose(XN_MASK_ONI_CONTEXT, "Trying to open device by URI '%s'", deviceURI == NULL ? "(NULL)" : deviceURI); m_cs.Lock(); if (deviceURI == NULL) { // Default if (m_devices.Size() == 0) { m_errorLogger.Append("DeviceOpen using default: no devices found"); xnLogError(XN_MASK_ONI_CONTEXT, "Can't open default device - none found"); m_cs.Unlock(); return ONI_STATUS_ERROR; } pMyDevice = *m_devices.Begin(); } else { for (xnl::List<Device*>::Iterator iter = m_devices.Begin(); iter != m_devices.End(); ++iter) { if (xnOSStrCmp((*iter)->getInfo()->uri, deviceURI) == 0) { pMyDevice = *iter; } } } if (pMyDevice == NULL) { for (xnl::List<DeviceDriver*>::Iterator iter = m_deviceDrivers.Begin(); iter != m_deviceDrivers.End() && pMyDevice == NULL; ++iter) { if ((*iter)->tryDevice(deviceURI)) { for (xnl::List<Device*>::Iterator iter = m_devices.Begin(); iter != m_devices.End(); ++iter) { if (xnOSStrCmp((*iter)->getInfo()->uri, deviceURI) == 0) { pMyDevice = *iter; break; } } } else { // printf("Not yet\n"); } } } m_cs.Unlock(); if (pMyDevice == NULL) { xnLogError(XN_MASK_ONI_CONTEXT, "Couldn't open device '%s'", uri); m_errorLogger.Append("DeviceOpen: Couldn't open device '%s'", uri); return ONI_STATUS_NO_DEVICE; } _OniDevice* pDeviceHandle = XN_NEW(_OniDevice); if (pDeviceHandle == NULL) { m_errorLogger.Append("Couldn't allocate memory for DeviceHandle"); return ONI_STATUS_ERROR; } *pDevice = pDeviceHandle; pDeviceHandle->pDevice = pMyDevice; return pMyDevice->open(mode); }
void XnLogFileWriter::WriteUnformatted(const XnChar* strMessage) { xnOSWriteFile(m_fLogFile, strMessage, xnOSStrLen(strMessage) + 1); }