libvisiontransfer  7.0.0
parameter_enumeration_example.cpp
1 /*******************************************************************************
2  * Copyright (c) 2019 Nerian Vision GmbH
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *******************************************************************************/
14 
15 #include <visiontransfer/deviceenumeration.h>
16 #include <visiontransfer/imagetransfer.h>
17 #include <visiontransfer/imagepair.h>
18 #include <visiontransfer/scenescanparameters.h>
19 #include <iostream>
20 #include <exception>
21 #include <iomanip>
22 #include <stdio.h>
23 #include <stdlib.h>
24 
25 using namespace visiontransfer;
26 
27 int main(int argc, const char** argv) {
28  try {
29  // Search for SceneScan devices
30  DeviceEnumeration deviceEnum;
31 
32  DeviceEnumeration::DeviceList devices = deviceEnum.discoverDevices();
33  if(devices.size() == 0) {
34  std::cout << "No devices discovered!" << std::endl;
35  return -1;
36  }
37 
38  // Print devices
39  std::cout << "Discovered devices:" << std::endl;
40  for(unsigned int i = 0; i< devices.size(); i++) {
41  std::cout << devices[i].toString() << std::endl;
42  }
43  std::cout << std::endl;
44 
45  // Create an image transfer object that receives data from
46  // the first detected SceneScan
47  SceneScanParameters parameters(devices[0]);
48 
49  // Output the current parameterization
50 
51  const int colW = 35;
52  std::cout << std::boolalpha << std::left;
53  std::cout << "Server-side Parameter Enumeration" << std::endl;
54  std::cout << "=================================" << std::endl << std::endl;
55  std::map<std::string, ParameterInfo> all_params = parameters.getAllParameters();
56  std::cout << "All " << all_params.size() << " parameters reported by server:" << std::endl;
57  for (std::map<std::string, ParameterInfo>::iterator it = all_params.begin(); it != all_params.end(); ++it) {
58  ParameterInfo& param = it->second;
59  ParameterInfo::ParameterType t = param.getType();
60  switch (t) {
61  case ParameterInfo::TYPE_INT: {
62  std::cout << std::setw(colW) << (param.getName()+" (int)") << " = " << std::setw(10) << param.getValue<int>();
63  if (param.getMin<int>() != param.getMax<int>()) {
64  std::cout << " range " << param.getMin<int>() << "-" << param.getMax<int>();
65  if (param.getInc<int>() != 1) {
66  std::cout << ", increments of " << param.getInc<int>();
67  }
68  }
69  std::cout << std::endl;
70  break;
71  }
72  case ParameterInfo::TYPE_BOOL: {
73  std::cout << std::setw(colW) << (param.getName() + " (bool)") << " = " << (param.getValue<bool>()?"true":"false") << std::endl;
74  break;
75  }
76  case ParameterInfo::TYPE_DOUBLE: {
77  std::cout << std::setw(colW) << (param.getName()+" (double)") << " = " << std::setw(10) << param.getValue<double>();
78  if (param.getMin<double>() != param.getMax<double>()) {
79  std::cout << " range " << param.getMin<double>() << "-" << param.getMax<double>();
80  }
81  std::cout << std::endl;
82  break;
83  }
84  }
85  }
86  std::cout << std::endl;
87 
88  // Setting an enumerated parameter
89  if (argc > 1) {
90  std::string argname(argv[1]);
91  if (argc > 2) {
92  double val = atof(argv[2]);
93  std::cout << "Sending request to set " << argname << " to " << val << std::endl;
94  parameters.setNamedParameter(argname, val);
95  } else {
96  std::cout << "Requesting single parameter " << argname << std::endl;
97  std::cout << "-> cast as a double: " << parameters.getNamedParameter<double>(argname) << std::endl;
98  }
99  } else {
100  std::cout << "You can launch this with a parameter name to get (and a value to set it)" << std::endl;
101  std::cout << " e.g. " << argv[0] << " operation_mode [2]" << std::endl;
102  }
103 
104  return 0;
105  } catch(const std::exception& ex) {
106  std::cerr << "Exception occurred: " << ex.what() << std::endl;
107  }
108 
109  return 0;
110 }
111 
DeviceList discoverDevices()
Discovers new devices and returns the list of all devices that have been found.
T getMin() const
Returns the minimum parameter value, cast to the desired type (int, double or bool) ...
std::string getName() const
Returns the string representation of the parameter name.
Allows a configuration of SceneScan&#39;s parameters through a network connection.
T getInc() const
Returns the increment of the parameter (i.e. increment for raising / lowering the value)...
ParameterType getType() const
Returns the type of the parameter.
T getValue() const
Returns the current parameter value, cast to the desired type (int, double or bool) ...
T getMax() const
Returns the maximum parameter value, cast to the desired type (int, double or bool) ...
Allows for the discovery of devices in the network.
Nerian Vision Technologies