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-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/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" || std::string(argv[1]) == "-l")
54  {
55  bool extended=(std::string(argv[1]) == "-L");
56 
57  // list all systems, interfaces and devices
58 
59  std::vector<std::shared_ptr<rcg::System> > system=rcg::System::getSystems();
60 
61  for (size_t i=0; i<system.size(); i++)
62  {
63  system[i]->open();
64 
65  std::cout << "Transport Layer " << system[i]->getID() << std::endl;
66  std::cout << "Vendor: " << system[i]->getVendor() << std::endl;
67  std::cout << "Model: " << system[i]->getModel() << std::endl;
68  std::cout << "Vendor version: " << system[i]->getVersion() << std::endl;
69  std::cout << "TL type: " << system[i]->getTLType() << std::endl;
70  std::cout << "Name: " << system[i]->getName() << std::endl;
71  std::cout << "Pathname: " << system[i]->getPathname() << std::endl;
72  std::cout << "Display name: " << system[i]->getDisplayName() << std::endl;
73  std::cout << "GenTL version " << system[i]->getMajorVersion() << "."
74  << system[i]->getMinorVersion() << std::endl;
75  std::cout << std::endl;
76 
77  std::vector<std::shared_ptr<rcg::Interface> > interf=system[i]->getInterfaces();
78 
79  if (extended)
80  {
81  rcg::printNodemap(system[i]->getNodeMap(), "Root");
82  std::cout << std::endl;
83  }
84 
85  for (size_t k=0; k<interf.size(); k++)
86  {
87  interf[k]->open();
88 
89  std::cout << " Interface " << interf[k]->getID() << std::endl;
90  std::cout << " Display name: " << interf[k]->getDisplayName() << std::endl;
91  std::cout << " TL type: " << interf[k]->getTLType() << std::endl;
92  std::cout << std::endl;
93 
94  std::vector<std::shared_ptr<rcg::Device> > device=interf[k]->getDevices();
95 
96  if (extended)
97  {
98  rcg::printNodemap(interf[k]->getNodeMap(), "Root");
99  std::cout << std::endl;
100  }
101 
102  for (size_t j=0; j<device.size(); j++)
103  {
104  std::cout << " Device " << device[j]->getID() << std::endl;
105  std::cout << " Vendor: " << device[j]->getVendor() << std::endl;
106  std::cout << " Model: " << device[j]->getModel() << std::endl;
107  std::cout << " TL type: " << device[j]->getTLType() << std::endl;
108  std::cout << " Display name: " << device[j]->getDisplayName() << std::endl;
109  std::cout << " User defined name: " << device[j]->getUserDefinedName() << std::endl;
110  std::cout << " Access status: " << device[j]->getAccessStatus() << std::endl;
111  std::cout << " Serial number: " << device[j]->getSerialNumber() << std::endl;
112  std::cout << " Version: " << device[j]->getVersion() << std::endl;
113  std::cout << " TS Frequency: " << device[j]->getTimestampFrequency() << std::endl;
114  std::cout << std::endl;
115  }
116 
117  interf[k]->close();
118  }
119 
120  system[i]->close();
121  }
122  }
123  else if (std::string(argv[1]) == "-s")
124  {
125  // list all systems, interfaces and devices
126 
127  std::vector<std::shared_ptr<rcg::System> > system=rcg::System::getSystems();
128 
129  std::cout << "Interface\tSerial Number\tVendor\tModel\tName" << std::endl;
130 
131  for (size_t i=0; i<system.size(); i++)
132  {
133  system[i]->open();
134 
135  std::vector<std::shared_ptr<rcg::Interface> > interf=system[i]->getInterfaces();
136 
137  for (size_t k=0; k<interf.size(); k++)
138  {
139  interf[k]->open();
140 
141  std::vector<std::shared_ptr<rcg::Device> > device=interf[k]->getDevices();
142 
143  for (size_t j=0; j<device.size(); j++)
144  {
145  std::cout << interf[k]->getID() << '\t'
146  << device[j]->getSerialNumber() << '\t'
147  << device[j]->getVendor() << '\t'
148  << device[j]->getModel() << '\t'
149  << device[j]->getDisplayName() << std::endl;
150  }
151 
152  interf[k]->close();
153  }
154 
155  system[i]->close();
156  }
157  }
158  else
159  {
160  int k=1;
161 
162  // get parameters, if any
163 
164  int module_event_timeout=-1;
165  const char *xml=0;
166  const char *paramfile=0;
167  bool local_nodemap=false;
168  bool edit=false;
169 
170  while (k+1 < argc && argv[k][0] == '-')
171  {
172  if (std::string(argv[k]) == "-o")
173  {
174  k++;
175  xml=argv[k++];
176 
177  if (std::string(xml) == ".")
178  {
179  xml="";
180  }
181  }
182  else if (std::string(argv[k]) == "-m")
183  {
184  k++;
185  module_event_timeout=std::stoi(std::string(argv[k++]));
186  }
187  else if (std::string(argv[k]) == "-p")
188  {
189  k++;
190  paramfile=argv[k++];
191  }
192  else if (std::string(argv[k]) == "-d")
193  {
194  k++;
195  local_nodemap=true;
196  }
197  else if (std::string(argv[k]) == "-e")
198  {
199  k++;
200  edit=true;
201  }
202  else
203  {
204  std::cerr << "Unknown parameter: " << argv[k] << std::endl;
205  ret=1;
206  break;
207  }
208  }
209 
210  if (ret == 0)
211  {
212  if (k < argc)
213  {
214  // separate optional node name from device id
215 
216  std::string devid=argv[k++];
217  std::string node="Root";
218  int depth=1000;
219 
220  {
221  size_t j=devid.find('?');
222 
223  if (j != std::string::npos)
224  {
225  if (devid.substr(j+1) != "-")
226  {
227  node=devid.substr(j+1);
228  devid=devid.substr(0, j);
229  depth=1;
230 
231  if (node.size() == 0)
232  {
233  node="Root";
234  }
235  }
236  else
237  {
238  node="";
239  devid=devid.substr(0, j);
240  }
241  }
242  }
243 
244  // find specific device accross all systems and interfaces
245 
246  std::shared_ptr<rcg::Device> dev=rcg::getDevice(devid.c_str());
247 
248  if (dev)
249  {
250  // open device and optionally change some settings
251 
252  if (k < argc || edit || paramfile)
253  {
254  dev->open(rcg::Device::CONTROL);
255  }
256  else
257  {
258  dev->open(rcg::Device::READONLY);
259  }
260 
261  // get nodemap
262 
263  std::shared_ptr<GenApi::CNodeMapRef> nodemap;
264  if (local_nodemap)
265  {
266  nodemap=dev->getNodeMap(xml);
267  }
268  else
269  {
270  nodemap=dev->getRemoteNodeMap(xml);
271  }
272 
273  // register and enable module events
274 
275  if (module_event_timeout >= 0)
276  {
277  dev->enableModuleEvents();
278 
279  std::shared_ptr<GenApi::CNodeMapRef> lnodemap;
280  lnodemap=dev->getNodeMap();
281 
282  std::vector<std::string> list;
283  rcg::getEnum(lnodemap, "EventSelector", list, false);
284 
285  for (size_t i=0; i<list.size(); i++)
286  {
287  rcg::setEnum(lnodemap, "EventSelector", list[i].c_str(), true);
288  rcg::setEnum(lnodemap, "EventNotification", "On", false);
289  }
290  }
291 
292  if (nodemap)
293  {
294  // interpret all remaining parameters
295 
296  while (k < argc)
297  {
298  std::string p=argv[k++];
299 
300  if (p.size() > 0 && p[0] == '@')
301  {
302  // load streamable parameters from file into nodemap
303 
304  rcg::loadStreamableParameters(nodemap, p.substr(1).c_str(), true);
305  }
306  else if (p.find('=') != std::string::npos)
307  {
308  // split argument in key and value
309 
310  size_t j=p.find('=');
311  std::string value=p.substr(j+1);
312  std::string key=p.substr(0, j);
313 
314  // set key=value pair through GenICam
315 
316  rcg::setString(nodemap, key.c_str(), value.c_str(), true);
317  }
318  else
319  {
320  // call the command
321  rcg::callCommand(nodemap, p.c_str(), true);
322  }
323  }
324 
325  if (module_event_timeout >= 0)
326  {
327  std::cout << "Waiting for events" << std::endl;
328 
329  int64_t eventid=dev->getModuleEvent(1000*module_event_timeout);
330 
331  if (eventid < 0)
332  {
333  std::cout << "Received no module events" << std::endl;
334  }
335 
336  while (eventid >= 0)
337  {
338  std::cout << "Received module event with ID: " << eventid << std::endl;
339  eventid=dev->getModuleEvent(0);
340  }
341 
342  std::cout << std::endl;
343  }
344 
345  if (edit)
346  {
347  if (!rcg::editNodemap(nodemap, node.c_str()))
348  {
349  std::cerr << "Unknown node: " << node << std::endl;
350  ret=1;
351  }
352  }
353  else if (node.size() > 0)
354  {
355  if (depth > 1)
356  {
357  // report all features
358 
359  std::cout << "Device: " << dev->getID() << std::endl;
360  std::cout << "Vendor: " << dev->getVendor() << std::endl;
361  std::cout << "Model: " << dev->getModel() << std::endl;
362  std::cout << "TL type: " << dev->getTLType() << std::endl;
363  std::cout << "Display name: " << dev->getDisplayName() << std::endl;
364  std::cout << "User defined name: " << dev->getUserDefinedName() << std::endl;
365  std::cout << "Serial number: " << dev->getSerialNumber() << std::endl;
366  std::cout << "Version: " << dev->getVersion() << std::endl;
367  std::cout << "TS Frequency: " << dev->getTimestampFrequency() << std::endl;
368  std::cout << std::endl;
369 
370  std::vector<std::shared_ptr<rcg::Stream> > stream=dev->getStreams();
371 
372  std::cout << "Available streams:" << std::endl;
373  for (size_t i=0; i<stream.size(); i++)
374  {
375  std::cout << " Stream ID: " << stream[i]->getID() << std::endl;
376  }
377 
378  std::cout << std::endl;
379 
380  if (local_nodemap)
381  {
382  std::cout << "Local device nodemap:" << std::endl;
383  }
384  else
385  {
386  std::cout << "Remote device nodemap:" << std::endl;
387  }
388 
389  rcg::printNodemap(nodemap, node.c_str(), depth, true);
390  }
391  else
392  {
393  // report requested node only
394 
395  if (!rcg::printNodemap(nodemap, node.c_str(), depth, true))
396  {
397  std::cerr << "Unknown node: " << node << std::endl;
398  ret=1;
399  }
400  }
401  }
402 
403  if (paramfile)
404  {
405  rcg::saveStreamableParameters(nodemap, paramfile, true);
406  }
407  }
408  else
409  {
410  std::cerr << "Nodemap not available!" << std::endl;
411  }
412 
413  dev->close();
414  }
415  else
416  {
417  std::cerr << "Device '" << devid << "' not found!" << std::endl;
418  ret=1;
419  }
420  }
421  else
422  {
423  std::cerr << "Device name not given!" << std::endl;
424  ret=1;
425  }
426  }
427  }
428  }
429  else
430  {
431  std::cout << argv[0] << " -h | -L | -l | -s | ([-o <xml-output-file>|.] [-m <timeout>] [-p <file>] [-d] [-e] [<interface-id>:]<device-id>[?<node>] [@<file>] [<key>=<value>] ...)" << std::endl;
432  std::cout << std::endl;
433  std::cout << "Provides information about GenICam transport layers, interfaces and devices." << std::endl;
434  std::cout << std::endl;
435  std::cout << "Options: " << std::endl;
436  std::cout << "-h Prints help information and exits" << std::endl;
437  std::cout << "-L List all available devices on all interfaces (extended format)" << std::endl;
438  std::cout << "-l List all available devices on all interfaces" << std::endl;
439  std::cout << "-s List all available devices on all interfaces (short format)" << std::endl;
440  std::cout << "-o Store XML description from specified device" << std::endl;
441  std::cout << "-m Registers for module events and waits for the given number of seconds for such events" << std::endl;
442  std::cout << "-d Use local device nodemap, instead of remote nodemap" << std::endl;
443  std::cout << "-e Open nodemap editor instead of printing nodemap" << std::endl;
444  std::cout << "-p Store all streamable parameters to the given file, after applying all parameters" << std::endl;
445  std::cout << std::endl;
446  std::cout << "Parameters:" << std::endl;
447  std::cout << "<interface-id> Optional GenICam ID of interface for connecting to the device" << std::endl;
448  std::cout << "<device-id> GenICam device ID, serial number or user defined name of device" << std::endl;
449  std::cout << "<node> Optional name of category or parameter to be reported. '-' for none. Default is 'Root'." << std::endl;
450  std::cout << "@<file> Optional file with parameters as store with parameter '-p'" << std::endl;
451  std::cout << "<key>=<value> Optional GenICam parameters to be changed in the given order before reporting" << std::endl;
452  ret=1;
453  }
454  }
455  catch (const std::exception &ex)
456  {
457  std::cerr << ex.what() << std::endl;
458  ret=2;
459  }
460 
462 
463  return ret;
464 }
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
nodemap_edit.h
device.h
rcg::callCommand
bool callCommand(const std::shared_ptr< GenApi::CNodeMapRef > &nodemap, const char *name, bool exception)
Calls the given command.
Definition: config.cc:61
main
int main(int argc, char *argv[])
Definition: gc_info.cc:45
rcg::saveStreamableParameters
bool saveStreamableParameters(const std::shared_ptr< GenApi::CNodeMapRef > &nodemap, const char *name, bool exception)
Store all streamable parameters from the nodemap into the file.
Definition: config.cc:1305
rcg::printNodemap
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:324
rcg::System::clearSystems
static void clearSystems()
Clears the internal list of systems.
Definition: system.cc:282
rcg::getEnum
std::string getEnum(const std::shared_ptr< GenApi::CNodeMapRef > &nodemap, const char *name, bool exception)
Get the value of an enumeration of the given nodemap.
Definition: config.cc:747
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
stream.h
rcg::Device::CONTROL
@ CONTROL
Definition: device.h:60
system.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::setEnum
bool setEnum(const std::shared_ptr< GenApi::CNodeMapRef > &nodemap, const char *name, const char *value, bool exception)
Set the value of an enumeration of the given nodemap.
Definition: config.cc:302
rcg::editNodemap
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.
Definition: nodemap_edit.cc:1126
nodemap_out.h
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