61 bool callCommand(
const std::shared_ptr<GenApi::CNodeMapRef> &nodemap,
const char *name,
83 throw std::invalid_argument(std::string(
"Feature not a command: ")+name);
88 throw std::invalid_argument(std::string(
"Feature not writable: ")+name);
93 throw std::invalid_argument(std::string(
"Feature not found: ")+name);
100 throw std::invalid_argument(ex.
what());
107 bool setBoolean(
const std::shared_ptr<GenApi::CNodeMapRef> &nodemap,
const char *name,
108 bool value,
bool exception)
124 val->SetValue(value);
129 throw std::invalid_argument(std::string(
"Feature not boolean: ")+name);
134 throw std::invalid_argument(std::string(
"Feature not writable: ")+name);
139 throw std::invalid_argument(std::string(
"Feature not found: ")+name);
146 throw std::invalid_argument(ex.
what());
153 bool setInteger(
const std::shared_ptr<GenApi::CNodeMapRef> &nodemap,
const char *name,
170 val->SetValue(value);
175 throw std::invalid_argument(std::string(
"Feature not integer: ")+name);
180 throw std::invalid_argument(std::string(
"Feature not writable: ")+name);
185 throw std::invalid_argument(std::string(
"Feature not found: ")+name);
192 throw std::invalid_argument(ex.
what());
199 bool setIPV4Address(
const std::shared_ptr<GenApi::CNodeMapRef> &nodemap,
const char *name,
200 const char *value,
bool exception)
218 std::stringstream in(value);
221 for (
int i=0; i<4; i++)
224 ip=(ip<<8)|(stoi(elem)&0xff);
232 throw std::invalid_argument(std::string(
"Feature not integer: ")+name);
237 throw std::invalid_argument(std::string(
"Feature not writable: ")+name);
242 throw std::invalid_argument(std::string(
"Feature not found: ")+name);
249 throw std::invalid_argument(ex.
what());
256 bool setFloat(
const std::shared_ptr<GenApi::CNodeMapRef> &nodemap,
const char *name,
257 double value,
bool exception)
273 val->SetValue(value);
278 throw std::invalid_argument(std::string(
"Feature not float: ")+name);
283 throw std::invalid_argument(std::string(
"Feature not writable: ")+name);
288 throw std::invalid_argument(std::string(
"Feature not found: ")+name);
295 throw std::invalid_argument(ex.
what());
302 bool setEnum(
const std::shared_ptr<GenApi::CNodeMapRef> &nodemap,
const char *name,
303 const char *value,
bool exception)
323 entry=val->GetEntryByName(value);
330 val->SetIntValue(entry->GetValue());
336 throw std::invalid_argument(std::string(
"Enumeration '")+name+
337 "' does not contain: "+value);
342 throw std::invalid_argument(std::string(
"Feature not enumeration: ")+name);
347 throw std::invalid_argument(std::string(
"Feature not writable: ")+name);
352 throw std::invalid_argument(std::string(
"Feature not found: ")+name);
359 throw std::invalid_argument(ex.
what());
366 size_t setRegister(
const std::shared_ptr<GenApi::CNodeMapRef> &nodemap,
const char *name,
367 const uint8_t *buffer,
size_t len,
bool exception)
383 len=std::min(len,
static_cast<size_t>(val->GetLength()));
384 val->Set(buffer, len);
389 throw std::invalid_argument(std::string(
"Feature not of type register: ")+name);
394 throw std::invalid_argument(std::string(
"Feature not writable: ")+name);
399 throw std::invalid_argument(std::string(
"Feature not found: ")+name);
406 throw std::invalid_argument(ex.
what());
413 bool setString(
const std::shared_ptr<GenApi::CNodeMapRef> &nodemap,
const char *name,
414 const char *value,
bool exception)
426 switch (node->GetPrincipalInterfaceType())
432 std::string v=std::string(value);
433 if (v ==
"true" || v ==
"True" || v ==
"TRUE")
437 else if (v ==
"false" || v ==
"False" || v ==
"FALSE")
443 p->SetValue(
static_cast<bool>(std::stoi(v)));
452 switch (p->GetRepresentation())
455 p->SetValue(std::stoll(std::string(value), 0, 16));
462 std::stringstream in(value);
465 for (
int i=0; i<4; i++)
468 ip=(ip<<8)|(stoi(elem)&0xff);
479 std::stringstream in(value);
482 for (
int i=0; i<4; i++)
485 mac=(mac<<8)|(stoi(elem, 0, 16)&0xff);
493 p->SetValue(std::stoll(std::string(value)));
502 p->SetValue(std::stof(std::string(value)));
513 entry=p->GetEntryByName(value);
520 p->SetIntValue(entry->GetValue());
524 throw std::invalid_argument(std::string(
"Enumeration '")+name+
525 "' does not contain: "+value);
536 size_t n=s.find_first_not_of(
"0123456789abcdefABCDEF");
537 if (n != std::string::npos)
539 throw std::invalid_argument(std::string(
"Register '")+name+
540 "only accepts hedadecimal values: "+s);
543 std::vector<uint8_t> buffer;
544 for (
size_t i=0; i<s.size()-1; i+=2)
546 buffer.push_back(stoi(s.substr(i, 2), 0, 16));
549 p->Set(buffer.data(), std::min(buffer.size(),
static_cast<size_t>(p->GetLength())));
563 throw std::invalid_argument(std::string(
"Feature of unknown datatype: ")+name);
570 throw std::invalid_argument(std::string(
"Feature not writable: ")+name);
575 throw std::invalid_argument(std::string(
"Feature not found: ")+name);
582 throw std::invalid_argument(ex.
what());
589 bool getBoolean(
const std::shared_ptr<GenApi::CNodeMapRef> &nodemap,
const char *name,
590 bool exception,
bool igncache)
606 ret=val->GetValue(
false, igncache);
610 throw std::invalid_argument(std::string(
"Feature not boolean: ")+name);
615 throw std::invalid_argument(std::string(
"Feature not readable: ")+name);
620 throw std::invalid_argument(std::string(
"Feature not found: ")+name);
627 throw std::invalid_argument(ex.
what());
639 if (vmin != 0) *vmin=0;
640 if (vmax != 0) *vmax=0;
653 ret=p->GetCurrentEntry(
false, igncache)->GetValue();
655 if (vmin != 0) *vmin=ret;
656 if (vmax != 0) *vmax=ret;
664 ret=val->GetValue(
false, igncache);
666 if (vmin != 0) *vmin=val->GetMin();
667 if (vmax != 0) *vmax=val->GetMax();
671 throw std::invalid_argument(std::string(
"Feature not integer: ")+name);
677 throw std::invalid_argument(std::string(
"Feature not readable: ")+name);
682 throw std::invalid_argument(std::string(
"Feature not found: ")+name);
689 throw std::invalid_argument(ex.
what());
696 double getFloat(
const std::shared_ptr<GenApi::CNodeMapRef> &nodemap,
const char *name,
697 double *vmin,
double *vmax,
bool exception,
bool igncache)
701 if (vmin != 0) *vmin=0;
702 if (vmax != 0) *vmax=0;
716 ret=val->GetValue(
false, igncache);
718 if (vmin != 0) *vmin=val->GetMin();
719 if (vmax != 0) *vmax=val->GetMax();
723 throw std::invalid_argument(std::string(
"Feature not float: ")+name);
728 throw std::invalid_argument(std::string(
"Feature not readable: ")+name);
733 throw std::invalid_argument(std::string(
"Feature not found: ")+name);
740 throw std::invalid_argument(ex.
what());
747 std::string
getEnum(
const std::shared_ptr<GenApi::CNodeMapRef> &nodemap,
const char *name,
768 ret=entry->GetSymbolic();
772 throw std::invalid_argument(std::string(
"Current value is not defined: ")+name);
777 throw std::invalid_argument(std::string(
"Feature not enumeration: ")+name);
782 throw std::invalid_argument(std::string(
"Feature not readable: ")+name);
787 throw std::invalid_argument(std::string(
"Feature not found: ")+name);
794 throw std::invalid_argument(ex.
what());
801 std::string
getEnum(
const std::shared_ptr<GenApi::CNodeMapRef> &nodemap,
const char *name,
802 std::vector<std::string> &list,
bool exception)
821 val->GetSymbolics(entries);
823 for (
size_t i=0; i<entries.size(); i++)
825 list.push_back(std::string(entries[i]));
832 ret=entry->GetSymbolic();
836 throw std::invalid_argument(std::string(
"Current value is not defined: ")+name);
841 throw std::invalid_argument(std::string(
"Feature not enumeration: ")+name);
846 throw std::invalid_argument(std::string(
"Feature not readable: ")+name);
851 throw std::invalid_argument(std::string(
"Feature not found: ")+name);
858 throw std::invalid_argument(ex.
what());
865 size_t getRegister(
const std::shared_ptr<GenApi::CNodeMapRef> &nodemap,
const char *name,
866 uint8_t *buffer,
size_t len,
size_t *total,
bool exception,
bool igncache)
870 if (total != 0) *total=0;
884 size_t n=
static_cast<size_t>(p->GetLength());
888 len=std::min(len, n);
889 p->Get(buffer,
static_cast<int64_t>(len));
894 throw std::invalid_argument(std::string(
"Feature not of type register: ")+name);
899 throw std::invalid_argument(std::string(
"Feature not readable: ")+name);
904 throw std::invalid_argument(std::string(
"Feature not found: ")+name);
911 throw std::invalid_argument(ex.
what());
918 std::string
getString(
const std::shared_ptr<GenApi::CNodeMapRef> &nodemap,
const char *name,
919 bool exception,
bool igncache)
931 switch (node->GetPrincipalInterfaceType())
936 out << p->GetValue(
false, igncache);
943 int64_t value=p->GetValue(
false, igncache);
945 switch (p->GetRepresentation())
948 out << std::hex << value;
952 out << ((value>>24)&0xff) <<
'.' << ((value>>16)&0xff) <<
'.'
953 << ((value>>8)&0xff) <<
'.' << (value&0xff);
957 out << std::hex << std::setfill(
'0');
958 out << std::setw(2) << ((value>>40)&0xff) <<
':'
959 << std::setw(2) << ((value>>32)&0xff) <<
':'
960 << std::setw(2) << ((value>>24)&0xff) <<
':'
961 << std::setw(2) << ((value>>16)&0xff) <<
':'
962 << std::setw(2) << ((value>>8)&0xff) <<
':'
963 << std::setw(2) << (value&0xff);
976 out << p->GetValue(
false, igncache);
983 out << p->GetCurrentEntry()->GetSymbolic();
991 int len=std::min(
static_cast<int>(p->GetLength()), 32);
997 for (
int i=0; i<len; i++)
999 out << std::setfill('0') << std::setw(2) << static_cast<int>(buffer[i]);
1007 out << p->GetValue(
false, igncache);
1014 throw std::invalid_argument(std::string(
"Feature of unknown datatype: ")+name);
1021 throw std::invalid_argument(std::string(
"Feature not readable: ")+name);
1026 throw std::invalid_argument(std::string(
"Feature not found: ")+name);
1033 throw std::invalid_argument(ex.
what());
1040 void checkFeature(
const std::shared_ptr<GenApi::CNodeMapRef> &nodemap,
const char *name,
1041 const char *value,
bool igncache)
1043 std::string cvalue=
getString(nodemap, name,
true, igncache);
1045 if (cvalue !=
"" && cvalue != value)
1048 out << name <<
" == " << value <<
" expected: " << cvalue;
1049 throw std::invalid_argument(out.
str());
1053 std::shared_ptr<GenApi::CChunkAdapter>
getChunkAdapter(
const std::shared_ptr<GenApi::CNodeMapRef> &nodemap,
1054 const std::string &tltype)
1056 std::shared_ptr<GenApi::CChunkAdapter> chunkadapter;
1058 if (
setBoolean(nodemap,
"ChunkModeActive",
true))
1060 if (tltype ==
"GEV")
1064 else if (tltype ==
"U3V")
1074 return chunkadapter;
1078 const Buffer *buffer, uint32_t ipart)
1080 std::string component;
1089 if (sel != 0 && part != 0)
1096 sel->GetEntries(list);
1098 for (
size_t i=0; i<list.size() && component.size() == 0; i++)
1104 sel->SetIntValue(entry->GetValue());
1116 catch (
const std::exception &)
1131 component=
"Intensity";
1135 component=
"IntensityCombined";
1140 component=
"Disparity";
1144 component=
"Confidence";
1159 std::string
loadFile(
const std::shared_ptr<GenApi::CNodeMapRef> &nodemap,
const char *name,
1167 rf.
attach(nodemap->_Ptr);
1169 if (rf.
openFile(name, std::ios::in))
1171 int length=std::numeric_limits<int>::max();
1177 catch (
const std::exception &)
1180 size_t off=0, n=512;
1181 std::vector<char> buffer(512);
1183 while (n > 0 && length > 0)
1185 n=rf.
read(buffer.data(), off, std::min(length,
static_cast<int>(buffer.size())), name);
1195 n=rf.
read(buffer.data(), off, n, name);
1201 ret.append(buffer.data(), n);
1214 throw std::invalid_argument(std::string(
"Cannot open file for reading: ")+name);
1221 bool saveFile(
const std::shared_ptr<GenApi::CNodeMapRef> &nodemap,
const char *name,
1222 const std::string &data,
bool exception)
1229 rf.
attach(nodemap->_Ptr);
1231 if (rf.
openFile(name, std::ios::out))
1233 size_t off=0, n=512;
1236 n=rf.
write(data.c_str()+off, off, std::min(
static_cast<size_t>(512), data.size()-off), name);
1242 if (off != data.size())
1247 out <<
"Error: Can only write " << off <<
" of " << data.size() <<
" bytes";
1248 throw std::invalid_argument(out.
str());
1258 throw std::invalid_argument(std::string(
"Cannot open file for writing: ")+name);
1277 in.exceptions(std::ios_base::failbit | std::ios_base::badbit);
1287 catch (
const std::exception &ex)
1291 throw std::invalid_argument(ex.what());
1298 throw std::invalid_argument(ex.
what());
1317 out.exceptions(std::ios_base::failbit | std::ios_base::badbit);
1325 catch (
const std::exception &ex)
1329 throw std::invalid_argument(ex.what());
1336 throw std::invalid_argument(ex.
what());