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  // default interface is 0 (allowed to fail)
124  rcg::setInteger(nodemap, "GevInterfaceSelector", 0);
125 
126  while (i < argc)
127  {
128  std::string p=argv[i++];
129 
130  if (p == "--iponly")
131  {
132  iponly=true;
133  }
134  else if (p[0] == '-' && i < argc)
135  {
136  showsummary=true;
137 
138  if (p == "-n") // change user defined device name
139  {
140  rcg::setString(nodemap, "DeviceUserID", argv[i++], true);
141  }
142  else if (p == "-f") // switch to specified interface
143  {
144  rcg::setString(nodemap, "GevInterfaceSelector", argv[i++], true);
145  }
146  else if (p == "-d") // switch dhcp on or off
147  {
148  rcg::setString(nodemap, "GevCurrentIPConfigurationDHCP", argv[i++], true);
149  }
150  else if (p == "-p") // switch persistent IP on or off
151  {
152  rcg::setString(nodemap, "GevCurrentIPConfigurationPersistentIP", argv[i++], true);
153  }
154  else if (p == "-t") // switch precision time protocol on or off
155  {
156  rcg::setString(nodemap, "PtpEnable", argv[i++], true);
157  }
158  else if (p == "-i") // set persistent IP address
159  {
160  rcg::setIPV4Address(nodemap, "GevPersistentIPAddress", argv[i++], true);
161  }
162  else if (p == "-s") // set persistent subnet mask
163  {
164  rcg::setIPV4Address(nodemap, "GevPersistentSubnetMask", argv[i++], true);
165  }
166  else if (p == "-g") // set persistent gateway
167  {
168  rcg::setIPV4Address(nodemap, "GevPersistentDefaultGateway", argv[i++], true);
169  }
170  else
171  {
172  std::cerr << "Unknown parameter: " << p << std::endl;
173  exit(1);
174  }
175  }
176  else if (p.find('=') != std::string::npos)
177  {
178  // split argument in key and value
179 
180  size_t k=p.find('=');
181  std::string value=p.substr(k+1);
182  std::string key=p.substr(0, k);
183 
184  // set key=value pair through GenICam
185 
186  rcg::setString(nodemap, key.c_str(), value.c_str(), true);
187  }
188  else
189  {
190  // call the command
191  rcg::callCommand(nodemap, p.c_str(), true);
192  }
193  }
194 
195  // print network configuration of the device
196 
197  if (iponly)
198  {
199  std::cout << rcg::getString(nodemap, "GevCurrentIPAddress") << std::endl;
200  }
201  else if (showsummary)
202  {
203  std::cout << "ID: " << dev->getParent()->getID() << ":"
204  << rcg::getString(nodemap, "DeviceID") << std::endl;
205  std::cout << "GenTL ID: " << dev->getID() << std::endl;
206  std::cout << "Serial number: " << rcg::getString(nodemap, "DeviceID") << std::endl;
207  std::cout << "User defined ID: " << rcg::getString(nodemap, "DeviceUserID") << std::endl;
208  std::cout << std::endl;
209 
210  int64_t n=0;
211  rcg::getInteger(nodemap, "GevInterfaceSelector", 0, &n);
212 
213  try
214  {
215  // just test if GEV interface parameters are available
216  rcg::getString(nodemap, "GevCurrentIPAddress", true);
217 
218  for (int64_t i=0; i<=n; i++)
219  {
220  rcg::setInteger(nodemap, "GevInterfaceSelector", i);
221 
222  std::cout << "Interface " << i << ":" << std::endl;
223 
224  std::cout << " MAC Address: " << rcg::getString(nodemap, "GevMACAddress") << std::endl;
225  std::cout << std::endl;
226 
227  std::cout << " Current IP: " << rcg::getString(nodemap, "GevCurrentIPAddress") << std::endl;
228  std::cout << " Current subnet mask: " << rcg::getString(nodemap, "GevCurrentSubnetMask") << std::endl;
229  std::cout << " Current gateway: " << rcg::getString(nodemap, "GevCurrentDefaultGateway") << std::endl;
230  std::cout << std::endl;
231 
232  std::cout << " Persistent IP on/off: " << rcg::getString(nodemap, "GevCurrentIPConfigurationPersistentIP") << std::endl;
233  std::cout << " Persistent IP: " << rcg::getString(nodemap, "GevPersistentIPAddress") << std::endl;
234  std::cout << " Persistent subnet mask: " << rcg::getString(nodemap, "GevPersistentSubnetMask") << std::endl;
235  std::cout << " Persistent gateway: " << rcg::getString(nodemap, "GevPersistentDefaultGateway") << std::endl;
236  std::cout << " DHCP on/off: " << rcg::getString(nodemap, "GevCurrentIPConfigurationDHCP") << std::endl;
237  std::cout << " Link local on/off: " << rcg::getString(nodemap, "GevCurrentIPConfigurationLLA") << std::endl;
238  std::cout << std::endl;
239  }
240  }
241  catch (const std::exception &)
242  {
243  std::cout << "Gev interface parameters are not available" << std::endl;
244  std::cout << std::endl;
245  }
246 
247  try
248  {
249  // just test if Ptp parameters are available
250  rcg::getString(nodemap, "PtpEnable", true);
251 
252  std::cout << "PTP: " << rcg::getString(nodemap, "PtpEnable") << std::endl;
253  std::cout << "PTP status: " << rcg::getString(nodemap, "PtpStatus") << std::endl;
254  std::cout << "PTP offset: " << rcg::getInteger(nodemap, "PtpOffsetFromMaster") << " ns" << std::endl;
255  }
256  catch (const std::exception &)
257  {
258  std::cout << "Ptp parameters are not available" << std::endl;
259  std::cout << std::endl;
260  }
261  }
262 
263  dev->close();
264  }
265  else
266  {
267  std::cerr << "Cannot find device: " << argv[1] << std::endl;
268  ret=1;
269  }
270  }
271  }
272  else
273  {
274  std::cout << argv[0] << " -h | -l | ([<interface-id>:]<device-id> <options> ...)" << std::endl;
275  std::cout << std::endl;
276  std::cout << "Configuration of a GigE Vision device via GenICam." << std::endl;
277  std::cout << std::endl;
278  std::cout << "-h Prints help information and exits" << std::endl;
279  std::cout << "-l Lists all available GigE Vision devices" << std::endl;
280  std::cout << std::endl;
281  std::cout << "Parameters:" << std::endl;
282  std::cout << "<interface-id> Optional GenICam ID of interface for connecting to the device" << std::endl;
283  std::cout << "<device-id> GenICam device ID, serial number or user defined name of device" << std::endl;
284  std::cout << std::endl;
285  std::cout << "Options:" << std::endl;
286  std::cout << "-n <id> Set user defined id" << std::endl;
287  std::cout << "-f <n> Apply all further IP settings to interface with specified number. Default: 0" << std::endl;
288  std::cout << "-d 1|0 Switch DHCP on or off" << std::endl;
289  std::cout << "-p 1|0 Switch persistent IP on or off" << std::endl;
290  std::cout << "-t 1|0 Switch precision time protocol (ptp) on or off" << std::endl;
291  std::cout << "-i <ip> Set persistent IP address" << std::endl;
292  std::cout << "-s <ip> Set subnet mask for persistent IP address" << std::endl;
293  std::cout << "-g <ip> Set default gateway for persistent IP address" << std::endl;
294  std::cout << "--iponly Show current IP of device instead of full summary" << std::endl;
295  std::cout << "<key>=<value> Optional GenICam parameters to be changed in the given order" << std::endl;
296  ret=1;
297  }
298  }
299  catch (const std::exception &ex)
300  {
301  std::cerr << ex.what() << std::endl;
302  ret=2;
303  }
304 
306 
307  return ret;
308 }
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:198
std::shared_ptr< Device > getDevice(const char *id)
Searches across all transport layers and interfaces for a device.
Definition: device.cc:480
static std::vector< std::shared_ptr< System > > getSystems()
This function creates systems for all producers that can be found.
Definition: system.cc:201
int main(int argc, char *argv[])
Definition: gc_config.cc:43
__int64 int64_t
Definition: config-win32.h:21
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:563
static void clearSystems()
Clears the internal list of systems.
Definition: system.cc:282
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:365
bool callCommand(const std::shared_ptr< GenApi::CNodeMapRef > &nodemap, const char *name, bool exception)
Calls the given command.
Definition: config.cc:60
bool setInteger(const std::shared_ptr< GenApi::CNodeMapRef > &nodemap, const char *name, int64_t value, bool exception)
Set the value of an integer feature of the given nodemap.
Definition: config.cc:152
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:794


rc_genicam_api
Author(s): Heiko Hirschmueller
autogenerated on Sun Jun 18 2023 02:43:55