mirror of
https://github.com/orbbec/OrbbecSDK_ROS2.git
synced 2026-10-11 15:09:48 +08:00
fixed get device by uid
This commit is contained in:
@@ -109,7 +109,8 @@ void OBCameraNodeDriver::onDeviceConnected(const std::shared_ptr<ob::DeviceList>
|
|||||||
pthread_mutex_lock(orb_device_lock_);
|
pthread_mutex_lock(orb_device_lock_);
|
||||||
std::shared_ptr<int> lock_holder(nullptr,
|
std::shared_ptr<int> lock_holder(nullptr,
|
||||||
[this](int *) { pthread_mutex_unlock(orb_device_lock_); });
|
[this](int *) { pthread_mutex_unlock(orb_device_lock_); });
|
||||||
RCLCPP_INFO_STREAM_THROTTLE(logger_, *get_clock(), 1000, "device list count " << device_list->deviceCount());
|
RCLCPP_INFO_STREAM_THROTTLE(logger_, *get_clock(), 1000,
|
||||||
|
"device list count " << device_list->deviceCount());
|
||||||
if (!device_) {
|
if (!device_) {
|
||||||
try {
|
try {
|
||||||
startDevice(device_list);
|
startDevice(device_list);
|
||||||
@@ -275,38 +276,17 @@ std::shared_ptr<ob::Device> OBCameraNodeDriver::selectDeviceBySerialNumber(
|
|||||||
|
|
||||||
std::shared_ptr<ob::Device> OBCameraNodeDriver::selectDeviceByUSBPort(
|
std::shared_ptr<ob::Device> OBCameraNodeDriver::selectDeviceByUSBPort(
|
||||||
const std::shared_ptr<ob::DeviceList> &list, const std::string &usb_port) {
|
const std::shared_ptr<ob::DeviceList> &list, const std::string &usb_port) {
|
||||||
for (size_t i = 0; i < list->deviceCount(); i++) {
|
try {
|
||||||
try {
|
auto device = list->getDeviceByUid(usb_port.c_str());
|
||||||
auto pid = list->pid(i);
|
return device;
|
||||||
if (isOpenNIDevice(pid)) {
|
} catch (ob::Error &e) {
|
||||||
// openNI device
|
RCLCPP_ERROR_STREAM(logger_, "Failed to get device info " << e.getMessage());
|
||||||
auto dev = list->getDevice(i);
|
} catch (std::exception &e) {
|
||||||
auto device_info = dev->getDeviceInfo();
|
RCLCPP_ERROR_STREAM(logger_, "Failed to get device info " << e.what());
|
||||||
std::string uid = device_info->uid();
|
} catch (...) {
|
||||||
auto port_id = parseUsbPort(uid);
|
RCLCPP_ERROR_STREAM(logger_, "Failed to get device info");
|
||||||
if (port_id == usb_port) {
|
|
||||||
RCLCPP_INFO_STREAM_THROTTLE(logger_, *get_clock(), 1000,
|
|
||||||
"Device port id " << port_id << " matched");
|
|
||||||
return dev;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
std::string uid = list->uid(i);
|
|
||||||
auto port_id = parseUsbPort(uid);
|
|
||||||
RCLCPP_ERROR_STREAM_THROTTLE(logger_, *get_clock(), 1000, "Device usb port: " << uid);
|
|
||||||
if (port_id == usb_port) {
|
|
||||||
RCLCPP_INFO_STREAM_THROTTLE(logger_, *get_clock(), 1000,
|
|
||||||
"Device usb port " << uid << " matched");
|
|
||||||
return list->getDevice(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (ob::Error &e) {
|
|
||||||
RCLCPP_ERROR_STREAM(logger_, "Failed to get device info " << e.getMessage());
|
|
||||||
} catch (std::exception &e) {
|
|
||||||
RCLCPP_ERROR_STREAM(logger_, "Failed to get device info " << e.what());
|
|
||||||
} catch (...) {
|
|
||||||
RCLCPP_ERROR_STREAM(logger_, "Failed to get device info");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user