gc_config.cc
Go to the documentation of this file.
1 /*
2  * This file is part of the rc_genicam_api package.
3  *
4  * Copyright (c) 2017 Roboception GmbH
5  * All rights reserved
6  *
7  * Author: Heiko Hirschmueller
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright notice,
13  * this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright notice,
16  * this list of conditions and the following disclaimer in the documentation
17  * and/or other materials provided with the distribution.
18  *
19  * 3. Neither the name of the copyright holder nor the names of its contributors
20  * may be used to endorse or promote products derived from this software without
21  * specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  */
35 
36 #include <rc_genicam_api/system.h>
38 #include <rc_genicam_api/device.h>
39 #include <rc_genicam_api/config.h>
40 
41 #include <iostream>
42 
43 int main(int argc, char *argv[])
44 {
45  int ret=0;
46 
47  try
48  {
49  if (argc > 1 && std::string(argv[1]) != "-h")
50  {
51  // list all available GigE Vision devices
52 
53  if (std::string(argv[1]) == "-l")
54  {
55  std::cout << "Available GigE Vision devices:" << std::endl;
56 
57  std::vector<std::shared_ptr<rcg::System> > system=rcg::System::getSystems();
58 
59  for (size_t i=0; i<system.size(); i++)
60  {
61  system[i]->open();
62 
63  std::vector<std::shared_ptr<rcg::Interface> > interf=system[i]->getInterfaces();
64 
65  for (size_t k=0; k<interf.size(); k++)
66  {
67  interf[k]->open();
68 
69  std::vector<std::shared_ptr<rcg::Device> > device=interf[k]->getDevices();
70 
71  for (size_t j=0; j<device.size(); j++)
72  {
73  if (device[j]->getTLType() == "GEV")
74  {
75  std::cout << " " << interf[k]->getID() << ":" << device[j]->getSerialNumber() << " (";
76 
77  std::string uname=device[j]->getDisplayName();
78 
79  if (uname.size() > 0)
80  {
81  std::cout << uname << ", ";
82  }
83 
84  std::cout << device[j]->getID() << ")" << std::endl;
85  }
86  }
87 
88  interf[k]->close();
89  }
90 
91  system[i]->close();
92  }
93  }
94  else
95  {
96  // discover and open a specific device
97 
98  int i=1;
99  std::shared_ptr<rcg::Device> dev=rcg::getDevice(argv[i++]);
100 
101  if (dev != 0)
102  {
103  bool showsummary=false;
104  bool iponly=false;
105 
106  // open device with control or read only access, depending on the
107  // given parameters
108 
109  if (i == argc || (i+1 == argc && std::string(argv[i]) == "--iponly"))
110  {
111  dev->open(rcg::Device::READONLY);
112  showsummary=true;
113  }
114  else
115  {
116  dev->open(rcg::Device::CONTROL);
117  }
118 
119  // change setting according to given parameters
120 
121  std::shared_ptr<GenApi::CNodeMapRef> nodemap=dev->getRemoteNodeMap();
122 
123  while (i < argc)
124  {
125  std::string p=argv[i++];
126 
127  if (p == "--iponly")
128  {
129  iponly=true;
130  }
131  else if (p[0] == '-' && i < argc)
132  {
133  showsummary=true;
134 
135  if (p == "-n") // change user defined device name
136  {
137  rcg::setString(nodemap, "DeviceUserID", argv[i++], true);
138  }
139  else if (p == "-d") // switch dhcp on or off
140  {
141  rcg::setString(nodemap, "GevCurrentIPConfigurationDHCP", argv[i++], true);
142  }
143  else if (p == "-p") // switch persistent IP on or off
144  {
145  rcg::setString(nodemap, "GevCurrentIPConfigurationPersistentIP", argv[i++], true);
146  }
147  else if (p == "-t") // switch precision time protocol on or off
148  {
149  rcg::setString(nodemap, "PtpEnable", argv[i++], true);
150  }
151  else if (p == "-i") // set persistent IP address
152  {
153  rcg::setIPV4Address(nodemap, "GevPersistentIPAddress", argv[i++], true);
154  }
155  else if (p == "-s") // set persistent subnet mask
156  {
157  rcg::setIPV4Address(nodemap, "GevPersistentSubnetMask", argv[i++], true);
158  }
159  else if (p == "-g") // set persistent gateway
160  {
161  rcg::setIPV4Address(nodemap, "GevPersistentDefaultGateway", argv[i++], true);
162  }
163  else
164  {
165  std::cerr << "Unknown parameter: " << p << std::endl;
166  exit(1);
167  }
168  }
169  else if (p.find('=') != std::string::npos)
170  {
171  // split argument in key and value
172 
173  size_t k=p.find('=');
174  std::string value=p.substr(k+1);
175  std::string key=p.substr(0, k);
176 
177  // set key=value pair through GenICam
178 
179  rcg::setString(nodemap, key.c_str(), value.c_str(), true);
180  }
181  else
182  {
183  // call the command
184  rcg::callCommand(nodemap, p.c_str(), true);
185  }
186  }
187 
188  // print network configuration of the device
189 
190  if (iponly)
191  {
192  std::cout << rcg::getString(nodemap, "GevCurrentIPAddress") << std::endl;
193  }
194  else if (showsummary)
195  {
196  std::cout << "ID: " << dev->getParent()->getID() << ":"
197  << rcg::getString(nodemap, "DeviceID") << std::endl;
198  std::cout << "GenTL ID: " << dev->getID() << std::endl;
199  std::cout << "Serial number: " << rcg::getString(nodemap, "DeviceID") << std::endl;
200  std::cout << "User defined ID: " << rcg::getString(nodemap, "DeviceUserID") << std::endl;
201  std::cout << "MAC Address: " << rcg::getString(nodemap, "GevMACAddress") << std::endl;
202  std::cout << std::endl;
203 
204  std::cout << "Current IP: " << rcg::getString(nodemap, "GevCurrentIPAddress") << std::endl;
205  std::cout << "Current subnet mask: " << rcg::getString(nodemap, "GevCurrentSubnetMask") << std::endl;
206  std::cout << "Current gateway: " << rcg::getString(nodemap, "GevCurrentDefaultGateway") << std::endl;
207  std::cout << std::endl;
208 
209  std::cout << "Persistent IP on/off: " << rcg::getString(nodemap, "GevCurrentIPConfigurationPersistentIP") << std::endl;
210  std::cout << " Persistent IP: " << rcg::getString(nodemap, "GevPersistentIPAddress") << std::endl;
211  std::cout << " Persistent subnet mask: " << rcg::getString(nodemap, "GevPersistentSubnetMask") << std::endl;
212  std::cout << " Persistent gateway: " << rcg::getString(nodemap, "GevPersistentDefaultGateway") << std::endl;
213  std::cout << "DHCP on/off: " << rcg::getString(nodemap, "GevCurrentIPConfigurationDHCP") << std::endl;
214  std::cout << "Link local on/off: " << rcg::getString(nodemap, "GevCurrentIPConfigurationLLA") << std::endl;
215  std::cout << std::endl;
216 
217  std::cout << "PTP: " << rcg::getString(nodemap, "PtpEnable") << std::endl;
218  std::cout << "PTP status: " << rcg::getString(nodemap, "PtpStatus") << std::endl;
219  std::cout << "PTP offset: " << rcg::getInteger(nodemap, "PtpOffsetFromMaster") << " ns" << std::endl;
220  }
221 
222  dev->close();
223  }
224  else
225  {
226  std::cerr << "Cannot find device: " << argv[1] << std::endl;
227  ret=1;
228  }
229  }
230  }
231  else
232  {
233  std::cout << argv[0] << " -h | -l | ([<interface-id>:]<device-id> <options> ...)" << std::endl;
234  std::cout << std::endl;
235  std::cout << "Configuration of a GigE Vision device via GenICam." << std::endl;
236  std::cout << std::endl;
237  std::cout << "-h Prints help information and exits" << std::endl;
238  std::cout << "-l Lists all available GigE Vision devices" << std::endl;
239  std::cout << std::endl;
240  std::cout << "Parameters:" << std::endl;
241  std::cout << "<interface-id> Optional GenICam ID of interface for connecting to the device" << std::endl;
242  std::cout << "<device-id> GenICam device ID, serial number or user defined name of device" << std::endl;
243  std::cout << std::endl;
244  std::cout << "Options:" << std::endl;
245  std::cout << "-n <id> Set user defined id" << std::endl;
246  std::cout << "-d 1|0 Switch DHCP on or off" << std::endl;
247  std::cout << "-p 1|0 Switch persistent IP on or off" << std::endl;
248  std::cout << "-t 1|0 Switch precision time protocol (ptp) on or off" << std::endl;
249  std::cout << "-i <ip> Set persistent IP address" << std::endl;
250  std::cout << "-s <ip> Set subnet mask for persistent IP address" << std::endl;
251  std::cout << "-g <ip> Set default gateway for persistent IP address" << std::endl;
252  std::cout << "--iponly Show current IP of device instead of full summary" << std::endl;
253  std::cout << "<key>=<value> Optional GenICam parameters to be changed in the given order" << std::endl;
254  ret=1;
255  }
256  }
257  catch (const std::exception &ex)
258  {
259  std::cerr << ex.what() << std::endl;
260  ret=2;
261  }
262 
264 
265  return ret;
266 }
bool setIPV4Address(const std::shared_ptr< GenApi::CNodeMapRef > &nodemap, const char *name, const char *value, bool exception)
Set the value of an integer feature of the given nodemap from an IP address.
Definition: config.cc:191
std::shared_ptr< Device > getDevice(const char *id)
Searches across all transport layers and interfaces for a device.
Definition: device.cc:469
static std::vector< std::shared_ptr< System > > getSystems()
Returns a list of systems (i.e.
Definition: system.cc:116
int main(int argc, char *argv[])
Definition: gc_config.cc:43
int64_t getInteger(const std::shared_ptr< GenApi::CNodeMapRef > &nodemap, const char *name, int64_t *vmin, int64_t *vmax, bool exception, bool igncache)
Get the value of an integer feature of the given nodemap.
Definition: config.cc:542
static void clearSystems()
Clears the internal list of systems.
Definition: system.cc:213
bool setString(const std::shared_ptr< GenApi::CNodeMapRef > &nodemap, const char *name, const char *value, bool exception)
Set the value of a feature of the given nodemap.
Definition: config.cc:351
bool callCommand(const std::shared_ptr< GenApi::CNodeMapRef > &nodemap, const char *name, bool exception)
Calls the given command.
Definition: config.cc:53
std::string getString(const std::shared_ptr< GenApi::CNodeMapRef > &nodemap, const char *name, bool exception, bool igncache)
Get the value of a feature of the given nodemap.
Definition: config.cc:773


rc_genicam_api
Author(s): Heiko Hirschmueller
autogenerated on Wed Mar 17 2021 02:48:40