cpp-enumerate-devices.cpp
Go to the documentation of this file.
00001 // License: Apache 2.0. See LICENSE file in root directory.
00002 // Copyright(c) 2015 Intel Corporation. All Rights Reserved.
00003 
00004 #include <librealsense/rs.hpp>
00005 #include <iostream>
00006 #include <iomanip>
00007 
00008 int main() try
00009 {
00010     rs::log_to_console(rs::log_severity::warn);
00011     //rs::log_to_file(rs::log_severity::debug, "librealsense.log");
00012 
00013     // Obtain a list of devices currently present on the system
00014     rs::context ctx;
00015     int device_count = ctx.get_device_count();   
00016     if (!device_count) printf("No device detected. Is it plugged in?\n");
00017 
00018     for(int i = 0; i < device_count; ++i)
00019     {
00020         // Show the device name and information
00021         rs::device * dev = ctx.get_device(i);
00022         std::cout << "Device " << i << " - " << dev->get_name() << ":\n";
00023         std::cout << " Serial number: " << dev->get_serial() << "\n";
00024         std::cout << " Firmware version: " << dev->get_firmware_version() << "\n";
00025         try { std::cout << " USB Port ID: " << dev->get_usb_port_id() << "\n"; } catch (...) {}
00026         if (dev->supports(rs::capabilities::adapter_board)) std::cout << " Adapter Board Firmware version: " << dev->get_info(rs::camera_info::adapter_board_firmware_version) << "\n";
00027         if (dev->supports(rs::capabilities::motion_events)) std::cout << " Motion Module Firmware version: " << dev->get_info(rs::camera_info::motion_module_firmware_version) << "\n";
00028 
00029         // Show which options are supported by this device
00030         std::cout << " Camera info: \n";
00031         for (int j = RS_CAMERA_INFO_DEVICE_NAME; j < RS_CAMERA_INFO_COUNT; ++j)
00032         {
00033             rs::camera_info param = (rs::camera_info)j;
00034             if (dev->supports(param))
00035                 std::cout << "    " << std::left << std::setw(20) << rs_camera_info_to_string(rs_camera_info(param)) << ": \t" << dev->get_info(param) << std::endl;
00036         }
00037 
00038         // Show which options are supported by this device
00039         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;
00040         for(int j = 0; j < RS_OPTION_COUNT; ++j)
00041         {
00042             rs::option opt = (rs::option)j;
00043             if(dev->supports_option(opt))
00044             {
00045                 double min, max, step, def;
00046                 dev->get_option_range(opt, min, max, step, def);
00047                 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";
00048             }
00049         }
00050 
00051         // Show which streams are supported by this device
00052         for(int j = 0; j < RS_STREAM_COUNT; ++j)
00053         {
00054             // Determine number of available streaming modes (zero means stream is unavailable) 
00055             rs::stream strm = (rs::stream)j;
00056             int mode_count = dev->get_stream_mode_count(strm);
00057             if(mode_count == 0) continue;
00058 
00059             // Show each available mode for this stream
00060             std::cout << " Stream " << strm << " - " << mode_count << " modes:\n";
00061             for(int k = 0; k < mode_count; ++k)
00062             {
00063                 // Show width, height, format, and framerate, the settings required to enable the stream in this mode
00064                 int width, height, framerate;
00065                 rs::format format;
00066                 dev->get_stream_mode(strm, k, width, height, format, framerate);
00067                 std::cout << "  " << width << "\tx " << height << "\t@ " << framerate << "Hz\t" << format;
00068 
00069                 // Enable the stream in this mode so that we can retrieve its intrinsics
00070                 dev->enable_stream(strm, width, height, format, framerate);
00071                 rs::intrinsics intrin = dev->get_stream_intrinsics(strm);
00072 
00073                 // Show horizontal and vertical field of view, in degrees
00074                 std::cout << "\t" << std::setprecision(3) << intrin.hfov() << " x " << intrin.vfov() << " degrees, distortion = " << intrin.model() << std::endl;
00075             }
00076 
00077             // Some stream mode combinations are invalid, so disable this stream before moving on to the next one
00078             dev->disable_stream(strm);
00079         }
00080     }
00081 
00082     return EXIT_SUCCESS;
00083 }
00084 catch(const rs::error & e)
00085 {
00086     std::cerr << "RealSense error calling " << e.get_failed_function() << "(" << e.get_failed_args() << "):\n    " << e.what() << std::endl;
00087     return EXIT_FAILURE;
00088 }


librealsense
Author(s): Sergey Dorodnicov , Mark Horn , Reagan Lopez
autogenerated on Tue Jun 25 2019 19:54:38