gc_info.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/stream.h>
42 
43 #include <iostream>
44 
45 int main(int argc, char *argv[])
46 {
47  int ret=0;
48 
49  try
50  {
51  if (argc >= 2 && std::string(argv[1]) != "-h")
52  {
53  if (std::string(argv[1]) == "-l")
54  {
55  // list all systems, interfaces and devices
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::cout << "Transport Layer " << system[i]->getID() << std::endl;
64  std::cout << "Vendor: " << system[i]->getVendor() << std::endl;
65  std::cout << "Model: " << system[i]->getModel() << std::endl;
66  std::cout << "Vendor version: " << system[i]->getVersion() << std::endl;
67  std::cout << "TL type: " << system[i]->getTLType() << std::endl;
68  std::cout << "Name: " << system[i]->getName() << std::endl;
69  std::cout << "Pathname: " << system[i]->getPathname() << std::endl;
70  std::cout << "Display name: " << system[i]->getDisplayName() << std::endl;
71  std::cout << "GenTL version " << system[i]->getMajorVersion() << "."
72  << system[i]->getMinorVersion() << std::endl;
73  std::cout << std::endl;
74 
75  std::vector<std::shared_ptr<rcg::Interface> > interf=system[i]->getInterfaces();
76 
77  for (size_t k=0; k<interf.size(); k++)
78  {
79  interf[k]->open();
80 
81  std::cout << " Interface " << interf[k]->getID() << std::endl;
82  std::cout << " Display name: " << interf[k]->getDisplayName() << std::endl;
83  std::cout << " TL type: " << interf[k]->getTLType() << std::endl;
84  std::cout << std::endl;
85 
86  std::vector<std::shared_ptr<rcg::Device> > device=interf[k]->getDevices();
87 
88  for (size_t j=0; j<device.size(); j++)
89  {
90  std::cout << " Device " << device[j]->getID() << std::endl;
91  std::cout << " Vendor: " << device[j]->getVendor() << std::endl;
92  std::cout << " Model: " << device[j]->getModel() << std::endl;
93  std::cout << " TL type: " << device[j]->getTLType() << std::endl;
94  std::cout << " Display name: " << device[j]->getDisplayName() << std::endl;
95  std::cout << " User defined name: " << device[j]->getUserDefinedName() << std::endl;
96  std::cout << " Access status: " << device[j]->getAccessStatus() << std::endl;
97  std::cout << " Serial number: " << device[j]->getSerialNumber() << std::endl;
98  std::cout << " Version: " << device[j]->getVersion() << std::endl;
99  std::cout << " TS Frequency: " << device[j]->getTimestampFrequency() << std::endl;
100  std::cout << std::endl;
101  }
102 
103  interf[k]->close();
104  }
105 
106  system[i]->close();
107  }
108  }
109  else if (std::string(argv[1]) == "-s")
110  {
111  // list all systems, interfaces and devices
112 
113  std::vector<std::shared_ptr<rcg::System> > system=rcg::System::getSystems();
114 
115  std::cout << "Interface\tSerial Number\tVendor\tModel\tName" << std::endl;
116 
117  for (size_t i=0; i<system.size(); i++)
118  {
119  system[i]->open();
120 
121  std::vector<std::shared_ptr<rcg::Interface> > interf=system[i]->getInterfaces();
122 
123  for (size_t k=0; k<interf.size(); k++)
124  {
125  interf[k]->open();
126 
127  std::vector<std::shared_ptr<rcg::Device> > device=interf[k]->getDevices();
128 
129  for (size_t j=0; j<device.size(); j++)
130  {
131  std::cout << interf[k]->getID() << '\t'
132  << device[j]->getSerialNumber() << '\t'
133  << device[j]->getVendor() << '\t'
134  << device[j]->getModel() << '\t'
135  << device[j]->getDisplayName() << std::endl;
136  }
137 
138  interf[k]->close();
139  }
140 
141  system[i]->close();
142  }
143  }
144  else
145  {
146  int k=1;
147 
148  // get parameters, if any
149 
150  const char *xml=0;
151  if (k+1 < argc && std::string(argv[k]) == "-o")
152  {
153  k++;
154  xml=argv[k++];
155 
156  if (std::string(xml) == ".")
157  {
158  xml="";
159  }
160  }
161 
162  bool edit=false;
163  if (k < argc && std::string(argv[k]) == "-e")
164  {
165  k++;
166  edit=true;
167  }
168 
169  if (k < argc)
170  {
171  // separate optional node name from device id
172 
173  std::string devid=argv[k++];
174  std::string node="Root";
175  int depth=1000;
176 
177  {
178  size_t j=devid.find('?');
179 
180  if (j != std::string::npos)
181  {
182  node=devid.substr(j+1);
183  devid=devid.substr(0, j);
184  depth=1;
185 
186  if (node.size() == 0)
187  {
188  node="Root";
189  }
190  }
191  }
192 
193  // find specific device accross all systems and interfaces
194 
195  std::shared_ptr<rcg::Device> dev=rcg::getDevice(devid.c_str());
196 
197  if (dev)
198  {
199  // open device and optionally change some settings
200 
201  if (k < argc || edit)
202  {
203  dev->open(rcg::Device::CONTROL);
204  }
205  else
206  {
207  dev->open(rcg::Device::READONLY);
208  }
209 
210  std::shared_ptr<GenApi::CNodeMapRef> nodemap=dev->getRemoteNodeMap(xml);
211 
212  if (nodemap)
213  {
214  while (k < argc)
215  {
216  std::string p=argv[k++];
217 
218  if (p.find('=') != std::string::npos)
219  {
220  // split argument in key and value
221 
222  size_t j=p.find('=');
223  std::string value=p.substr(j+1);
224  std::string key=p.substr(0, j);
225 
226  // set key=value pair through GenICam
227 
228  rcg::setString(nodemap, key.c_str(), value.c_str(), true);
229  }
230  else
231  {
232  // call the command
233  rcg::callCommand(nodemap, p.c_str(), true);
234  }
235  }
236 
237  if (edit)
238  {
239  if (!rcg::editNodemap(nodemap, node.c_str()))
240  {
241  std::cerr << "Unknown node: " << node << std::endl;
242  ret=1;
243  }
244  }
245  else if (depth > 1)
246  {
247  // report all features
248 
249  std::cout << "Device: " << dev->getID() << std::endl;
250  std::cout << "Vendor: " << dev->getVendor() << std::endl;
251  std::cout << "Model: " << dev->getModel() << std::endl;
252  std::cout << "TL type: " << dev->getTLType() << std::endl;
253  std::cout << "Display name: " << dev->getDisplayName() << std::endl;
254  std::cout << "User defined name: " << dev->getUserDefinedName() << std::endl;
255  std::cout << "Serial number: " << dev->getSerialNumber() << std::endl;
256  std::cout << "Version: " << dev->getVersion() << std::endl;
257  std::cout << "TS Frequency: " << dev->getTimestampFrequency() << std::endl;
258  std::cout << std::endl;
259 
260  std::vector<std::shared_ptr<rcg::Stream> > stream=dev->getStreams();
261 
262  std::cout << "Available streams:" << std::endl;
263  for (size_t i=0; i<stream.size(); i++)
264  {
265  std::cout << " Stream ID: " << stream[i]->getID() << std::endl;
266  }
267 
268  std::cout << std::endl;
269 
270  std::cout << "Available features:" << std::endl;
271  rcg::printNodemap(nodemap, node.c_str(), depth, true);
272  }
273  else
274  {
275  // report requested node only
276 
277  if (!rcg::printNodemap(nodemap, node.c_str(), depth, true))
278  {
279  std::cerr << "Unknown node: " << node << std::endl;
280  ret=1;
281  }
282  }
283  }
284  else
285  {
286  std::cerr << "Nodemap not available!" << std::endl;
287  }
288 
289  dev->close();
290  }
291  else
292  {
293  std::cerr << "Device '" << devid << "' not found!" << std::endl;
294  ret=1;
295  }
296  }
297  else
298  {
299  std::cerr << "Device name not given!" << std::endl;
300  ret=1;
301  }
302  }
303  }
304  else
305  {
306  std::cout << argv[0] << " -h | -l | -s | ([-o <xml-output-file>|.] [-e] [<interface-id>:]<device-id>[?<node>] [<key>=<value>] ...)" << std::endl;
307  std::cout << std::endl;
308  std::cout << "Provides information about GenICam transport layers, interfaces and devices." << std::endl;
309  std::cout << std::endl;
310  std::cout << "Options: " << std::endl;
311  std::cout << "-h Prints help information and exits" << std::endl;
312  std::cout << "-l List all all available devices on all interfaces" << std::endl;
313  std::cout << "-s List all all available devices on all interfaces (short format)" << std::endl;
314  std::cout << "-o Store XML description from specified device" << std::endl;
315  std::cout << "-e Open nodemap editor instead of printing nodemap" << std::endl;
316  std::cout << std::endl;
317  std::cout << "Parameters:" << std::endl;
318  std::cout << "<interface-id> Optional GenICam ID of interface for connecting to the device" << std::endl;
319  std::cout << "<device-id> GenICam device ID, serial number or user defined name of device" << std::endl;
320  std::cout << "<node> Optional name of category or parameter to be reported" << std::endl;
321  std::cout << "<key>=<value> Optional GenICam parameters to be changed in the given order before reporting" << std::endl;
322  ret=1;
323  }
324  }
325  catch (const std::exception &ex)
326  {
327  std::cerr << ex.what() << std::endl;
328  ret=2;
329  }
330 
332 
333  return ret;
334 }
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
static void clearSystems()
Clears the internal list of systems.
Definition: system.cc:282
bool editNodemap(const std::shared_ptr< GenApi::CNodeMapRef > &nodemap, const char root[])
Shows nodemap in a curses gui in the terminal and allows editing of parameters.
int main(int argc, char *argv[])
Definition: gc_info.cc:45
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 printNodemap(const std::shared_ptr< GenApi::CNodeMapRef > &nodemap, const char root[], int depth, bool show_enum_list)
Printing of nodemap, starting at given root node.
Definition: nodemap_out.cc:293


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