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


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