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 << " Access status: " << device[j]->getAccessStatus() << std::endl;
351  std::cout << " Serial number: " << device[j]->getSerialNumber() << std::endl;
352  std::cout << " Version: " << device[j]->getVersion() << std::endl;
353  std::cout << " TS Frequency: " << device[j]->getTimestampFrequency() << std::endl;
354  std::cout << std::endl;
355  }
356 
357  interf[k]->close();
358  }
359 
360  system[i]->close();
361  }
362  }
363  else
364  {
365  int k=1;
366 
367  // get parameters, if any
368 
369  const char *xml=0;
370  if (k+1 < argc && std::string(argv[k]) == "-o")
371  {
372  k++;
373  xml=argv[k++];
374  }
375 
376  if (k < argc)
377  {
378  // separate optional node name from device id
379 
380  std::string devid=argv[k++];
381  std::string node="Root";
382  int depth=1000;
383 
384  {
385  size_t j=devid.find('?');
386 
387  if (j != std::string::npos)
388  {
389  node=devid.substr(j+1);
390  devid=devid.substr(0, j);
391  depth=1;
392 
393  if (node.size() == 0)
394  {
395  node="Root";
396  }
397  }
398  }
399 
400  // find specific device accross all systems and interfaces and show some
401  // information
402 
403  std::shared_ptr<rcg::Device> dev=rcg::getDevice(devid.c_str());
404 
405  if (dev)
406  {
407  // open device and optionally change some settings
408 
409  if (k < argc)
410  {
411  dev->open(rcg::Device::CONTROL);
412  }
413  else
414  {
415  dev->open(rcg::Device::READONLY);
416  }
417 
418  std::shared_ptr<GenApi::CNodeMapRef> nodemap=dev->getRemoteNodeMap(xml);
419 
420  while (k < argc)
421  {
422  std::string p=argv[k++];
423 
424  if (p.find('=') != std::string::npos)
425  {
426  // split argument in key and value
427 
428  size_t j=p.find('=');
429  std::string value=p.substr(j+1);
430  std::string key=p.substr(0, j);
431 
432  // set key=value pair through GenICam
433 
434  rcg::setString(nodemap, key.c_str(), value.c_str(), true);
435  }
436  else
437  {
438  // call the command
439  rcg::callCommand(nodemap, p.c_str(), true);
440  }
441  }
442 
443  if (depth > 1)
444  {
445  // report all features
446 
447  std::cout << "Device: " << dev->getID() << std::endl;
448  std::cout << "Vendor: " << dev->getVendor() << std::endl;
449  std::cout << "Model: " << dev->getModel() << std::endl;
450  std::cout << "TL type: " << dev->getTLType() << std::endl;
451  std::cout << "Display name: " << dev->getDisplayName() << std::endl;
452  std::cout << "User name: " << dev->getUserDefinedName() << std::endl;
453  std::cout << "Serial number: " << dev->getSerialNumber() << std::endl;
454  std::cout << "Version: " << dev->getVersion() << std::endl;
455  std::cout << "TS Frequency: " << dev->getTimestampFrequency() << std::endl;
456  std::cout << std::endl;
457 
458  std::vector<std::shared_ptr<rcg::Stream> > stream=dev->getStreams();
459 
460  std::cout << "Available streams:" << std::endl;
461  for (size_t i=0; i<stream.size(); i++)
462  {
463  std::cout << " Stream ID: " << stream[i]->getID() << std::endl;
464  }
465 
466  std::cout << std::endl;
467 
468  std::cout << "Available features:" << std::endl;
469  printNode(std::string(" "), nodemap->_GetNode(node.c_str()), depth);
470  }
471  else
472  {
473  // report requested node only
474 
475  GenApi::INode *p=nodemap->_GetNode(node.c_str());
476 
477  if (p)
478  {
479  printNode(std::string(), p, depth);
480  }
481  else
482  {
483  std::cerr << "Unknown node: " << node << std::endl;
484  ret=1;
485  }
486  }
487 
488  dev->close();
489  }
490  else
491  {
492  std::cerr << "Device '" << devid << "' not found!" << std::endl;
493  ret=1;
494  }
495  }
496  else
497  {
498  std::cerr << "Device name not given!" << std::endl;
499  ret=1;
500  }
501  }
502  }
503  else
504  {
505  std::cout << argv[0] << " -h | -l | ([-o <xml-output-file>] [<interface-id>:]<device-id>[?<node>] [<key>=<value>] ...)" << std::endl;
506  std::cout << std::endl;
507  std::cout << "Provides information about GenICam transport layers, interfaces and devices." << std::endl;
508  std::cout << std::endl;
509  std::cout << "Options: " << std::endl;
510  std::cout << "-h Prints help information and exits" << std::endl;
511  std::cout << "-l List all all available devices on all interfaces" << std::endl;
512  std::cout << "-o Filename to store XML description from specified device" << std::endl;
513  std::cout << std::endl;
514  std::cout << "Parameters:" << std::endl;
515  std::cout << "<interface-id> Optional GenICam ID of interface for connecting to the device" << std::endl;
516  std::cout << "<device-id> GenICam device ID, serial number or user defined name of device" << std::endl;
517  std::cout << "<node> Optional name of category or parameter to be reported" << std::endl;
518  std::cout << "<key>=<value> Optional GenICam parameters to be changed in the given order before reporting" << std::endl;
519  ret=1;
520  }
521  }
522  catch (const std::exception &ex)
523  {
524  std::cerr << ex.what() << std::endl;
525  ret=2;
526  }
527 
529 
530  return ret;
531 }
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
interface GENAPI_DECL_ABSTRACT IBoolean
Interface for Boolean properties.
Definition: IBoolean.h:61
ICommand interface.
Definition: Types.h:195
IPort interface.
Definition: Types.h:202
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()
interface GENAPI_DECL_ABSTRACT IEnumeration
Interface for enumeration properties.
Definition: IEnumeration.h:60
bool IsReadable(EAccessMode AccessMode)
Tests if readable.
Definition: INode.h:178
interface GENAPI_DECL_ABSTRACT IInteger
Interface for integer properties.
Definition: IInteger.h:61
interface GENAPI_DECL_ABSTRACT IFloat
Interface for float properties.
Definition: IFloat.h:60
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
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
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
interface GENAPI_DECL_ABSTRACT IString
Interface for string properties.
Definition: IString.h:61
Object is not yet initialized.
Definition: Types.h:61
Read and Write.
Definition: Types.h:60
interface GENAPI_DECL_ABSTRACT INode
Interface common to all nodes.
Definition: INode.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
interface GENAPI_DECL_ABSTRACT ICategory
Gives access to a category node.
Definition: ICategory.h:66


rc_genicam_api
Author(s): Heiko Hirschmueller
autogenerated on Thu Jun 6 2019 19:10:54