All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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-2024 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 readonly=false;
105  bool iponly=false;
106 
107  // open device with control or read only access, depending on the
108  // given parameters
109 
110  if (i == argc || (i+1 == argc && std::string(argv[i]) == "--iponly"))
111  {
112  try
113  {
114  // try to open with control to also show PTP status, which
115  // requires calling data latch
116  dev->open(rcg::Device::CONTROL);
117  }
118  catch (const std::exception &)
119  {
120  // fallback if another application is blocking the device, which
121  // means that PTP status cannot be shown
122  dev->open(rcg::Device::READONLY);
123  readonly=true;
124  }
125 
126  showsummary=true;
127  }
128  else
129  {
130  dev->open(rcg::Device::CONTROL);
131  }
132 
133  // change setting according to given parameters
134 
135  std::shared_ptr<GenApi::CNodeMapRef> nodemap=dev->getRemoteNodeMap();
136 
137  // default interface is 0 (allowed to fail)
138  rcg::setInteger(nodemap, "GevInterfaceSelector", 0);
139 
140  while (i < argc)
141  {
142  std::string p=argv[i++];
143 
144  if (p == "--iponly")
145  {
146  iponly=true;
147  }
148  else if (p[0] == '-' && i < argc)
149  {
150  showsummary=true;
151 
152  if (p == "-n") // change user defined device name
153  {
154  rcg::setString(nodemap, "DeviceUserID", argv[i++], true);
155  }
156  else if (p == "-f") // switch to specified interface
157  {
158  rcg::setString(nodemap, "GevInterfaceSelector", argv[i++], true);
159  }
160  else if (p == "-d") // switch dhcp on or off
161  {
162  rcg::setString(nodemap, "GevCurrentIPConfigurationDHCP", argv[i++], true);
163  }
164  else if (p == "-p") // switch persistent IP on or off
165  {
166  rcg::setString(nodemap, "GevCurrentIPConfigurationPersistentIP", argv[i++], true);
167  }
168  else if (p == "-t") // switch precision time protocol on or off
169  {
170  rcg::setString(nodemap, "PtpEnable", argv[i++], true);
171  }
172  else if (p == "-i") // set persistent IP address
173  {
174  rcg::setIPV4Address(nodemap, "GevPersistentIPAddress", argv[i++], true);
175  }
176  else if (p == "-s") // set persistent subnet mask
177  {
178  rcg::setIPV4Address(nodemap, "GevPersistentSubnetMask", argv[i++], true);
179  }
180  else if (p == "-g") // set persistent gateway
181  {
182  rcg::setIPV4Address(nodemap, "GevPersistentDefaultGateway", argv[i++], true);
183  }
184  else
185  {
186  std::cerr << "Unknown parameter: " << p << std::endl;
187  exit(1);
188  }
189  }
190  else if (p.size() > 0 && p[0] == '@')
191  {
192  // load streamable parameters from file into nodemap
193 
194  try
195  {
196  rcg::loadStreamableParameters(nodemap, p.substr(1).c_str(), true);
197  }
198  catch (const std::exception &ex)
199  {
200  std::cerr << "Warning: Loading of parameters from file '" << p.substr(1) <<
201  "' failed at least partially" << std::endl;
202  std::cerr << ex.what() << std::endl;
203  }
204  }
205  else if (p.find('=') != std::string::npos)
206  {
207  // split argument in key and value
208 
209  size_t k=p.find('=');
210  std::string value=p.substr(k+1);
211  std::string key=p.substr(0, k);
212 
213  // set key=value pair through GenICam
214 
215  rcg::setString(nodemap, key.c_str(), value.c_str(), true);
216  }
217  else
218  {
219  // call the command
220  rcg::callCommand(nodemap, p.c_str(), true);
221  }
222  }
223 
224  // print network configuration of the device
225 
226  if (iponly)
227  {
228  std::cout << rcg::getString(nodemap, "GevCurrentIPAddress") << std::endl;
229  }
230  else if (showsummary)
231  {
232  std::cout << "ID: " << dev->getParent()->getID() << ":"
233  << rcg::getString(nodemap, "DeviceID") << std::endl;
234  std::cout << "GenTL ID: " << dev->getID() << std::endl;
235  std::cout << "Serial number: " << rcg::getString(nodemap, "DeviceID") << std::endl;
236  std::cout << "User defined ID: " << rcg::getString(nodemap, "DeviceUserID") << std::endl;
237  std::cout << std::endl;
238 
239  int64_t n=0;
240  rcg::getInteger(nodemap, "GevInterfaceSelector", 0, &n);
241 
242  try
243  {
244  // just test if GEV interface parameters are available
245  rcg::getString(nodemap, "GevCurrentIPAddress", true);
246 
247  for (int64_t i=0; i<=n; i++)
248  {
249  rcg::setInteger(nodemap, "GevInterfaceSelector", i);
250 
251  std::cout << "Interface " << i << ":" << std::endl;
252 
253  std::cout << " MAC Address: " << rcg::getString(nodemap, "GevMACAddress") << std::endl;
254  std::cout << std::endl;
255 
256  std::cout << " Current IP: " << rcg::getString(nodemap, "GevCurrentIPAddress") << std::endl;
257  std::cout << " Current subnet mask: " << rcg::getString(nodemap, "GevCurrentSubnetMask") << std::endl;
258  std::cout << " Current gateway: " << rcg::getString(nodemap, "GevCurrentDefaultGateway") << std::endl;
259  std::cout << std::endl;
260 
261  std::cout << " Persistent IP on/off: " << rcg::getString(nodemap, "GevCurrentIPConfigurationPersistentIP") << std::endl;
262  std::cout << " Persistent IP: " << rcg::getString(nodemap, "GevPersistentIPAddress") << std::endl;
263  std::cout << " Persistent subnet mask: " << rcg::getString(nodemap, "GevPersistentSubnetMask") << std::endl;
264  std::cout << " Persistent gateway: " << rcg::getString(nodemap, "GevPersistentDefaultGateway") << std::endl;
265  std::cout << " DHCP on/off: " << rcg::getString(nodemap, "GevCurrentIPConfigurationDHCP") << std::endl;
266  std::cout << " Link local on/off: " << rcg::getString(nodemap, "GevCurrentIPConfigurationLLA") << std::endl;
267  std::cout << std::endl;
268  }
269  }
270  catch (const std::exception &)
271  {
272  std::cout << "Gev interface parameters are not available" << std::endl;
273  std::cout << std::endl;
274  }
275 
276  try
277  {
278  // just test if Ptp parameters are available
279  rcg::getString(nodemap, "PtpEnable", true);
280 
281  if (!readonly)
282  {
283  rcg::callCommand(nodemap, "PtpDataSetLatch");
284 
285  std::cout << "PTP: " << rcg::getString(nodemap, "PtpEnable") << std::endl;
286  std::cout << "PTP status: " << rcg::getString(nodemap, "PtpStatus") << std::endl;
287  std::cout << "PTP offset: " << rcg::getInteger(nodemap, "PtpOffsetFromMaster") << " ns" << std::endl;
288  }
289  else
290  {
291  std::cout << "Ptp cannot be shown due to another application with control access." << std::endl;
292  std::cout << std::endl;
293  }
294  }
295  catch (const std::exception &)
296  {
297  std::cout << "Ptp parameters are not available" << std::endl;
298  std::cout << std::endl;
299  }
300  }
301 
302  dev->close();
303  }
304  else
305  {
306  std::cerr << "Cannot find device: " << argv[1] << std::endl;
307  ret=1;
308  }
309  }
310  }
311  else
312  {
313  std::cout << argv[0] << " -h | -l | ([<interface-id>:]<device-id> <options> ...)" << std::endl;
314  std::cout << std::endl;
315  std::cout << "Configuration of a GigE Vision device via GenICam." << std::endl;
316  std::cout << std::endl;
317  std::cout << "-h Prints help information and exits" << std::endl;
318  std::cout << "-l Lists all available GigE Vision devices" << std::endl;
319  std::cout << std::endl;
320  std::cout << "Parameters:" << std::endl;
321  std::cout << "<interface-id> Optional GenICam ID of interface for connecting to the device" << std::endl;
322  std::cout << "<device-id> GenICam device ID, serial number or user defined name of device" << std::endl;
323  std::cout << std::endl;
324  std::cout << "Options:" << std::endl;
325  std::cout << "-n <id> Set user defined id" << std::endl;
326  std::cout << "-f <n> Apply all further IP settings to interface with specified number. Default: 0" << std::endl;
327  std::cout << "-d 1|0 Switch DHCP on or off" << std::endl;
328  std::cout << "-p 1|0 Switch persistent IP on or off" << std::endl;
329  std::cout << "-t 1|0 Switch precision time protocol (ptp) on or off" << std::endl;
330  std::cout << "-i <ip> Set persistent IP address" << std::endl;
331  std::cout << "-s <ip> Set subnet mask for persistent IP address" << std::endl;
332  std::cout << "-g <ip> Set default gateway for persistent IP address" << std::endl;
333  std::cout << "--iponly Show current IP of device instead of full summary" << std::endl;
334  std::cout << "@<file> Optional file with parameters as store with parameter 'gc_info -p ...'" << std::endl;
335  std::cout << "<key>=<value> Optional GenICam parameters to be changed in the given order" << std::endl;
336  ret=1;
337  }
338  }
339  catch (const std::exception &ex)
340  {
341  std::cerr << ex.what() << std::endl;
342  ret=2;
343  }
344 
346 
347  return ret;
348 }
rcg::setIPV4Address
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:199
rcg::getDevice
std::shared_ptr< Device > getDevice(const char *id, uint64_t timeout)
Searches across all transport layers and interfaces for a device.
Definition: device.cc:726
device.h
main
int main(int argc, char *argv[])
Definition: gc_config.cc:43
rcg::callCommand
bool callCommand(const std::shared_ptr< GenApi::CNodeMapRef > &nodemap, const char *name, bool exception)
Calls the given command.
Definition: config.cc:61
rcg::System::clearSystems
static void clearSystems()
Clears the internal list of systems.
Definition: system.cc:282
rcg::loadStreamableParameters
bool loadStreamableParameters(const std::shared_ptr< GenApi::CNodeMapRef > &nodemap, const char *name, bool exception)
Load all streamable parameters from file into the nodemap.
Definition: config.cc:1267
interface.h
rcg::setInteger
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:153
rcg::Device::CONTROL
@ CONTROL
Definition: device.h:60
system.h
config.h
rcg::setString
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:413
int64_t
__int64 int64_t
Definition: config-win32.h:21
rcg::getInteger
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:634
rcg::getString
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:918
rcg::System::getSystems
static std::vector< std::shared_ptr< System > > getSystems()
This function creates systems for all producers that can be found.
Definition: system.cc:201
rcg::Device::READONLY
@ READONLY
Definition: device.h:60


rc_genicam_api
Author(s): Heiko Hirschmueller
autogenerated on Wed Dec 4 2024 03:10:11