cpp-enumerate-devices.cpp
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2015 Intel Corporation. All Rights Reserved.
3 
4 #include <librealsense/rs.hpp>
5 #include <iostream>
6 #include <iomanip>
7 
8 int main() try
9 {
11  //rs::log_to_file(rs::log_severity::debug, "librealsense.log");
12 
13  // Obtain a list of devices currently present on the system
15  int device_count = ctx.get_device_count();
16  if (!device_count) printf("No device detected. Is it plugged in?\n");
17 
18  for(int i = 0; i < device_count; ++i)
19  {
20  // Show the device name and information
21  rs::device * dev = ctx.get_device(i);
22  std::cout << "Device " << i << " - " << dev->get_name() << ":\n";
23  std::cout << " Serial number: " << dev->get_serial() << "\n";
24  std::cout << " Firmware version: " << dev->get_firmware_version() << "\n";
25  try { std::cout << " USB Port ID: " << dev->get_usb_port_id() << "\n"; } catch (...) {}
26  if (dev->supports(rs::capabilities::adapter_board)) std::cout << " Adapter Board Firmware version: " << dev->get_info(rs::camera_info::adapter_board_firmware_version) << "\n";
27  if (dev->supports(rs::capabilities::motion_events)) std::cout << " Motion Module Firmware version: " << dev->get_info(rs::camera_info::motion_module_firmware_version) << "\n";
28 
29  // Show which options are supported by this device
30  std::cout << " Camera info: \n";
31  for (int j = RS_CAMERA_INFO_DEVICE_NAME; j < RS_CAMERA_INFO_COUNT; ++j)
32  {
34  if (dev->supports(param))
35  std::cout << " " << std::left << std::setw(20) << rs_camera_info_to_string(rs_camera_info(param)) << ": \t" << dev->get_info(param) << std::endl;
36  }
37 
38  // Show which options are supported by this device
39  std::cout << std::setw(55) << " Supported options:" << std::setw(10) << "min" << std::setw(10) << " max" << std::setw(6) << " step" << std::setw(10) << " default" << std::endl;
40  for(int j = 0; j < RS_OPTION_COUNT; ++j)
41  {
42  rs::option opt = (rs::option)j;
43  if(dev->supports_option(opt))
44  {
45  double min, max, step, def;
46  dev->get_option_range(opt, min, max, step, def);
47  std::cout << " " << std::left << std::setw(50) << opt << " : " << std::setw(5) << min << "... " << std::setw(12) << max << std::setw(6) << step << std::setw(10) << def << "\n";
48  }
49  }
50 
51  // Show which streams are supported by this device
52  for(int j = 0; j < RS_STREAM_COUNT; ++j)
53  {
54  // Determine number of available streaming modes (zero means stream is unavailable)
55  rs::stream strm = (rs::stream)j;
56  int mode_count = dev->get_stream_mode_count(strm);
57  if(mode_count == 0) continue;
58 
59  // Show each available mode for this stream
60  std::cout << " Stream " << strm << " - " << mode_count << " modes:\n";
61  for(int k = 0; k < mode_count; ++k)
62  {
63  // Show width, height, format, and framerate, the settings required to enable the stream in this mode
64  int width, height, framerate;
66  dev->get_stream_mode(strm, k, width, height, format, framerate);
67  std::cout << " " << width << "\tx " << height << "\t@ " << framerate << "Hz\t" << format;
68 
69  // Enable the stream in this mode so that we can retrieve its intrinsics
70  dev->enable_stream(strm, width, height, format, framerate);
71  rs::intrinsics intrin = dev->get_stream_intrinsics(strm);
72 
73  // Show horizontal and vertical field of view, in degrees
74  std::cout << "\t" << std::setprecision(3) << intrin.hfov() << " x " << intrin.vfov() << " degrees, distortion = " << intrin.model() << std::endl;
75  }
76 
77  // Some stream mode combinations are invalid, so disable this stream before moving on to the next one
78  dev->disable_stream(strm);
79  }
80  }
81 
82  return EXIT_SUCCESS;
83 }
84 catch(const rs::error & e)
85 {
86  std::cerr << "RealSense error calling " << e.get_failed_function() << "(" << e.get_failed_args() << "):\n " << e.what() << std::endl;
87  return EXIT_FAILURE;
88 }
void log_to_console(log_severity min_severity)
Definition: rs.hpp:1104
Provides convenience methods relating to devices.
Definition: rs.hpp:567
intrinsics get_stream_intrinsics(stream stream) const
Retrieves intrinsic camera parameters for specific stream.
Definition: rs.hpp:788
int main()
void enable_stream(stream stream, int width, int height, format format, int framerate, output_buffer_format output_buffer_type=output_buffer_format::continous)
Enables specific stream and requests specific properties.
Definition: rs.hpp:704
float vfov() const
Definition: rs.hpp:255
const std::string & get_failed_args() const
Definition: rs.hpp:315
rs_error * e
const char * rs_camera_info_to_string(rs_camera_info info)
Definition: rs.cpp:764
GLint GLint GLsizei GLsizei height
Definition: glext.h:112
const char * get_firmware_version() const
Retrieves version of firmware currently installed on device.
Definition: rs.hpp:608
const char * get_info(camera_info info) const
Retrieves camera-specific information such as versions of various components.
Definition: rs.hpp:618
void get_option_range(option option, double &min, double &max, double &step)
Retrieves available range of values of supported option.
Definition: rs.hpp:909
Video stream intrinsics.
Definition: rs.hpp:252
const char * get_usb_port_id() const
Retrieves USB port number of device.
Definition: rs.hpp:598
camera_info
Read-only strings that can be queried from the device.
Definition: rs.hpp:192
Exposes librealsense functionality for C++ compilers.
option
Defines general configuration controls.
Definition: rs.hpp:87
int get_stream_mode_count(stream stream) const
Determines number of streaming modes available for given stream.
Definition: rs.hpp:675
stream
Streams are different types of data provided by RealSense devices.
Definition: rs.hpp:24
Context.
Definition: rs.hpp:319
GLfloat param
Definition: glext.h:370
rs_camera_info
Read-only strings that can be queried from the device.
Definition: rs.h:237
const char * get_name() const
Retrieves human-readable device model string.
Definition: rs.hpp:578
format
Formats: defines how each stream can be encoded. rs_format specifies how a frame is represented in me...
Definition: rs.hpp:42
void get_stream_mode(stream stream, int index, int &width, int &height, format &format, int &framerate) const
Determines properties of specific streaming mode.
Definition: rs.hpp:690
GLint left
Definition: glext.h:1947
distortion model() const
Definition: rs.hpp:256
auto ctx
const char * get_serial() const
Retrieves unique serial number of device.
Definition: rs.hpp:588
bool supports_option(option option) const
Determines if device allows specific option to be queried and set.
Definition: rs.hpp:664
void disable_stream(stream stream)
Disables specific stream.
Definition: rs.hpp:723
GLint GLint GLsizei width
Definition: glext.h:112
rs_device * dev
bool supports(capabilities capability) const
Determines device capabilities.
Definition: rs.hpp:1005
device * get_device(int index)
Definition: rs.hpp:354
const std::string & get_failed_function() const
Definition: rs.hpp:314
int get_device_count() const
Definition: rs.hpp:343
float hfov() const
Definition: rs.hpp:254


librealsense
Author(s): Sergey Dorodnicov , Mark Horn , Reagan Lopez
autogenerated on Fri Mar 13 2020 03:16:17