gc_config.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/config.h>
00040 
00041 #include <iostream>
00042 
00043 int main(int argc, char *argv[])
00044 {
00045   try
00046   {
00047     if (argc > 1)
00048     {
00049       // list all available GigE Vision devices
00050 
00051       if (std::string(argv[1]) == "-l")
00052       {
00053         std::cout << "Available GigE Vision devices:" << std::endl;
00054 
00055         std::vector<std::shared_ptr<rcg::System> > system=rcg::System::getSystems();
00056 
00057         for (size_t i=0; i<system.size(); i++)
00058         {
00059           system[i]->open();
00060 
00061           std::vector<std::shared_ptr<rcg::Interface> > interf=system[i]->getInterfaces();
00062 
00063           for (size_t k=0; k<interf.size(); k++)
00064           {
00065             interf[k]->open();
00066 
00067             std::vector<std::shared_ptr<rcg::Device> > device=interf[k]->getDevices();
00068 
00069             for (size_t j=0; j<device.size(); j++)
00070             {
00071               if (device[j]->getTLType() == "GEV")
00072               {
00073                 std::cout << "  " << interf[k]->getID() << ":" << device[j]->getID() << " (";
00074 
00075                 std::string uname=device[j]->getDisplayName();
00076 
00077                 if (uname.size() > 0)
00078                 {
00079                   std::cout << uname << ", ";
00080                 }
00081 
00082                 std::cout << device[j]->getSerialNumber() << ")" << std::endl;
00083               }
00084             }
00085 
00086             interf[k]->close();
00087           }
00088 
00089           system[i]->close();
00090         }
00091       }
00092       else
00093       {
00094         // discover and open a specific device
00095 
00096         int i=1;
00097         std::shared_ptr<rcg::Device> dev=rcg::getDevice(argv[i++]);
00098 
00099         if (dev != 0)
00100         {
00101           if (i < argc)
00102           {
00103             dev->open(rcg::Device::CONTROL);
00104           }
00105           else
00106           {
00107             dev->open(rcg::Device::READONLY);
00108           }
00109 
00110           // change setting according to given parameters
00111 
00112           std::shared_ptr<GenApi::CNodeMapRef> nodemap=dev->getRemoteNodeMap();
00113 
00114           while (i < argc)
00115           {
00116             std::string p=argv[i++];
00117 
00118             if (p[0] == '-' && i < argc)
00119             {
00120               if (p == "-n") // change user defined device name
00121               {
00122                 rcg::setString(nodemap, "DeviceUserID", argv[i++], true);
00123               }
00124               else if (p == "-d") // switch dhcp on or off
00125               {
00126                 rcg::setString(nodemap, "GevCurrentIPConfigurationDHCP", argv[i++], true);
00127               }
00128               else if (p == "-p") // switch persistent IP on or off
00129               {
00130                 rcg::setString(nodemap, "GevCurrentIPConfigurationPersistentIP", argv[i++], true);
00131               }
00132               else if (p == "-t") // switch precision time protocol on or off
00133               {
00134                 rcg::setString(nodemap, "GevIEEE1588", argv[i++], true);
00135               }
00136               else if (p == "-i") // set persistent IP address
00137               {
00138                 rcg::setIPV4Address(nodemap, "GevPersistentIPAddress", argv[i++], true);
00139               }
00140               else if (p == "-s") // set persistent subnet mask
00141               {
00142                 rcg::setIPV4Address(nodemap, "GevPersistentSubnetMask", argv[i++], true);
00143               }
00144               else if (p == "-g") // set persistent gateway
00145               {
00146                 rcg::setIPV4Address(nodemap, "GevPersistentDefaultGateway", argv[i++], true);
00147               }
00148               else
00149               {
00150                 std::cerr << "Unknown parameter: " << p << std::endl;
00151                 exit(1);
00152               }
00153             }
00154             else if (p.find('=') != std::string::npos)
00155             {
00156               // split argument in key and value
00157 
00158               size_t k=p.find('=');
00159               std::string value=p.substr(k+1);
00160               std::string key=p.substr(0, k);
00161 
00162               // set key=value pair through GenICam
00163 
00164               rcg::setString(nodemap, key.c_str(), value.c_str(), true);
00165             }
00166             else
00167             {
00168               std::cerr << "Missing '=': " << p << std::endl;
00169               exit(1);
00170             }
00171           }
00172 
00173           // print network configuration of the device
00174 
00175           std::cout << "ID:                       " << dev->getParent()->getID() << ":"
00176                                                     << dev->getID() << std::endl;
00177           std::cout << "Serial number:            " << rcg::getString(nodemap, "DeviceID") << std::endl;
00178           std::cout << "User defined ID:          " << rcg::getString(nodemap, "DeviceUserID") << std::endl;
00179           std::cout << "MAC Address:              " << rcg::getString(nodemap, "GevMACAddress") << std::endl;
00180           std::cout << std::endl;
00181 
00182           std::cout << "Current IP:               " << rcg::getString(nodemap, "GevCurrentIPAddress") << std::endl;
00183           std::cout << "Current subnet mask:      " << rcg::getString(nodemap, "GevCurrentSubnetMask") << std::endl;
00184           std::cout << "Current gateway:          " << rcg::getString(nodemap, "GevCurrentDefaultGateway") << std::endl;
00185           std::cout << std::endl;
00186 
00187           std::cout << "Persistent IP on/off:     " << rcg::getString(nodemap, "GevCurrentIPConfigurationPersistentIP") << std::endl;
00188           std::cout << "  Persistent IP:          " << rcg::getString(nodemap, "GevPersistentIPAddress") << std::endl;
00189           std::cout << "  Persistent subnet mask: " << rcg::getString(nodemap, "GevPersistentSubnetMask") << std::endl;
00190           std::cout << "  Persistent gateway:     " << rcg::getString(nodemap, "GevPersistentDefaultGateway") << std::endl;
00191           std::cout << "DHCP on/off:              " << rcg::getString(nodemap, "GevCurrentIPConfigurationDHCP") << std::endl;
00192           std::cout << "Link local on/off:        " << rcg::getString(nodemap, "GevCurrentIPConfigurationLLA") << std::endl;
00193           std::cout << std::endl;
00194 
00195           std::cout << "PTP:                      " << rcg::getString(nodemap, "GevIEEE1588") << std::endl;
00196           std::cout << "PTP status:               " << rcg::getString(nodemap, "GevIEEE1588Status") << std::endl;
00197 
00198           dev->close();
00199         }
00200         else
00201         {
00202           std::cerr << "Cannot find device: " << argv[1] << std::endl;
00203         }
00204       }
00205     }
00206     else
00207     {
00208       std::cout << argv[0] << " -l|([interface-id>:]<device-id> <options>)" << std::endl;
00209       std::cout << std::endl;
00210       std::cout << "Configuration of a device via GenICam" << std::endl;
00211       std::cout << std::endl;
00212       std::cout << "-n <id>: Set user defined id" << std::endl;
00213       std::cout << "-d 1|0:  Switch DHCP on or off" << std::endl;
00214       std::cout << "-p 1|0:  Switch persistent IP on or off" << std::endl;
00215       std::cout << "-t 1|0:  Switch precision time protocol (ptp) on or off" << std::endl;
00216       std::cout << "-i <ip>: Set persistent IP address" << std::endl;
00217       std::cout << "-s <ip>: Set subnet mask for persistent IP address" << std::endl;
00218       std::cout << "-g <ip>: Set default gateway for persistent IP address" << std::endl;
00219       std::cout << std::endl;
00220       std::cout << "<key>=<value>: Set GenICam key to given value." << std::endl;
00221     }
00222   }
00223   catch (const std::exception &ex)
00224   {
00225     std::cerr << ex.what() << std::endl;
00226   }
00227 
00228   rcg::System::clearSystems();
00229 
00230   return 0;
00231 }


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:02