gc_info.cc
Go to the documentation of this file.
00001 /*
00002  * This file is part of the rc_genicam_api package.
00003  *
00004  * Copyright (c) 2017 Roboception GmbH
00005  * All rights reserved
00006  *
00007  * Author: Heiko Hirschmueller
00008  *
00009  * Redistribution and use in source and binary forms, with or without
00010  * modification, are permitted provided that the following conditions are met:
00011  *
00012  * 1. Redistributions of source code must retain the above copyright notice,
00013  * this list of conditions and the following disclaimer.
00014  *
00015  * 2. Redistributions in binary form must reproduce the above copyright notice,
00016  * this list of conditions and the following disclaimer in the documentation
00017  * and/or other materials provided with the distribution.
00018  *
00019  * 3. Neither the name of the copyright holder nor the names of its contributors
00020  * may be used to endorse or promote products derived from this software without
00021  * specific prior written permission.
00022  *
00023  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00024  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00025  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00026  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
00027  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00028  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00029  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00030  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00031  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00032  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00033  * POSSIBILITY OF SUCH DAMAGE.
00034  */
00035 
00036 #include <rc_genicam_api/system.h>
00037 #include <rc_genicam_api/interface.h>
00038 #include <rc_genicam_api/device.h>
00039 #include <rc_genicam_api/stream.h>
00040 #include <rc_genicam_api/config.h>
00041 
00042 #include <iostream>
00043 
00044 namespace
00045 {
00046 
00054 const char *getAccessMode(const GenApi::INode *node)
00055 {
00056   switch (node->GetAccessMode())
00057   {
00058     case GenApi::NI:
00059       return "(NI)";
00060 
00061     case GenApi::NA:
00062       return "(NA)";
00063 
00064     case GenApi::WO:
00065       return "(WO)";
00066 
00067     case GenApi::RO:
00068       return "(RO)";
00069 
00070     case GenApi::RW:
00071       return "(RW)";
00072 
00073     case GenApi::_UndefinedAccesMode:
00074       return "(undefined access mode)";
00075 
00076     case GenApi::_CycleDetectAccesMode:
00077       return "(cycle detection)";
00078 
00079     default:
00080       return "(unknown)";
00081   }
00082 }
00083 
00093 std::string formatValue(GenApi::IInteger *node, int64_t value)
00094 {
00095   std::ostringstream out;
00096 
00097   switch (node->GetRepresentation())
00098   {
00099     case GenApi::HexNumber:
00100       out << "0x" << std::hex << value;
00101       break;
00102 
00103     case GenApi::IPV4Address:
00104        out << ((value>>24)&0xff) << '.' << ((value>>16)&0xff) << '.'
00105            << ((value>>8)&0xff) << '.' << (value&0xff);
00106        break;
00107 
00108     case GenApi::MACAddress:
00109        out << std::hex << ((value>>32)&0xff) << ':' << ((value>>30)&0xff) << ':'
00110                        << ((value>>24)&0xff) << ':' << ((value>>16)&0xff) << ':'
00111                        << ((value>>8)&0xff) << ':' << (value&0xff);
00112        break;
00113 
00114     default:
00115       out << value;
00116       break;
00117   }
00118 
00119   return out.str();
00120 }
00121 
00132 void printNode(const std::string &prefix, GenApi::INode *node, int depth)
00133 {
00134   if (node != 0 && node->GetAccessMode() != GenApi::NI)
00135   {
00136     switch (node->GetPrincipalInterfaceType())
00137     {
00138       case GenApi::intfIValue:
00139         std::cout << prefix << "Value: " << node->GetName() << " " << getAccessMode(node)
00140                   << std::endl;
00141         break;
00142 
00143       case GenApi::intfIBase:
00144         std::cout << prefix << "Base: " << node->GetName() << " " << getAccessMode(node)
00145                   << std::endl;
00146         break;
00147 
00148       case GenApi::intfIInteger:
00149         {
00150           std::cout << prefix << "Integer: " << node->GetName() << " "
00151                     << getAccessMode(node) << " ";
00152 
00153           GenApi::IInteger *p=dynamic_cast<GenApi::IInteger *>(node);
00154 
00155           if (GenApi::IsReadable(p))
00156           {
00157             std::cout << "[" << formatValue(p, p->GetMin()) << ", "
00158                       << formatValue(p, p->GetMax()) << "]: ";
00159             std::cout << formatValue(p, p->GetValue()) << " " << p->GetUnit();
00160           }
00161 
00162           std::cout << std::endl;
00163         }
00164         break;
00165 
00166       case GenApi::intfIBoolean:
00167         {
00168           std::cout << prefix << "Boolean: " << node->GetName() << " " << getAccessMode(node);
00169 
00170           GenApi::IBoolean *p=dynamic_cast<GenApi::IBoolean *>(node);
00171 
00172           if (GenApi::IsReadable(p))
00173           {
00174             std::cout << ": " << p->GetValue();
00175           }
00176 
00177           std::cout << std::endl;
00178         }
00179         break;
00180 
00181       case GenApi::intfICommand:
00182         std::cout << prefix << "Command: " << node->GetName() << " " << getAccessMode(node)
00183                   << std::endl;
00184         break;
00185 
00186       case GenApi::intfIFloat:
00187         {
00188           std::cout << prefix << "Float: " << node->GetName() << " " << getAccessMode(node)
00189                     << " ";
00190 
00191           GenApi::IFloat *p=dynamic_cast<GenApi::IFloat *>(node);
00192 
00193           if (GenApi::IsReadable(p))
00194           {
00195             std::cout << "[" << p->GetMin() << ", "
00196                       << p->GetMax() << "]: "
00197                       << p->GetValue() << " " << p->GetUnit();
00198           }
00199 
00200           std::cout << std::endl;
00201         }
00202         break;
00203 
00204       case GenApi::intfIString:
00205         {
00206           std::cout << prefix << "String: " << node->GetName() << " " << getAccessMode(node)
00207                     << ": ";
00208 
00209           GenApi::IString *p=dynamic_cast<GenApi::IString *>(node);
00210 
00211           if (GenApi::IsReadable(p))
00212           {
00213             std::cout << p->GetValue();
00214           }
00215 
00216           std::cout << std::endl;
00217         }
00218         break;
00219 
00220       case GenApi::intfIRegister:
00221         std::cout << prefix << "Register: " << node->GetName() << " " << getAccessMode(node)
00222                   << std::endl;
00223         break;
00224 
00225       case GenApi::intfICategory:
00226         {
00227           std::cout << prefix << "Category: " << node->GetName() << " "
00228                     << getAccessMode(node) << std::endl;
00229 
00230           if (depth > 0)
00231           {
00232             GenApi::ICategory *root=dynamic_cast<GenApi::ICategory *>(node);
00233 
00234             if (root != 0)
00235             {
00236               GenApi::FeatureList_t feature;
00237               root->GetFeatures(feature);
00238 
00239               for (size_t i=0; i<feature.size(); i++)
00240               {
00241                 printNode(prefix+"  ", feature[i]->GetNode(), depth-1);
00242               }
00243             }
00244           }
00245         }
00246         break;
00247 
00248       case GenApi::intfIEnumeration:
00249         {
00250           std::cout << prefix << "Enumeration: " << node->GetName() << " " << getAccessMode(node)
00251                     << ' ';
00252 
00253           GenApi::IEnumeration *p=dynamic_cast<GenApi::IEnumeration *>(node);
00254 
00255           if (GenApi::IsReadable(p))
00256           {
00257             std::cout << '[';
00258 
00259             GenApi::StringList_t list;
00260             p->GetSymbolics(list);
00261 
00262             for (size_t i=0; i<list.size(); i++)
00263             {
00264               if (i > 0)
00265               {
00266                 std::cout << ' ';
00267               }
00268 
00269               std::cout << list[i];
00270             }
00271 
00272             std::cout << "]: ";
00273 
00274             if (p->GetCurrentEntry() != 0)
00275             {
00276               std::cout << p->GetCurrentEntry()->GetSymbolic();
00277             }
00278           }
00279 
00280           std::cout << std::endl;
00281         }
00282         break;
00283 
00284       case GenApi::intfIEnumEntry:
00285         std::cout << prefix << "EnumEntry: " << node->GetName() << " " << getAccessMode(node)
00286                   << std::endl;
00287         break;
00288 
00289       case GenApi::intfIPort:
00290         std::cout << prefix << "Port: " << node->GetName() << " " << getAccessMode(node)
00291                   << std::endl;
00292         break;
00293 
00294     }
00295   }
00296 }
00297 
00298 }
00299 
00300 int main(int argc, char *argv[])
00301 {
00302   int ret=0;
00303 
00304   try
00305   {
00306     if (argc >= 2 && std::string(argv[1]) != "-h")
00307     {
00308       if (std::string(argv[1]) == "-l")
00309       {
00310         // list all systems, interfaces and devices
00311 
00312         std::vector<std::shared_ptr<rcg::System> > system=rcg::System::getSystems();
00313 
00314         for (size_t i=0; i<system.size(); i++)
00315         {
00316           system[i]->open();
00317 
00318           std::cout << "Transport Layer " << system[i]->getID() << std::endl;
00319           std::cout << "Vendor:         " << system[i]->getVendor() << std::endl;
00320           std::cout << "Model:          " << system[i]->getModel() << std::endl;
00321           std::cout << "Vendor version: " << system[i]->getVersion() << std::endl;
00322           std::cout << "TL type:        " << system[i]->getTLType() << std::endl;
00323           std::cout << "Name:           " << system[i]->getName() << std::endl;
00324           std::cout << "Pathname:       " << system[i]->getPathname() << std::endl;
00325           std::cout << "Display name:   " << system[i]->getDisplayName() << std::endl;
00326           std::cout << "GenTL version   " << system[i]->getMajorVersion() << "."
00327                     << system[i]->getMinorVersion() << std::endl;
00328           std::cout << std::endl;
00329 
00330           std::vector<std::shared_ptr<rcg::Interface> > interf=system[i]->getInterfaces();
00331 
00332           for (size_t k=0; k<interf.size(); k++)
00333           {
00334             interf[k]->open();
00335 
00336             std::cout << "    Interface     " << interf[k]->getID() << std::endl;
00337             std::cout << "    Display name: " << interf[k]->getDisplayName() << std::endl;
00338             std::cout << "    TL type:      " << interf[k]->getTLType() << std::endl;
00339             std::cout << std::endl;
00340 
00341             std::vector<std::shared_ptr<rcg::Device> > device=interf[k]->getDevices();
00342 
00343             for (size_t j=0; j<device.size(); j++)
00344             {
00345               std::cout << "        Device         " << device[j]->getID() << std::endl;
00346               std::cout << "        Vendor:        " << device[j]->getVendor() << std::endl;
00347               std::cout << "        Model:         " << device[j]->getModel() << std::endl;
00348               std::cout << "        TL type:       " << device[j]->getTLType() << std::endl;
00349               std::cout << "        Display name:  " << device[j]->getDisplayName() << std::endl;
00350               std::cout << "        Access status: " << device[j]->getAccessStatus() << std::endl;
00351               std::cout << "        Serial number: " << device[j]->getSerialNumber() << std::endl;
00352               std::cout << "        Version:       " << device[j]->getVersion() << std::endl;
00353               std::cout << "        TS Frequency:  " << device[j]->getTimestampFrequency() << std::endl;
00354               std::cout << std::endl;
00355             }
00356 
00357             interf[k]->close();
00358           }
00359 
00360           system[i]->close();
00361         }
00362       }
00363       else
00364       {
00365         int k=1;
00366 
00367         // get parameters, if any
00368 
00369         const char *xml=0;
00370         if (k+1 < argc && std::string(argv[k]) == "-o")
00371         {
00372           k++;
00373           xml=argv[k++];
00374         }
00375 
00376         if (k < argc)
00377         {
00378           // separate optional node name from device id
00379 
00380           std::string devid=argv[k++];
00381           std::string node="Root";
00382           int depth=1000;
00383 
00384           {
00385             size_t j=devid.find('?');
00386 
00387             if (j != std::string::npos)
00388             {
00389               node=devid.substr(j+1);
00390               devid=devid.substr(0, j);
00391               depth=1;
00392 
00393               if (node.size() == 0)
00394               {
00395                 node="Root";
00396               }
00397             }
00398           }
00399 
00400           // find specific device accross all systems and interfaces and show some
00401           // information
00402 
00403           std::shared_ptr<rcg::Device> dev=rcg::getDevice(devid.c_str());
00404 
00405           if (dev)
00406           {
00407             // open device and optionally change some settings
00408 
00409             if (k < argc)
00410             {
00411               dev->open(rcg::Device::CONTROL);
00412             }
00413             else
00414             {
00415               dev->open(rcg::Device::READONLY);
00416             }
00417 
00418             std::shared_ptr<GenApi::CNodeMapRef> nodemap=dev->getRemoteNodeMap(xml);
00419 
00420             while (k < argc)
00421             {
00422               std::string p=argv[k++];
00423 
00424               if (p.find('=') != std::string::npos)
00425               {
00426                 // split argument in key and value
00427 
00428                 size_t j=p.find('=');
00429                 std::string value=p.substr(j+1);
00430                 std::string key=p.substr(0, j);
00431 
00432                 // set key=value pair through GenICam
00433 
00434                 rcg::setString(nodemap, key.c_str(), value.c_str(), true);
00435               }
00436               else
00437               {
00438                 // call the command
00439                 rcg::callCommand(nodemap, p.c_str(), true);
00440               }
00441             }
00442 
00443             if (depth > 1)
00444             {
00445               // report all features
00446 
00447               std::cout << "Device:        " << dev->getID() << std::endl;
00448               std::cout << "Vendor:        " << dev->getVendor() << std::endl;
00449               std::cout << "Model:         " << dev->getModel() << std::endl;
00450               std::cout << "TL type:       " << dev->getTLType() << std::endl;
00451               std::cout << "Display name:  " << dev->getDisplayName() << std::endl;
00452               std::cout << "User name:     " << dev->getUserDefinedName() << std::endl;
00453               std::cout << "Serial number: " << dev->getSerialNumber() << std::endl;
00454               std::cout << "Version:       " << dev->getVersion() << std::endl;
00455               std::cout << "TS Frequency:  " << dev->getTimestampFrequency() << std::endl;
00456               std::cout << std::endl;
00457 
00458               std::vector<std::shared_ptr<rcg::Stream> > stream=dev->getStreams();
00459 
00460               std::cout << "Available streams:" << std::endl;
00461               for (size_t i=0; i<stream.size(); i++)
00462               {
00463                 std::cout << "  Stream ID: " << stream[i]->getID() << std::endl;
00464               }
00465 
00466               std::cout << std::endl;
00467 
00468               std::cout << "Available features:" << std::endl;
00469               printNode(std::string("  "), nodemap->_GetNode(node.c_str()), depth);
00470             }
00471             else
00472             {
00473               // report requested node only
00474 
00475               GenApi::INode *p=nodemap->_GetNode(node.c_str());
00476 
00477               if (p)
00478               {
00479                 printNode(std::string(), p, depth);
00480               }
00481               else
00482               {
00483                 std::cerr << "Unknown node: " << node << std::endl;
00484                 ret=1;
00485               }
00486             }
00487 
00488             dev->close();
00489           }
00490           else
00491           {
00492             std::cerr << "Device '" << devid << "' not found!" << std::endl;
00493             ret=1;
00494           }
00495         }
00496         else
00497         {
00498           std::cerr << "Device name not given!" << std::endl;
00499           ret=1;
00500         }
00501       }
00502     }
00503     else
00504     {
00505       std::cout << argv[0] << " -h | -l | ([-o <xml-output-file>] [<interface-id>:]<device-id>[?<node>] [<key>=<value>] ...)" << std::endl;
00506       std::cout << std::endl;
00507       std::cout << "Provides information about GenICam transport layers, interfaces and devices." << std::endl;
00508       std::cout << std::endl;
00509       std::cout << "Options: " << std::endl;
00510       std::cout << "-h   Prints help information and exits" << std::endl;
00511       std::cout << "-l   List all all available devices on all interfaces" << std::endl;
00512       std::cout << "-o   Filename to store XML description from specified device" << std::endl;
00513       std::cout << std::endl;
00514       std::cout << "Parameters:" << std::endl;
00515       std::cout << "<interface-id> Optional GenICam ID of interface for connecting to the device" << std::endl;
00516       std::cout << "<device-id>    GenICam device ID, serial number or user defined name of device" << std::endl;
00517       std::cout << "<node>         Optional name of category or parameter to be reported" << std::endl;
00518       std::cout << "<key>=<value>  Optional GenICam parameters to be changed in the given order before reporting" << std::endl;
00519       ret=1;
00520     }
00521   }
00522   catch (const std::exception &ex)
00523   {
00524     std::cerr << ex.what() << std::endl;
00525     ret=2;
00526   }
00527 
00528   rcg::System::clearSystems();
00529 
00530   return ret;
00531 }


rc_genicam_api
Author(s): Heiko Hirschmueller
autogenerated on Thu Jun 6 2019 18:42:47