config.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 "config.h"
37 #include "buffer.h"
38 
39 #include <stdexcept>
40 #include <iomanip>
41 #include <limits>
42 
43 #include "Base/GCException.h"
44 
45 #include <GenApi/ChunkAdapterGEV.h>
46 #include <GenApi/ChunkAdapterU3V.h>
48 #include <GenApi/Filestream.h>
49 
51 
52 #ifdef _WIN32
53 #undef min
54 #undef max
55 #endif
56 
57 namespace rcg
58 {
59 
60 bool callCommand(const std::shared_ptr<GenApi::CNodeMapRef> &nodemap, const char *name,
61  bool exception)
62 {
63  bool ret=false;
64 
65  try
66  {
67  GenApi::INode *node=nodemap->_GetNode(name);
68 
69  if (node != 0)
70  {
71  if (GenApi::IsWritable(node))
72  {
73  GenApi::ICommand *val=dynamic_cast<GenApi::ICommand *>(node);
74 
75  if (val != 0)
76  {
77  val->Execute();
78  ret=true;
79  }
80  else if (exception)
81  {
82  throw std::invalid_argument(std::string("Feature not a command: ")+name);
83  }
84  }
85  else if (exception)
86  {
87  throw std::invalid_argument(std::string("Feature not writable: ")+name);
88  }
89  }
90  else if (exception)
91  {
92  throw std::invalid_argument(std::string("Feature not found: ")+name);
93  }
94  }
95  catch (const GENICAM_NAMESPACE::GenericException &ex)
96  {
97  if (exception)
98  {
99  throw std::invalid_argument(ex.what());
100  }
101  }
102 
103  return ret;
104 }
105 
106 bool setBoolean(const std::shared_ptr<GenApi::CNodeMapRef> &nodemap, const char *name,
107  bool value, bool exception)
108 {
109  bool ret=false;
110 
111  try
112  {
113  GenApi::INode *node=nodemap->_GetNode(name);
114 
115  if (node != 0)
116  {
117  if (GenApi::IsWritable(node))
118  {
119  GenApi::IBoolean *val=dynamic_cast<GenApi::IBoolean *>(node);
120 
121  if (val != 0)
122  {
123  val->SetValue(value);
124  ret=true;
125  }
126  else if (exception)
127  {
128  throw std::invalid_argument(std::string("Feature not boolean: ")+name);
129  }
130  }
131  else if (exception)
132  {
133  throw std::invalid_argument(std::string("Feature not writable: ")+name);
134  }
135  }
136  else if (exception)
137  {
138  throw std::invalid_argument(std::string("Feature not found: ")+name);
139  }
140  }
141  catch (const GENICAM_NAMESPACE::GenericException &ex)
142  {
143  if (exception)
144  {
145  throw std::invalid_argument(ex.what());
146  }
147  }
148 
149  return ret;
150 }
151 
152 bool setInteger(const std::shared_ptr<GenApi::CNodeMapRef> &nodemap, const char *name,
153  int64_t value, bool exception)
154 {
155  bool ret=false;
156 
157  try
158  {
159  GenApi::INode *node=nodemap->_GetNode(name);
160 
161  if (node != 0)
162  {
163  if (GenApi::IsWritable(node))
164  {
165  GenApi::IInteger *val=dynamic_cast<GenApi::IInteger *>(node);
166 
167  if (val != 0)
168  {
169  val->SetValue(value);
170  ret=true;
171  }
172  else if (exception)
173  {
174  throw std::invalid_argument(std::string("Feature not integer: ")+name);
175  }
176  }
177  else if (exception)
178  {
179  throw std::invalid_argument(std::string("Feature not writable: ")+name);
180  }
181  }
182  else if (exception)
183  {
184  throw std::invalid_argument(std::string("Feature not found: ")+name);
185  }
186  }
187  catch (const GENICAM_NAMESPACE::GenericException &ex)
188  {
189  if (exception)
190  {
191  throw std::invalid_argument(ex.what());
192  }
193  }
194 
195  return ret;
196 }
197 
198 bool setIPV4Address(const std::shared_ptr<GenApi::CNodeMapRef> &nodemap, const char *name,
199  const char *value, bool exception)
200 {
201  bool ret=false;
202 
203  try
204  {
205  GenApi::INode *node=nodemap->_GetNode(name);
206 
207  if (node != 0)
208  {
209  if (GenApi::IsWritable(node))
210  {
211  GenApi::IInteger *val=dynamic_cast<GenApi::IInteger *>(node);
212 
213  if (val != 0)
214  {
215  int64_t ip=0;
216 
217  std::stringstream in(value);
218  std::string elem;
219 
220  for (int i=0; i<4; i++)
221  {
222  getline(in, elem, '.');
223  ip=(ip<<8)|(stoi(elem)&0xff);
224  }
225 
226  val->SetValue(ip);
227  ret=true;
228  }
229  else if (exception)
230  {
231  throw std::invalid_argument(std::string("Feature not integer: ")+name);
232  }
233  }
234  else if (exception)
235  {
236  throw std::invalid_argument(std::string("Feature not writable: ")+name);
237  }
238  }
239  else if (exception)
240  {
241  throw std::invalid_argument(std::string("Feature not found: ")+name);
242  }
243  }
244  catch (const GENICAM_NAMESPACE::GenericException &ex)
245  {
246  if (exception)
247  {
248  throw std::invalid_argument(ex.what());
249  }
250  }
251 
252  return ret;
253 }
254 
255 bool setFloat(const std::shared_ptr<GenApi::CNodeMapRef> &nodemap, const char *name,
256  double value, bool exception)
257 {
258  bool ret=false;
259 
260  try
261  {
262  GenApi::INode *node=nodemap->_GetNode(name);
263 
264  if (node != 0)
265  {
266  if (GenApi::IsWritable(node))
267  {
268  GenApi::IFloat *val=dynamic_cast<GenApi::IFloat *>(node);
269 
270  if (val != 0)
271  {
272  val->SetValue(value);
273  ret=true;
274  }
275  else if (exception)
276  {
277  throw std::invalid_argument(std::string("Feature not float: ")+name);
278  }
279  }
280  else if (exception)
281  {
282  throw std::invalid_argument(std::string("Feature not writable: ")+name);
283  }
284  }
285  else if (exception)
286  {
287  throw std::invalid_argument(std::string("Feature not found: ")+name);
288  }
289  }
290  catch (const GENICAM_NAMESPACE::GenericException &ex)
291  {
292  if (exception)
293  {
294  throw std::invalid_argument(ex.what());
295  }
296  }
297 
298  return ret;
299 }
300 
301 bool setEnum(const std::shared_ptr<GenApi::CNodeMapRef> &nodemap, const char *name,
302  const char *value, bool exception)
303 {
304  bool ret=false;
305 
306  try
307  {
308  GenApi::INode *node=nodemap->_GetNode(name);
309 
310  if (node != 0)
311  {
312  if (GenApi::IsWritable(node))
313  {
314  GenApi::IEnumeration *val=dynamic_cast<GenApi::IEnumeration *>(node);
315 
316  if (val != 0)
317  {
318  GenApi::IEnumEntry *entry=0;
319 
320  try
321  {
322  entry=val->GetEntryByName(value);
323  }
325  { }
326 
327  if (entry != 0)
328  {
329  val->SetIntValue(entry->GetValue());
330 
331  return true;
332  }
333  else if (exception)
334  {
335  throw std::invalid_argument(std::string("Enumeration '")+name+
336  "' does not contain: "+value);
337  }
338  }
339  else if (exception)
340  {
341  throw std::invalid_argument(std::string("Feature not enumeration: ")+name);
342  }
343  }
344  else if (exception)
345  {
346  throw std::invalid_argument(std::string("Feature not writable: ")+name);
347  }
348  }
349  else if (exception)
350  {
351  throw std::invalid_argument(std::string("Feature not found: ")+name);
352  }
353  }
354  catch (const GENICAM_NAMESPACE::GenericException &ex)
355  {
356  if (exception)
357  {
358  throw std::invalid_argument(ex.what());
359  }
360  }
361 
362  return ret;
363 }
364 
365 bool setString(const std::shared_ptr<GenApi::CNodeMapRef> &nodemap, const char *name,
366  const char *value, bool exception)
367 {
368  bool ret=false;
369 
370  try
371  {
372  GenApi::INode *node=nodemap->_GetNode(name);
373 
374  if (node != 0)
375  {
376  if (GenApi::IsWritable(node))
377  {
378  switch (node->GetPrincipalInterfaceType())
379  {
381  {
382  GenApi::IBoolean *p=dynamic_cast<GenApi::IBoolean *>(node);
383 
384  std::string v=std::string(value);
385  if (v == "true" || v == "True" || v == "TRUE")
386  {
387  p->SetValue(1);
388  }
389  else if (v == "false" || v == "False" || v == "FALSE")
390  {
391  p->SetValue(0);
392  }
393  else
394  {
395  p->SetValue(static_cast<bool>(std::stoi(v)));
396  }
397  }
398  break;
399 
401  {
402  GenApi::IInteger *p=dynamic_cast<GenApi::IInteger *>(node);
403 
404  switch (p->GetRepresentation())
405  {
406  case GenApi::HexNumber:
407  p->SetValue(std::stoll(std::string(value), 0, 16));
408  break;
409 
410  case GenApi::IPV4Address:
411  {
412  int64_t ip=0;
413 
414  std::stringstream in(value);
415  std::string elem;
416 
417  for (int i=0; i<4; i++)
418  {
419  getline(in, elem, '.');
420  ip=(ip<<8)|(stoi(elem)&0xff);
421  }
422 
423  p->SetValue(ip);
424  }
425  break;
426 
427  case GenApi::MACAddress:
428  {
429  int64_t mac=0;
430 
431  std::stringstream in(value);
432  std::string elem;
433 
434  for (int i=0; i<4; i++)
435  {
436  getline(in, elem, ':');
437  mac=(mac<<8)|(stoi(elem, 0, 16)&0xff);
438  }
439 
440  p->SetValue(mac);
441  }
442  break;
443 
444  default:
445  p->SetValue(std::stoll(std::string(value)));
446  break;
447  }
448  }
449  break;
450 
451  case GenApi::intfIFloat:
452  {
453  GenApi::IFloat *p=dynamic_cast<GenApi::IFloat *>(node);
454  p->SetValue(std::stof(std::string(value)));
455  }
456  break;
457 
459  {
460  GenApi::IEnumeration *p=dynamic_cast<GenApi::IEnumeration *>(node);
461  GenApi::IEnumEntry *entry=0;
462 
463  try
464  {
465  entry=p->GetEntryByName(value);
466  }
468  { }
469 
470  if (entry != 0)
471  {
472  p->SetIntValue(entry->GetValue());
473  }
474  else if (exception)
475  {
476  throw std::invalid_argument(std::string("Enumeration '")+name+
477  "' does not contain: "+value);
478  }
479  }
480  break;
481 
482  case GenApi::intfIString:
483  {
484  GenApi::IString *p=dynamic_cast<GenApi::IString *>(node);
485  p->SetValue(value);
486  }
487  break;
488 
489  default:
490  if (exception)
491  {
492  throw std::invalid_argument(std::string("Feature of unknown datatype: ")+name);
493  }
494  break;
495  }
496  }
497  else if (exception)
498  {
499  throw std::invalid_argument(std::string("Feature not writable: ")+name);
500  }
501  }
502  else if (exception)
503  {
504  throw std::invalid_argument(std::string("Feature not found: ")+name);
505  }
506  }
507  catch (const GENICAM_NAMESPACE::GenericException &ex)
508  {
509  if (exception)
510  {
511  throw std::invalid_argument(ex.what());
512  }
513  }
514 
515  return ret;
516 }
517 
518 bool getBoolean(const std::shared_ptr<GenApi::CNodeMapRef> &nodemap, const char *name,
519  bool exception, bool igncache)
520 {
521  bool ret=false;
522 
523  try
524  {
525  GenApi::INode *node=nodemap->_GetNode(name);
526 
527  if (node != 0)
528  {
529  if (GenApi::IsReadable(node))
530  {
531  GenApi::IBoolean *val=dynamic_cast<GenApi::IBoolean *>(node);
532 
533  if (val != 0)
534  {
535  ret=val->GetValue(false, igncache);
536  }
537  else if (exception)
538  {
539  throw std::invalid_argument(std::string("Feature not boolean: ")+name);
540  }
541  }
542  else if (exception)
543  {
544  throw std::invalid_argument(std::string("Feature not readable: ")+name);
545  }
546  }
547  else if (exception)
548  {
549  throw std::invalid_argument(std::string("Feature not found: ")+name);
550  }
551  }
552  catch (const GENICAM_NAMESPACE::GenericException &ex)
553  {
554  if (exception)
555  {
556  throw std::invalid_argument(ex.what());
557  }
558  }
559 
560  return ret;
561 }
562 
563 int64_t getInteger(const std::shared_ptr<GenApi::CNodeMapRef> &nodemap, const char *name,
564  int64_t *vmin, int64_t *vmax, bool exception, bool igncache)
565 {
566  int64_t ret=0;
567 
568  if (vmin != 0) *vmin=0;
569  if (vmax != 0) *vmax=0;
570 
571  try
572  {
573  GenApi::INode *node=nodemap->_GetNode(name);
574 
575  if (node != 0)
576  {
577  if (GenApi::IsReadable(node))
578  {
579  if (node->GetPrincipalInterfaceType() == GenApi::intfIEnumeration)
580  {
581  GenApi::IEnumeration *p=dynamic_cast<GenApi::IEnumeration *>(node);
582  ret=p->GetCurrentEntry(false, igncache)->GetValue();
583 
584  if (vmin != 0) *vmin=ret;
585  if (vmax != 0) *vmax=ret;
586  }
587  else
588  {
589  GenApi::IInteger *val=dynamic_cast<GenApi::IInteger *>(node);
590 
591  if (val != 0)
592  {
593  ret=val->GetValue(false, igncache);
594 
595  if (vmin != 0) *vmin=val->GetMin();
596  if (vmax != 0) *vmax=val->GetMax();
597  }
598  else if (exception)
599  {
600  throw std::invalid_argument(std::string("Feature not integer: ")+name);
601  }
602  }
603  }
604  else if (exception)
605  {
606  throw std::invalid_argument(std::string("Feature not readable: ")+name);
607  }
608  }
609  else if (exception)
610  {
611  throw std::invalid_argument(std::string("Feature not found: ")+name);
612  }
613  }
614  catch (const GENICAM_NAMESPACE::GenericException &ex)
615  {
616  if (exception)
617  {
618  throw std::invalid_argument(ex.what());
619  }
620  }
621 
622  return ret;
623 }
624 
625 double getFloat(const std::shared_ptr<GenApi::CNodeMapRef> &nodemap, const char *name,
626  double *vmin, double *vmax, bool exception, bool igncache)
627 {
628  double ret=0;
629 
630  if (vmin != 0) *vmin=0;
631  if (vmax != 0) *vmax=0;
632 
633  try
634  {
635  GenApi::INode *node=nodemap->_GetNode(name);
636 
637  if (node != 0)
638  {
639  if (GenApi::IsReadable(node))
640  {
641  GenApi::IFloat *val=dynamic_cast<GenApi::IFloat *>(node);
642 
643  if (val != 0)
644  {
645  ret=val->GetValue(false, igncache);
646 
647  if (vmin != 0) *vmin=val->GetMin();
648  if (vmax != 0) *vmax=val->GetMax();
649  }
650  else if (exception)
651  {
652  throw std::invalid_argument(std::string("Feature not float: ")+name);
653  }
654  }
655  else if (exception)
656  {
657  throw std::invalid_argument(std::string("Feature not readable: ")+name);
658  }
659  }
660  else if (exception)
661  {
662  throw std::invalid_argument(std::string("Feature not found: ")+name);
663  }
664  }
665  catch (const GENICAM_NAMESPACE::GenericException &ex)
666  {
667  if (exception)
668  {
669  throw std::invalid_argument(ex.what());
670  }
671  }
672 
673  return ret;
674 }
675 
676 std::string getEnum(const std::shared_ptr<GenApi::CNodeMapRef> &nodemap, const char *name,
677  bool exception)
678 {
679  std::string ret;
680 
681  try
682  {
683  GenApi::INode *node=nodemap->_GetNode(name);
684 
685  if (node != 0)
686  {
687  if (GenApi::IsReadable(node))
688  {
689  GenApi::IEnumeration *val=dynamic_cast<GenApi::IEnumeration *>(node);
690 
691  if (val != 0)
692  {
693  GenApi::IEnumEntry *entry=val->GetCurrentEntry();
694 
695  if (entry != 0)
696  {
697  ret=entry->GetSymbolic();
698  }
699  else if (exception)
700  {
701  throw std::invalid_argument(std::string("Current value is not defined: ")+name);
702  }
703  }
704  else if (exception)
705  {
706  throw std::invalid_argument(std::string("Feature not enumeration: ")+name);
707  }
708  }
709  else if (exception)
710  {
711  throw std::invalid_argument(std::string("Feature not readable: ")+name);
712  }
713  }
714  else if (exception)
715  {
716  throw std::invalid_argument(std::string("Feature not found: ")+name);
717  }
718  }
719  catch (const GENICAM_NAMESPACE::GenericException &ex)
720  {
721  if (exception)
722  {
723  throw std::invalid_argument(ex.what());
724  }
725  }
726 
727  return ret;
728 }
729 
730 std::string getEnum(const std::shared_ptr<GenApi::CNodeMapRef> &nodemap, const char *name,
731  std::vector<std::string> &list, bool exception)
732 {
733  std::string ret;
734 
735  list.clear();
736 
737  try
738  {
739  GenApi::INode *node=nodemap->_GetNode(name);
740 
741  if (node != 0)
742  {
743  if (GenApi::IsReadable(node))
744  {
745  GenApi::IEnumeration *val=dynamic_cast<GenApi::IEnumeration *>(node);
746 
747  if (val != 0)
748  {
749  GenApi::StringList_t entries;
750  val->GetSymbolics(entries);
751 
752  for (size_t i=0; i<entries.size(); i++)
753  {
754  list.push_back(std::string(entries[i]));
755  }
756 
757  GenApi::IEnumEntry *entry=val->GetCurrentEntry();
758 
759  if (entry != 0)
760  {
761  ret=entry->GetSymbolic();
762  }
763  else if (exception)
764  {
765  throw std::invalid_argument(std::string("Current value is not defined: ")+name);
766  }
767  }
768  else if (exception)
769  {
770  throw std::invalid_argument(std::string("Feature not enumeration: ")+name);
771  }
772  }
773  else if (exception)
774  {
775  throw std::invalid_argument(std::string("Feature not readable: ")+name);
776  }
777  }
778  else if (exception)
779  {
780  throw std::invalid_argument(std::string("Feature not found: ")+name);
781  }
782  }
783  catch (const GENICAM_NAMESPACE::GenericException &ex)
784  {
785  if (exception)
786  {
787  throw std::invalid_argument(ex.what());
788  }
789  }
790 
791  return ret;
792 }
793 
794 std::string getString(const std::shared_ptr<GenApi::CNodeMapRef> &nodemap, const char *name,
795  bool exception, bool igncache)
796 {
797  std::ostringstream out;
798 
799  try
800  {
801  GenApi::INode *node=nodemap->_GetNode(name);
802 
803  if (node != 0)
804  {
805  if (GenApi::IsReadable(node))
806  {
807  switch (node->GetPrincipalInterfaceType())
808  {
810  {
811  GenApi::IBoolean *p=dynamic_cast<GenApi::IBoolean *>(node);
812  out << p->GetValue(false, igncache);
813  }
814  break;
815 
817  {
818  GenApi::IInteger *p=dynamic_cast<GenApi::IInteger *>(node);
819  int64_t value=p->GetValue(false, igncache);
820 
821  switch (p->GetRepresentation())
822  {
823  case GenApi::HexNumber:
824  out << std::hex << value;
825  break;
826 
827  case GenApi::IPV4Address:
828  out << ((value>>24)&0xff) << '.' << ((value>>16)&0xff) << '.'
829  << ((value>>8)&0xff) << '.' << (value&0xff);
830  break;
831 
832  case GenApi::MACAddress:
833  out << std::hex << std::setfill('0');
834  out << std::setw(2) << ((value>>40)&0xff) << ':'
835  << std::setw(2) << ((value>>32)&0xff) << ':'
836  << std::setw(2) << ((value>>24)&0xff) << ':'
837  << std::setw(2) << ((value>>16)&0xff) << ':'
838  << std::setw(2) << ((value>>8)&0xff) << ':'
839  << std::setw(2) << (value&0xff);
840  break;
841 
842  default:
843  out << value;
844  break;
845  }
846  }
847  break;
848 
849  case GenApi::intfIFloat:
850  {
851  GenApi::IFloat *p=dynamic_cast<GenApi::IFloat *>(node);
852  out << p->GetValue(false, igncache);
853  }
854  break;
855 
857  {
858  GenApi::IEnumeration *p=dynamic_cast<GenApi::IEnumeration *>(node);
859  out << p->GetCurrentEntry()->GetSymbolic();
860  }
861  break;
862 
863  case GenApi::intfIString:
864  {
865  GenApi::IString *p=dynamic_cast<GenApi::IString *>(node);
866  out << p->GetValue(false, igncache);
867  }
868  break;
869 
870  default:
871  if (exception)
872  {
873  throw std::invalid_argument(std::string("Feature of unknown datatype: ")+name);
874  }
875  break;
876  }
877  }
878  else if (exception)
879  {
880  throw std::invalid_argument(std::string("Feature not readable: ")+name);
881  }
882  }
883  else if (exception)
884  {
885  throw std::invalid_argument(std::string("Feature not found: ")+name);
886  }
887  }
888  catch (const GENICAM_NAMESPACE::GenericException &ex)
889  {
890  if (exception)
891  {
892  throw std::invalid_argument(ex.what());
893  }
894  }
895 
896  return out.str();
897 }
898 
899 void checkFeature(const std::shared_ptr<GenApi::CNodeMapRef> &nodemap, const char *name,
900  const char *value, bool igncache)
901 {
902  std::string cvalue=getString(nodemap, name, true, igncache);
903 
904  if (cvalue != "" && cvalue != value)
905  {
906  std::ostringstream out;
907  out << name << " == " << value << " expected: " << cvalue;
908  throw std::invalid_argument(out.str());
909  }
910 }
911 
912 std::shared_ptr<GenApi::CChunkAdapter> getChunkAdapter(const std::shared_ptr<GenApi::CNodeMapRef> &nodemap,
913  const std::string &tltype)
914 {
915  std::shared_ptr<GenApi::CChunkAdapter> chunkadapter;
916 
917  if (setBoolean(nodemap, "ChunkModeActive", true))
918  {
919  if (tltype == "GEV")
920  {
921  chunkadapter=std::shared_ptr<GenApi::CChunkAdapter>(new GenApi::CChunkAdapterGEV(nodemap->_Ptr));
922  }
923  else if (tltype == "U3V")
924  {
925  chunkadapter=std::shared_ptr<GenApi::CChunkAdapter>(new GenApi::CChunkAdapterU3V(nodemap->_Ptr));
926  }
927  else
928  {
929  chunkadapter=std::shared_ptr<GenApi::CChunkAdapter>(new GenApi::CChunkAdapterGeneric(nodemap->_Ptr));
930  }
931  }
932 
933  return chunkadapter;
934 }
935 
936 std::string getComponetOfPart(const std::shared_ptr<GenApi::CNodeMapRef> &nodemap,
937  const Buffer *buffer, uint32_t ipart)
938 {
939  std::string component;
940 
941  try
942  {
943  // get chunk component selector and proprietary chunk part index parmeters
944 
945  GenApi::IEnumeration *sel=dynamic_cast<GenApi::IEnumeration *>(nodemap->_GetNode("ChunkComponentSelector"));
946  GenApi::IInteger *part=dynamic_cast<GenApi::IInteger *>(nodemap->_GetNode("ChunkPartIndex"));
947 
948  if (sel != 0 && part != 0)
949  {
950  if (GenApi::IsReadable(sel) && GenApi::IsWritable(sel) && GenApi::IsReadable(part))
951  {
952  // go through all available enumerations
953 
954  GenApi::NodeList_t list;
955  sel->GetEntries(list);
956 
957  for (size_t i=0; i<list.size() && component.size() == 0; i++)
958  {
959  GenApi::IEnumEntry *entry=dynamic_cast<GenApi::IEnumEntry *>(list[i]);
960 
961  if (entry != 0 && GenApi::IsReadable(entry))
962  {
963  sel->SetIntValue(entry->GetValue());
964 
965  int64_t val=part->GetValue();
966  if (val == ipart)
967  {
968  component=dynamic_cast<GenApi::IEnumEntry *>(list[i])->GetSymbolic();
969  }
970  }
971  }
972  }
973  }
974  }
975  catch (const std::exception &)
976  { /* ignore errors */ }
978  { /* ignore errors */ }
979 
980  // try guessing component name from pixel format
981 
982  if (component.size() == 0 && buffer->getImagePresent(ipart))
983  {
984  switch (buffer->getPixelFormat(ipart))
985  {
986  case Mono8:
987  case YCbCr411_8:
988  if (buffer->getWidth(ipart) >= buffer->getHeight(ipart))
989  {
990  component="Intensity";
991  }
992  else
993  {
994  component="IntensityCombined";
995  }
996  break;
997 
998  case Coord3D_C16:
999  component="Disparity";
1000  break;
1001 
1002  case Confidence8:
1003  component="Confidence";
1004  break;
1005 
1006  case Error8:
1007  component="Error";
1008  break;
1009 
1010  default:
1011  break;
1012  }
1013  }
1014 
1015  return component;
1016 }
1017 
1018 std::string loadFile(const std::shared_ptr<GenApi::CNodeMapRef> &nodemap, const char *name,
1019  bool exception)
1020 {
1021  std::string ret;
1022 
1023  // load file in pieces of 512 bytes
1024 
1026  rf.attach(nodemap->_Ptr);
1027 
1028  if (rf.openFile(name, std::ios::in))
1029  {
1030  size_t length=std::numeric_limits<size_t>::max();
1031  try
1032  {
1033  // limit read operation to file size, if available
1034  length=rcg::getInteger(nodemap, "FileSize", 0, 0, true);
1035  }
1036  catch (const std::exception &)
1037  { }
1038 
1039  size_t off=0, n=512;
1040  std::vector<char> buffer(512);
1041 
1042  while (n > 0 && length > 0)
1043  {
1044  n=rf.read(buffer.data(), off, std::min(length, buffer.size()), name);
1045 
1046  if (n == 0)
1047  {
1048  // workaround for reading last partial block if camera reports failure
1049 
1050  n=rcg::getInteger(nodemap, "FileOperationResult");
1051 
1052  if (n > 0)
1053  {
1054  n=rf.read(buffer.data(), off, n, name);
1055  }
1056  }
1057 
1058  if (n > 0)
1059  {
1060  ret.append(buffer.data(), n);
1061  }
1062 
1063  off+=n;
1064  length-=n;
1065  }
1066 
1067  rf.closeFile(name);
1068  }
1069  else
1070  {
1071  if (exception)
1072  {
1073  throw std::invalid_argument(std::string("Cannot open file for reading: ")+name);
1074  }
1075  }
1076 
1077  return ret;
1078 }
1079 
1080 bool saveFile(const std::shared_ptr<GenApi::CNodeMapRef> &nodemap, const char *name,
1081  const std::string &data, bool exception)
1082 {
1083  bool ret=true;
1084 
1085  // store in pieces of 512 bytes
1086 
1088  rf.attach(nodemap->_Ptr);
1089 
1090  if (rf.openFile(name, std::ios::out))
1091  {
1092  size_t off=0, n=512;
1093  while (n > 0)
1094  {
1095  n=rf.write(data.c_str()+off, off, std::min(static_cast<size_t>(512), data.size()-off), name);
1096  off+=n;
1097  }
1098 
1099  rf.closeFile(name);
1100 
1101  if (off != data.size())
1102  {
1103  if (exception)
1104  {
1105  std::ostringstream out;
1106  out << "Error: Can only write " << off << " of " << data.size() << " bytes";
1107  throw std::invalid_argument(out.str());
1108  }
1109 
1110  ret=false;
1111  }
1112  }
1113  else
1114  {
1115  if (exception)
1116  {
1117  throw std::invalid_argument(std::string("Cannot open file for reading: ")+name);
1118  }
1119 
1120  ret=false;
1121  }
1122 
1123  return ret;
1124 }
1125 
1126 }
bool getBoolean(const std::shared_ptr< GenApi::CNodeMapRef > &nodemap, const char *name, bool exception, bool igncache)
Get the value of a boolean feature of the given nodemap.
Definition: config.cc:518
bool setIPV4Address(const std::shared_ptr< GenApi::CNodeMapRef > &nodemap, const char *name, const char *value, bool exception)
Set the value of an integer feature of the given nodemap from an IP address.
Definition: config.cc:198
Hex number in an edit control.
Definition: Types.h:94
Connects a chunked DCAM buffer to a node map.
IFloat interface.
Definition: Types.h:195
GENICAM_INTERFACE GENAPI_DECL_ABSTRACT IBoolean
Interface for Boolean properties.
Definition: IBoolean.h:61
Definition: PFNC.h:306
GENICAM_INTERFACE IInteger
Interface for integer properties.
Definition: IFloat.h:114
Definition of ODevFileStream and IDevFileStream.
std::istream & getline(std::istream &is, GENICAM_NAMESPACE::gcstring &str)
STL getline.
Definition: GCString.h:194
std::shared_ptr< GenApi::CChunkAdapter > getChunkAdapter(const std::shared_ptr< GenApi::CNodeMapRef > &nodemap, const std::string &tltype)
NOTE: This function is deprecated.
Definition: config.cc:912
Adapter between the std::iostreambuf and the SFNC Features representing the device filesystem...
Definition: Filestream.h:106
std::string loadFile(const std::shared_ptr< GenApi::CNodeMapRef > &nodemap, const char *name, bool exception)
Loads the contents of a file via the GenICam FileAccessControl interface.
Definition: config.cc:1018
Declaration of the CChunkAdapterGeneric class.
__int64 int64_t
Definition: config-win32.h:21
int64_t getInteger(const std::shared_ptr< GenApi::CNodeMapRef > &nodemap, const char *name, int64_t *vmin, int64_t *vmax, bool exception, bool igncache)
Get the value of an integer feature of the given nodemap.
Definition: config.cc:563
virtual GenICam_streamsize write(const char *buf, int64_t offs, int64_t len, const char *pFileName)
writes data into a file
size_t getWidth(std::uint32_t part) const
Returns the width of the image in pixel.
Definition: buffer.cc:344
std::string str()
bool setFloat(const std::shared_ptr< GenApi::CNodeMapRef > &nodemap, const char *name, double value, bool exception)
Set the value of a float feature of the given nodemap.
Definition: config.cc:255
virtual GENICAM_NAMESPACE::gcstring GetSymbolic() const =0
Get symbolic enum value.
bool IsReadable(EAccessMode AccessMode)
Tests if readable.
Definition: INode.h:178
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:301
GENICAM_INTERFACE GENAPI_DECL_ABSTRACT ICommand
Interface for command like properties.
Definition: ICommand.h:59
IString interface.
Definition: Types.h:196
IBoolean interface.
Definition: Types.h:193
bool getImagePresent(std::uint32_t part) const
Returns if a 2D, 3D or confidence image is present in the specified part.
Definition: buffer.cc:472
The buffer class encapsulates a Genicam buffer that is provided by a stream.
Definition: buffer.h:118
bool saveFile(const std::shared_ptr< GenApi::CNodeMapRef > &nodemap, const char *name, const std::string &data, bool exception)
Loads the contents of the given string as a file via the GenICam FileAccessControl interface...
Definition: config.cc:1080
Declaration of the CChunkAdapterGEV class.
node_vector NodeList_t
a list of node references
Definition: INode.h:55
void checkFeature(const std::shared_ptr< GenApi::CNodeMapRef > &nodemap, const char *name, const char *value, bool igncache)
Checks the value of given feature and throws an exception in case of a mismatch.
Definition: config.cc:899
size_t getHeight(std::uint32_t part) const
Returns the height of the image in pixel.
Definition: buffer.cc:369
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:676
#define Error8
Definition: pixel_formats.h:46
GENICAM_INTERFACE GENAPI_DECL_ABSTRACT IEnumeration
Interface for enumeration properties.
Definition: IEnumeration.h:60
std::string getComponetOfPart(const std::shared_ptr< GenApi::CNodeMapRef > &nodemap, const Buffer *buffer, uint32_t ipart)
Definition: config.cc:936
virtual bool openFile(const char *pFileName, std::ios_base::openmode mode)
open a file on the device
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
virtual bool attach(GENAPI_NAMESPACE::INodeMap *pInterface)
attach file protocol adapter to nodemap
uint64_t getPixelFormat(std::uint32_t part) const
Returns the pixel format of the specified part as defined in the PFNC.
Definition: buffer.cc:519
virtual GenICam_streamsize read(char *buf, int64_t offs, GenICam_streamsize len, const char *pFileName)
read data from the device into a buffer
bool setBoolean(const std::shared_ptr< GenApi::CNodeMapRef > &nodemap, const char *name, bool value, bool exception)
Set the value of a boolean feature of the given nodemap.
Definition: config.cc:106
double getFloat(const std::shared_ptr< GenApi::CNodeMapRef > &nodemap, const char *name, double *vmin, double *vmax, bool exception, bool igncache)
Get the value of a double feature of the given nodemap.
Definition: config.cc:625
bool callCommand(const std::shared_ptr< GenApi::CNodeMapRef > &nodemap, const char *name, bool exception)
Calls the given command.
Definition: config.cc:60
Connects a generic chunked buffer to a node map.
IEnumeration interface.
Definition: Types.h:199
GENICAM_INTERFACE GENAPI_DECL_ABSTRACT IString
Interface for string properties.
Definition: IString.h:61
Definition: buffer.cc:47
bool IsWritable(EAccessMode AccessMode)
Tests if writable.
Definition: INode.h:196
GENICAM_INTERFACE GENAPI_DECL_ABSTRACT IFloat
Interface for float properties.
Definition: IFloat.h:60
bool setInteger(const std::shared_ptr< GenApi::CNodeMapRef > &nodemap, const char *name, int64_t value, bool exception)
Set the value of an integer feature of the given nodemap.
Definition: config.cc:152
GENICAM_INTERFACE INode
Interface common to all nodes.
Definition: ICategory.h:51
GenICam&#39;s exception class.
Definition: GCException.h:63
GENICAM_NAMESPACE::gcstring_vector StringList_t
A list of strings.
Definition: Types.h:149
IInteger interface.
Definition: Types.h:192
GENICAM_INTERFACE GENAPI_DECL_ABSTRACT IEnumEntry
Interface of single enum value.
Definition: IEnumEntry.h:60
std::string getString(const std::shared_ptr< GenApi::CNodeMapRef > &nodemap, const char *name, bool exception, bool igncache)
Get the value of a feature of the given nodemap.
Definition: config.cc:794
Connects a chunked U3V buffer to a node map.
virtual bool closeFile(const char *pFileName)
close a file on the device
virtual const char * what() const
Get error description (overwrite from std:exception)
Declaration of the CChunkAdapterU3V class.


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