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>
40 #include <rc_genicam_api/config.h>
41 
42 #include <iostream>
43 
44 namespace
45 {
46 
54 const char *getAccessMode(const GenApi::INode *node)
55 {
56  switch (node->GetAccessMode())
57  {
58  case GenApi::NI:
59  return "(NI)";
60 
61  case GenApi::NA:
62  return "(NA)";
63 
64  case GenApi::WO:
65  return "(WO)";
66 
67  case GenApi::RO:
68  return "(RO)";
69 
70  case GenApi::RW:
71  return "(RW)";
72 
74  return "(undefined access mode)";
75 
77  return "(cycle detection)";
78 
79  default:
80  return "(unknown)";
81  }
82 }
83 
93 std::string formatValue(GenApi::IInteger *node, int64_t value)
94 {
96 
97  switch (node->GetRepresentation())
98  {
99  case GenApi::HexNumber:
100  out << "0x" << std::hex << value;
101  break;
102 
103  case GenApi::IPV4Address:
104  out << ((value>>24)&0xff) << '.' << ((value>>16)&0xff) << '.'
105  << ((value>>8)&0xff) << '.' << (value&0xff);
106  break;
107 
108  case GenApi::MACAddress:
109  out << std::hex << ((value>>32)&0xff) << ':' << ((value>>30)&0xff) << ':'
110  << ((value>>24)&0xff) << ':' << ((value>>16)&0xff) << ':'
111  << ((value>>8)&0xff) << ':' << (value&0xff);
112  break;
113 
114  default:
115  out << value;
116  break;
117  }
118 
119  return out.str();
120 }
121 
132 void printNode(const std::string &prefix, GenApi::INode *node, int depth)
133 {
134  if (node != 0 && node->GetAccessMode() != GenApi::NI)
135  {
136  switch (node->GetPrincipalInterfaceType())
137  {
138  case GenApi::intfIValue:
139  std::cout << prefix << "Value: " << node->GetName() << " " << getAccessMode(node)
140  << std::endl;
141  break;
142 
143  case GenApi::intfIBase:
144  std::cout << prefix << "Base: " << node->GetName() << " " << getAccessMode(node)
145  << std::endl;
146  break;
147 
149  {
150  std::cout << prefix << "Integer: " << node->GetName() << " "
151  << getAccessMode(node) << " ";
152 
153  GenApi::IInteger *p=dynamic_cast<GenApi::IInteger *>(node);
154 
155  if (GenApi::IsReadable(p))
156  {
157  std::cout << "[" << formatValue(p, p->GetMin()) << ", "
158  << formatValue(p, p->GetMax()) << "]: ";
159  std::cout << formatValue(p, p->GetValue()) << " " << p->GetUnit();
160  }
161 
162  std::cout << std::endl;
163  }
164  break;
165 
167  {
168  std::cout << prefix << "Boolean: " << node->GetName() << " " << getAccessMode(node);
169 
170  GenApi::IBoolean *p=dynamic_cast<GenApi::IBoolean *>(node);
171 
172  if (GenApi::IsReadable(p))
173  {
174  std::cout << ": " << p->GetValue();
175  }
176 
177  std::cout << std::endl;
178  }
179  break;
180 
182  std::cout << prefix << "Command: " << node->GetName() << " " << getAccessMode(node)
183  << std::endl;
184  break;
185 
186  case GenApi::intfIFloat:
187  {
188  std::cout << prefix << "Float: " << node->GetName() << " " << getAccessMode(node)
189  << " ";
190 
191  GenApi::IFloat *p=dynamic_cast<GenApi::IFloat *>(node);
192 
193  if (GenApi::IsReadable(p))
194  {
195  std::cout << "[" << p->GetMin() << ", "
196  << p->GetMax() << "]: "
197  << p->GetValue() << " " << p->GetUnit();
198  }
199 
200  std::cout << std::endl;
201  }
202  break;
203 
204  case GenApi::intfIString:
205  {
206  std::cout << prefix << "String: " << node->GetName() << " " << getAccessMode(node)
207  << ": ";
208 
209  GenApi::IString *p=dynamic_cast<GenApi::IString *>(node);
210 
211  if (GenApi::IsReadable(p))
212  {
213  std::cout << p->GetValue();
214  }
215 
216  std::cout << std::endl;
217  }
218  break;
219 
221  std::cout << prefix << "Register: " << node->GetName() << " " << getAccessMode(node)
222  << std::endl;
223  break;
224 
226  {
227  std::cout << prefix << "Category: " << node->GetName() << " "
228  << getAccessMode(node) << std::endl;
229 
230  if (depth > 0)
231  {
232  GenApi::ICategory *root=dynamic_cast<GenApi::ICategory *>(node);
233 
234  if (root != 0)
235  {
236  GenApi::FeatureList_t feature;
237  root->GetFeatures(feature);
238 
239  for (size_t i=0; i<feature.size(); i++)
240  {
241  printNode(prefix+" ", feature[i]->GetNode(), depth-1);
242  }
243  }
244  }
245  }
246  break;
247 
249  {
250  std::cout << prefix << "Enumeration: " << node->GetName() << " " << getAccessMode(node)
251  << ' ';
252 
253  GenApi::IEnumeration *p=dynamic_cast<GenApi::IEnumeration *>(node);
254 
255  if (GenApi::IsReadable(p))
256  {
257  std::cout << '[';
258 
260  p->GetSymbolics(list);
261 
262  for (size_t i=0; i<list.size(); i++)
263  {
264  if (i > 0)
265  {
266  std::cout << ' ';
267  }
268 
269  std::cout << list[i];
270  }
271 
272  std::cout << "]: ";
273 
274  if (p->GetCurrentEntry() != 0)
275  {
276  std::cout << p->GetCurrentEntry()->GetSymbolic();
277  }
278  }
279 
280  std::cout << std::endl;
281  }
282  break;
283 
285  std::cout << prefix << "EnumEntry: " << node->GetName() << " " << getAccessMode(node)
286  << std::endl;
287  break;
288 
289  case GenApi::intfIPort:
290  std::cout << prefix << "Port: " << node->GetName() << " " << getAccessMode(node)
291  << std::endl;
292  break;
293 
294  }
295  }
296 }
297 
298 }
299 
300 int main(int argc, char *argv[])
301 {
302  int ret=0;
303 
304  try
305  {
306  if (argc >= 2 && std::string(argv[1]) != "-h")
307  {
308  if (std::string(argv[1]) == "-l")
309  {
310  // list all systems, interfaces and devices
311 
312  std::vector<std::shared_ptr<rcg::System> > system=rcg::System::getSystems();
313 
314  for (size_t i=0; i<system.size(); i++)
315  {
316  system[i]->open();
317 
318  std::cout << "Transport Layer " << system[i]->getID() << std::endl;
319  std::cout << "Vendor: " << system[i]->getVendor() << std::endl;
320  std::cout << "Model: " << system[i]->getModel() << std::endl;
321  std::cout << "Vendor version: " << system[i]->getVersion() << std::endl;
322  std::cout << "TL type: " << system[i]->getTLType() << std::endl;
323  std::cout << "Name: " << system[i]->getName() << std::endl;
324  std::cout << "Pathname: " << system[i]->getPathname() << std::endl;
325  std::cout << "Display name: " << system[i]->getDisplayName() << std::endl;
326  std::cout << "GenTL version " << system[i]->getMajorVersion() << "."
327  << system[i]->getMinorVersion() << std::endl;
328  std::cout << std::endl;
329 
330  std::vector<std::shared_ptr<rcg::Interface> > interf=system[i]->getInterfaces();
331 
332  for (size_t k=0; k<interf.size(); k++)
333  {
334  interf[k]->open();
335 
336  std::cout << " Interface " << interf[k]->getID() << std::endl;
337  std::cout << " Display name: " << interf[k]->getDisplayName() << std::endl;
338  std::cout << " TL type: " << interf[k]->getTLType() << std::endl;
339  std::cout << std::endl;
340 
341  std::vector<std::shared_ptr<rcg::Device> > device=interf[k]->getDevices();
342 
343  for (size_t j=0; j<device.size(); j++)
344  {
345  std::cout << " Device " << device[j]->getID() << std::endl;
346  std::cout << " Vendor: " << device[j]->getVendor() << std::endl;
347  std::cout << " Model: " << device[j]->getModel() << std::endl;
348  std::cout << " TL type: " << device[j]->getTLType() << std::endl;
349  std::cout << " Display name: " << device[j]->getDisplayName() << std::endl;
350  std::cout << " User defined name: " << device[j]->getUserDefinedName() << std::endl;
351  std::cout << " Access status: " << device[j]->getAccessStatus() << std::endl;
352  std::cout << " Serial number: " << device[j]->getSerialNumber() << std::endl;
353  std::cout << " Version: " << device[j]->getVersion() << std::endl;
354  std::cout << " TS Frequency: " << device[j]->getTimestampFrequency() << std::endl;
355  std::cout << std::endl;
356  }
357 
358  interf[k]->close();
359  }
360 
361  system[i]->close();
362  }
363  }
364  else
365  {
366  int k=1;
367 
368  // get parameters, if any
369 
370  const char *xml=0;
371  if (k+1 < argc && std::string(argv[k]) == "-o")
372  {
373  k++;
374  xml=argv[k++];
375  }
376 
377  if (k < argc)
378  {
379  // separate optional node name from device id
380 
381  std::string devid=argv[k++];
382  std::string node="Root";
383  int depth=1000;
384 
385  {
386  size_t j=devid.find('?');
387 
388  if (j != std::string::npos)
389  {
390  node=devid.substr(j+1);
391  devid=devid.substr(0, j);
392  depth=1;
393 
394  if (node.size() == 0)
395  {
396  node="Root";
397  }
398  }
399  }
400 
401  // find specific device accross all systems and interfaces and show some
402  // information
403 
404  std::shared_ptr<rcg::Device> dev=rcg::getDevice(devid.c_str());
405 
406  if (dev)
407  {
408  // open device and optionally change some settings
409 
410  if (k < argc)
411  {
412  dev->open(rcg::Device::CONTROL);
413  }
414  else
415  {
416  dev->open(rcg::Device::READONLY);
417  }
418 
419  std::shared_ptr<GenApi::CNodeMapRef> nodemap=dev->getRemoteNodeMap(xml);
420 
421  if (nodemap)
422  {
423  while (k < argc)
424  {
425  std::string p=argv[k++];
426 
427  if (p.find('=') != std::string::npos)
428  {
429  // split argument in key and value
430 
431  size_t j=p.find('=');
432  std::string value=p.substr(j+1);
433  std::string key=p.substr(0, j);
434 
435  // set key=value pair through GenICam
436 
437  rcg::setString(nodemap, key.c_str(), value.c_str(), true);
438  }
439  else
440  {
441  // call the command
442  rcg::callCommand(nodemap, p.c_str(), true);
443  }
444  }
445 
446  if (depth > 1)
447  {
448  // report all features
449 
450  std::cout << "Device: " << dev->getID() << std::endl;
451  std::cout << "Vendor: " << dev->getVendor() << std::endl;
452  std::cout << "Model: " << dev->getModel() << std::endl;
453  std::cout << "TL type: " << dev->getTLType() << std::endl;
454  std::cout << "Display name: " << dev->getDisplayName() << std::endl;
455  std::cout << "User defined name: " << dev->getUserDefinedName() << std::endl;
456  std::cout << "Serial number: " << dev->getSerialNumber() << std::endl;
457  std::cout << "Version: " << dev->getVersion() << std::endl;
458  std::cout << "TS Frequency: " << dev->getTimestampFrequency() << std::endl;
459  std::cout << std::endl;
460 
461  std::vector<std::shared_ptr<rcg::Stream> > stream=dev->getStreams();
462 
463  std::cout << "Available streams:" << std::endl;
464  for (size_t i=0; i<stream.size(); i++)
465  {
466  std::cout << " Stream ID: " << stream[i]->getID() << std::endl;
467  }
468 
469  std::cout << std::endl;
470 
471  std::cout << "Available features:" << std::endl;
472  printNode(std::string(" "), nodemap->_GetNode(node.c_str()), depth);
473  }
474  else
475  {
476  // report requested node only
477 
478  GenApi::INode *p=nodemap->_GetNode(node.c_str());
479 
480  if (p)
481  {
482  printNode(std::string(), p, depth);
483  }
484  else
485  {
486  std::cerr << "Unknown node: " << node << std::endl;
487  ret=1;
488  }
489  }
490  }
491  else
492  {
493  std::cerr << "Nodemap not available!" << std::endl;
494  }
495 
496  dev->close();
497  }
498  else
499  {
500  std::cerr << "Device '" << devid << "' not found!" << std::endl;
501  ret=1;
502  }
503  }
504  else
505  {
506  std::cerr << "Device name not given!" << std::endl;
507  ret=1;
508  }
509  }
510  }
511  else
512  {
513  std::cout << argv[0] << " -h | -l | ([-o <xml-output-file>] [<interface-id>:]<device-id>[?<node>] [<key>=<value>] ...)" << std::endl;
514  std::cout << std::endl;
515  std::cout << "Provides information about GenICam transport layers, interfaces and devices." << std::endl;
516  std::cout << std::endl;
517  std::cout << "Options: " << std::endl;
518  std::cout << "-h Prints help information and exits" << std::endl;
519  std::cout << "-l List all all available devices on all interfaces" << std::endl;
520  std::cout << "-o Filename to store XML description from specified device" << std::endl;
521  std::cout << std::endl;
522  std::cout << "Parameters:" << std::endl;
523  std::cout << "<interface-id> Optional GenICam ID of interface for connecting to the device" << std::endl;
524  std::cout << "<device-id> GenICam device ID, serial number or user defined name of device" << std::endl;
525  std::cout << "<node> Optional name of category or parameter to be reported" << std::endl;
526  std::cout << "<key>=<value> Optional GenICam parameters to be changed in the given order before reporting" << std::endl;
527  ret=1;
528  }
529  }
530  catch (const std::exception &ex)
531  {
532  std::cerr << ex.what() << std::endl;
533  ret=2;
534  }
535 
537 
538  return ret;
539 }
std::shared_ptr< Device > getDevice(const char *id)
Searches across all transport layers and interfaces for a device.
Definition: device.cc:469
Hex number in an edit control.
Definition: Types.h:95
IFloat interface.
Definition: Types.h:196
ICommand interface.
Definition: Types.h:195
GENICAM_INTERFACE GENAPI_DECL_ABSTRACT IBoolean
Interface for Boolean properties.
Definition: IBoolean.h:61
IPort interface.
Definition: Types.h:202
GENICAM_INTERFACE IInteger
Interface for integer properties.
Definition: IFloat.h:114
IBase interface.
Definition: Types.h:192
static std::vector< std::shared_ptr< System > > getSystems()
Returns a list of systems (i.e.
Definition: system.cc:116
virtual INode * GetNode(const GENICAM_NAMESPACE::gcstring &Name) const =0
Retrieves the node from the central map by Name.
__int64 int64_t
Definition: config-win32.h:21
used internally for AccessMode cycle detection
Definition: Types.h:62
std::string str()
bool IsReadable(EAccessMode AccessMode)
Tests if readable.
Definition: INode.h:178
static void clearSystems()
Clears the internal list of systems.
Definition: system.cc:213
IString interface.
Definition: Types.h:197
IBoolean interface.
Definition: Types.h:194
int main(int argc, char *argv[])
Definition: gc_info.cc:300
IValue interface.
Definition: Types.h:191
GENICAM_INTERFACE GENAPI_DECL_ABSTRACT IEnumeration
Interface for enumeration properties.
Definition: IEnumeration.h:60
ICategory interface.
Definition: Types.h:199
Not implemented.
Definition: Types.h:56
Read Only.
Definition: Types.h:59
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
GENICAM_INTERFACE GENAPI_DECL_ABSTRACT ICategory
Gives access to a category node.
Definition: ICategory.h:66
Not available.
Definition: Types.h:57
Write Only.
Definition: Types.h:58
bool callCommand(const std::shared_ptr< GenApi::CNodeMapRef > &nodemap, const char *name, bool exception)
Calls the given command.
Definition: config.cc:53
IEnumeration interface.
Definition: Types.h:200
GENICAM_INTERFACE GENAPI_DECL_ABSTRACT IString
Interface for string properties.
Definition: IString.h:61
Object is not yet initialized.
Definition: Types.h:61
GENICAM_INTERFACE GENAPI_DECL_ABSTRACT IFloat
Interface for float properties.
Definition: IFloat.h:60
GENICAM_INTERFACE INode
Interface common to all nodes.
Definition: ICategory.h:51
Read and Write.
Definition: Types.h:60
GENICAM_NAMESPACE::gcstring_vector StringList_t
A list of strings.
Definition: Types.h:150
IRegister interface.
Definition: Types.h:198
IEnumEntry interface.
Definition: Types.h:201
IInteger interface.
Definition: Types.h:193


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