diff --git a/include/librealsense2/h/rs_device.h b/include/librealsense2/h/rs_device.h index b9e4dd8b3e..974dfdf688 100644 --- a/include/librealsense2/h/rs_device.h +++ b/include/librealsense2/h/rs_device.h @@ -54,6 +54,12 @@ rs2_device* rs2_create_device(const rs2_device_list* info_list, int index, rs2_e */ void rs2_delete_device(rs2_device* device); +/** +* \param[in] device Realsense device to query +* \return True if device is still present in the system +*/ +int rs2_device_is_connected( const rs2_device * device, rs2_error ** error ); + /** * Retrieve camera specific information, like versions of various internal components. * \param[in] device The RealSense device diff --git a/include/librealsense2/hpp/rs_device.hpp b/include/librealsense2/hpp/rs_device.hpp index 615636c5b7..7986d0c8c5 100644 --- a/include/librealsense2/hpp/rs_device.hpp +++ b/include/librealsense2/hpp/rs_device.hpp @@ -91,7 +91,6 @@ namespace rs2 void hardware_reset() { rs2_error* e = nullptr; - rs2_hardware_reset(_dev.get(), &e); error::handle(e); } @@ -110,6 +109,8 @@ namespace rs2 } device() : _dev(nullptr) {} + // Note: this checks the validity of rs2::device (i.e., if it's connected to a realsense device), and does + // NOT reflect the current condition (connected/disconnected). Use is_connected() for that. operator bool() const { return _dev != nullptr; @@ -125,6 +126,14 @@ namespace rs2 < 0 ); } + bool is_connected() const + { + rs2_error * e = nullptr; + bool connected = rs2_device_is_connected( _dev.get(), &e ); + error::handle( e ); + return connected; + } + template bool is() const { diff --git a/src/realsense.def b/src/realsense.def index 75ab764531..9099c69d40 100644 --- a/src/realsense.def +++ b/src/realsense.def @@ -18,6 +18,7 @@ EXPORTS rs2_delete_device_list rs2_create_device rs2_delete_device + rs2_device_is_connected rs2_query_sensors rs2_get_sensors_count diff --git a/src/rs.cpp b/src/rs.cpp index 517338ff11..2ad64cbf41 100644 --- a/src/rs.cpp +++ b/src/rs.cpp @@ -308,6 +308,13 @@ void rs2_delete_device(rs2_device* device) BEGIN_API_CALL } NOEXCEPT_RETURN(, device) +int rs2_device_is_connected( const rs2_device * device, rs2_error ** error ) BEGIN_API_CALL +{ + VALIDATE_NOT_NULL( device ); + return device->device->is_valid(); +} +HANDLE_EXCEPTIONS_AND_RETURN( 0, device ) + rs2_sensor* rs2_create_sensor(const rs2_sensor_list* list, int index, rs2_error** error) BEGIN_API_CALL { VALIDATE_NOT_NULL(list);