void LLCCEP_tools::commandLineParametersParser::addFlag( LLCCEP_tools::commandLineFlag clf) { auto checkMnemonicsOK = [this, &clf] { for (const auto &i: clf.possibleMnemonics) { for (const auto &j: flags) { for (const auto &k: j.possibleMnemonics) { if (i == k) { throw RUNTIME_EXCEPTION(CONSTRUCT_MSG( "Redeclaring '%s' parameter mnemonic", k.c_str())); } } } } }; for (const auto &i: flags) { if (i.name == clf.name) { throw RUNTIME_EXCEPTION(CONSTRUCT_MSG( "Attempt of re-adding '%s' param", clf.name.c_str())); } } checkMnemonicsOK(); flags.push_back(clf); }
void LLCCEP_exec::softcore::set(LLCCEP::arg data, double val) { SOFTCORE_OK; switch (data.type) { case LLCCEP_ASM::LEX_T_REG: if (DBL_AE(data.val, 32) || DBL_LESS(data.val, 0)) { throw RUNTIME_EXCEPTION(CONSTRUCT_MSG( "Error!\n" "Overbounding while writing data to register!\n")); } else { regs[static_cast<size_t>(data.val)] = val; } break; case LLCCEP_ASM::LEX_T_MEM: (*mm)[static_cast<size_t>(data.val)] = val; break; default: throw RUNTIME_EXCEPTION(CONSTRUCT_MSG( "Error!\n" "Invalid or damaged binary file: invalid writing!\n")); } SOFTCORE_OK; }
void LLCCEP_exec::softcore::emulated_ldregs(LLCCEP::instruction data) { SOFTCORE_OK; static_cast<void>(data); if (!registersStore.size()) { throw RUNTIME_EXCEPTION(CONSTRUCT_MSG( "Error: registersStore is empty, " "cannot rollback registers states")); } double *oldRegs = *(registersStore.end() - 1); if (!oldRegs) { throw RUNTIME_EXCEPTION(CONSTRUCT_MSG( "Invalid registers storage pointer: cannot rollback")) } memcpy(regs, oldRegs, 32 * sizeof(double)); delete oldRegs; registersStore.pop_back(); SOFTCORE_OK; }
void LLCCEP_tools::commandLineParametersParser::parse(int argn, char **argv) { for (int i = 1; i < argn; i++) { auto param = isParam(argv[i]); if (param != flags.end()) { bool follow = followed(argv[i]); if (follow && i == argn - 1) { throw RUNTIME_EXCEPTION(CONSTRUCT_MSG( "Sudden end after '%s'", argv[i])); } else if (follow) { param->following = argv[++i]; } else if (!follow) { param->following = "1"; } } else if (maxFreeParams != (static_cast<size_t>(-1)) && freeParams.size() > maxFreeParams) { throw RUNTIME_EXCEPTION(CONSTRUCT_MSG( "Too many free parameters")); } else { freeParams.push_back(argv[i]); } } }
double LLCCEP_exec::softcore::get(LLCCEP::arg data) { SOFTCORE_OK; switch (data.type) { case LLCCEP_ASM::LEX_T_REG: if (static_cast<size_t>(data.val) >= 32) { throw RUNTIME_EXCEPTION(CONSTRUCT_MSG( "Error!\n" "Overbounding while reading data from register!\n")); } else { return regs[static_cast<size_t>(data.val)]; } break; case LLCCEP_ASM::LEX_T_MEM: return (*mm)[static_cast<size_t>(data.val)]; break; case LLCCEP_ASM::LEX_T_COND: case LLCCEP_ASM::LEX_T_VAL: return data.val; break; default: throw RUNTIME_EXCEPTION(CONSTRUCT_MSG( "Error!\n" "Invalid or damaged binary file: invalid reading!\n")); } return 0.0f; }
//////////////////////////////////////////////////////////////////////////////// //! Read args as token value pair into map for better processing (Even the //! values remain strings until the parameter values is requested by the //! program.) //! @param argc the argument count (as given to 'main') //! @param argv the char* array containing the command line arguments //////////////////////////////////////////////////////////////////////////////// void CmdArgReader::createArgsMaps( const int argc, const char** argv) { std::string token; std::string val_str; std::map< std::string, std::string> args; std::string::size_type pos; std::string arg; for( int i=1; i<argc; ++i) { arg = argv[i]; // check if valid command line argument: all arguments begin with - or -- if (arg[0] != '-') { RUNTIME_EXCEPTION("Invalid command line argument."); } int numDashes = (arg[1] == '-' ? 2 : 1); // check if only flag or if a value is given if ( (pos = arg.find( '=')) == std::string::npos) { unprocessed[ std::string( arg, numDashes, arg.length()-numDashes)] = "FLAG"; } else { unprocessed[ std::string( arg, numDashes, pos-numDashes)] = std::string( arg, pos+1, arg.length()-1); } } }
::std::string LLCCEP_debugger::debugCore::currentCodeInfo() const { /* Result */ ::std::stringstream res; /* Get code reader */ LLCCEP::codeReader *reader = softcore::reader; if (!reader) { throw RUNTIME_EXCEPTION(CONSTRUCT_MSG( "Invalid reader for debugCore")); } /* Filename */ ::std::string fname = reader->getInstructionFile(softcore::pc); res << "__________________________________________________" << ::std::endl << "Disassembly dump of '" << fname << "':" << ::std::endl; size_t line = reader->getInstructionLine(pc); res << "==> " << line << " | " << LLCCEP::getInstructionMnemonic(reader->getInstruction(pc)) << ::std::endl; return res.str(); }
LLCCEP::ramValue LLCCEP::IRGenerator::createVariable(std::string varName) { IR_GENERATOR_OK; if (vars.find(varName) != vars.end()) { throw RUNTIME_EXCEPTION(CONSTRUCT_MSG( "'%s' variable was already declared", varName.c_str())); } size_t ptr; if (released.size()) { ptr = *(released.end() - 1); released.pop_back(); } else { ptr = freeptr; freeptr++; } vars[varName] = ptr; IR_GENERATOR_OK; return LLCCEP::ramValue(vars); }
void LLCCEP::IRGenerator::outputFile(::std::FILE *out = stdout) { if (!out) { throw RUNTIME_EXCEPTION(CONSTRUCT_MSG( "Invalid output file to IR generator")); } output = out; }
void LLCCEP_exec::softcore::setMm(LLCCEP_exec::memoryManager *newMm) { /* If memory manager is already * setted up and ok */ if (ready & LLCCEP_exec::softcore::MM_READY) { throw RUNTIME_EXCEPTION(CONSTRUCT_MSG( "An attempt of re-setting memory manager\n" "for softcore [" ptr_pf "]", this)); } if (!newMm) { throw RUNTIME_EXCEPTION(CONSTRUCT_MSG( "An attempt of setting memory manager pointer to invalid\n" "for softcore [" ptr_pf "]", this)); } mm = newMm; ready |= LLCCEP_exec::softcore::MM_READY; }
void LLCCEP_exec::softcore::executeNextInstruction() { SOFTCORE_OK; void (LLCCEP_exec::softcore::*funcs[])(LLCCEP::instruction) = { &LLCCEP_exec::softcore::emulated_mov, &LLCCEP_exec::softcore::emulated_mav, &LLCCEP_exec::softcore::emulated_mva, &LLCCEP_exec::softcore::emulated_push, &LLCCEP_exec::softcore::emulated_pop, &LLCCEP_exec::softcore::emulated_top, &LLCCEP_exec::softcore::emulated_add, &LLCCEP_exec::softcore::emulated_sub, &LLCCEP_exec::softcore::emulated_mul, &LLCCEP_exec::softcore::emulated_div, &LLCCEP_exec::softcore::emulated_and, &LLCCEP_exec::softcore::emulated_or, &LLCCEP_exec::softcore::emulated_xor, &LLCCEP_exec::softcore::emulated_off, &LLCCEP_exec::softcore::emulated_nop, &LLCCEP_exec::softcore::emulated_swi, &LLCCEP_exec::softcore::emulated_cmp, &LLCCEP_exec::softcore::emulated_inc, &LLCCEP_exec::softcore::emulated_dec, &LLCCEP_exec::softcore::emulated_sqrt, &LLCCEP_exec::softcore::emulated_sin, &LLCCEP_exec::softcore::emulated_cos, &LLCCEP_exec::softcore::emulated_ptan, &LLCCEP_exec::softcore::emulated_patan, &LLCCEP_exec::softcore::emulated_ldc, &LLCCEP_exec::softcore::emulated_call, &LLCCEP_exec::softcore::emulated_jmp, &LLCCEP_exec::softcore::emulated_ret, &LLCCEP_exec::softcore::emulated_stregs, &LLCCEP_exec::softcore::emulated_ldregs }; LLCCEP::instruction inst{}; if (pc >= reader->getProgramData().size) { quit = true; return; } inst = reader->getInstruction(pc); if (inst.opcode >= LLCCEP_ASM::INST_NUM) { throw RUNTIME_EXCEPTION(CONSTRUCT_MSG( "Opcode overbound!")); } (this->*funcs[inst.opcode])(inst); pc++; SOFTCORE_OK; }
bool LLCCEP_tools::commandLineParametersParser::followed(::std::string mnem) { auto param = isParam(mnem); if (param == flags.end()) { throw RUNTIME_EXCEPTION(CONSTRUCT_MSG( "Not param '%s'", mnem.c_str())); } return param->followed; }
void LLCCEP_exec::softcore::setCodeReader(LLCCEP::codeReader *newReader) { /* If code reader is already * setted up and ok */ if (ready & LLCCEP_exec::softcore::CR_READY) { throw RUNTIME_EXCEPTION(CONSTRUCT_MSG( "An attempt of re-setting code reader\n" "for softocore [" ptr_pf "]", this)); } if (!newReader) { throw RUNTIME_EXCEPTION(CONSTRUCT_MSG( "An attempt of setting reader pointer to invalid\n" "for softcore [" ptr_pf "]", this)); } reader = newReader; ready |= LLCCEP_exec::softcore::CR_READY; }
void LLCCEP_ASM::analyzer::analyzerIssue(::std::string file, size_t line, const char *fmt, ...) { va_list list; va_start(list, fmt); char res[4096]; vsprintf(res, fmt, list); va_end(list); ::std::string absPath = filesystem::getAbsolutePath(file); throw RUNTIME_EXCEPTION(CONSTRUCT_MSG("%s:" size_t_pf ":\n%s", absPath.c_str(), line, res)); }
void LLCCEP_exec::softcore::emulated_top(LLCCEP::instruction data) { SOFTCORE_OK; if (!stk.size()) { throw RUNTIME_EXCEPTION(CONSTRUCT_MSG( "Error!\n" "Can't get top: stack is empty!\n")); } set(data.args[0], *(stk.end() - 1)); SOFTCORE_OK; }
void LLCCEP_debugger::debugCore::continueExecution() { DEBUG_CORE_OK; if (gotError) { gotError = false; ::std::cerr << "Got an error, restarting program" << ::std::endl; softcore::pc = softcore::reader->getProgramData().main_id; } auto breakpointReached = [this]() { ::std::string fname = softcore::reader->getInstructionFile(softcore::pc); size_t line = softcore::reader->getInstructionLine(softcore::pc); for (auto i = breakpoints.begin(); i < breakpoints.end(); i++) { if (i->fname == fname && i->line == line) return i; } return breakpoints.end(); }; QEventLoop ev; while (running()) { auto bp = breakpointReached(); if (bp != breakpoints.end() && bp->active && !forcedExecution) { forcedExecution = true; break; } else if (bp != breakpoints.end() && bp->active && forcedExecution) { forcedExecution = false; } try { softcore::executeNextInstruction(); } catch (::LLCCEP::runtime_exception &exc) { ::std::cerr << "Execution was interrupted by an exception:" << ::std::endl << exc.msg() << ::std::endl; gotError = true; break; } catch (...) { throw RUNTIME_EXCEPTION(CONSTRUCT_MSG( "Got runtime error while program execution")); } ev.processEvents(QEventLoop::AllEvents, 100); } DEBUG_CORE_OK; }
void LLCCEP::IRGenerator::releaseVariable(::std::string varName) { IR_GENERATOR_OK; auto f = vars.find(varName); if (f == vars.end()) { throw RUNTIME_EXCEPTION(CONSTRUCT_MSG( "Invalid '%s' variable to free", varName.c_str())) } released.push_back(f->second); vars.erase(f); IR_GENERATOR_OK; }
void LLCCEP_exec::softcore::emulated_pop(LLCCEP::instruction data) { SOFTCORE_OK; static_cast<void>(data); if (!stk.size()) { throw RUNTIME_EXCEPTION(CONSTRUCT_MSG( "Error!\n" "Can't pop: stack is empty!\n")); } stk.pop_back(); SOFTCORE_OK; }
void LLCCEP_exec::softcore::emulated_stregs(LLCCEP::instruction data) { SOFTCORE_OK; static_cast<void>(data); double *newRegs = new (::std::nothrow) double[32]; if (!newRegs) { throw RUNTIME_EXCEPTION(CONSTRUCT_MSG( "Cannot allocate memory for registers copy")); } memcpy(newRegs, regs, 32 * sizeof(double)); registersStore.push_back(newRegs); SOFTCORE_OK; }
::std::string LLCCEP_tools::commandLineParametersParser::getParam( ::std::string name) { auto find = [this, name] { for (auto i = flags.begin(); i < flags.end(); i++) if (i->name == name) return i; return flags.end(); }; if (find() == flags.end()) { throw RUNTIME_EXCEPTION(CONSTRUCT_MSG( "No such flag '%s'", name.c_str())); } return find()->following; }
//////////////////////////////////////////////////////////////////////////////// //! Read args as token value pair into map for better processing (Even the //! values remain strings until the parameter values is requested by the //! program.) //! @param argc the argument count (as given to 'main') //! @param argv the char* array containing the command line arguments //////////////////////////////////////////////////////////////////////////////// void CmdArgReader::createArgsMaps( const int argc, const char** argv, const char *init_args) { std::string token; std::string val_str; std::map< std::string, std::string> args; std::string::size_type pos; std::string arg; if (init_args != 0) { char *tmp = new char[ strlen( init_args ) +1]; strcpy(tmp, init_args); char *p = strtok(tmp, " "); for ( ; p != 0 ; p = strtok(NULL, " ")) { arg = p; // check if valid command line argument: all arguments begin with - or -- if (arg[0] != '-') { RUNTIME_EXCEPTION("Invalid command line argument."); } int numDashes = (arg[1] == '-' ? 2 : 1); // check if only flag or if a value is given if ( (pos = arg.find( '=')) == std::string::npos) { unprocessed[ std::string( arg, numDashes, arg.length()-numDashes)] = "FLAG"; } else { unprocessed[ std::string( arg, numDashes, pos-numDashes)] = std::string( arg, pos+1, arg.length()-1); } //printf (" Default: %s\n", arg.c_str()); } delete[] tmp; } for( int i=1; i<argc; ++i) { arg = argv[i]; //printf(" %s\n", arg.c_str()); // check if valid command line argument: all arguments begin with - or -- if (arg[0] != '-') { continue; // Jimmy modified //RUNTIME_EXCEPTION("Invalid command line argument."); } int numDashes = (arg[1] == '-' ? 2 : 1); // check if only flag or if a value is given if ( (pos = arg.find( '=')) == std::string::npos) { unprocessed[ std::string( arg, numDashes, arg.length()-numDashes)] = "FLAG"; } else { unprocessed[ std::string( arg, numDashes, pos-numDashes)] = std::string( arg, pos+1, arg.length()-1); } } }
void LLCCEP_exec::softcore::emulated_swi(LLCCEP::instruction data) { SOFTCORE_OK; auto getFmtString = [](char c) -> ::std::string { switch (c) { case 'x': return "%x"; break; case 'b': return "%b"; break; case 'o': return "%o"; break; default: throw RUNTIME_EXCEPTION(CONSTRUCT_MSG( "Error!\n" "Invalid format!\n")); } }; auto getWindow = [this]() { size_t id = static_cast<size_t>(regs[1]); if (id >= windows.size()) { throw RUNTIME_EXCEPTION(CONSTRUCT_MSG( "Error!\n" "Overbounding while access to windows: " "no window with " size_t_pf " ID!\n", id)); } return windows[id]; }; auto checkf = [](FILE *fd, size_t function) { if (!fd) { throw RUNTIME_EXCEPTION(CONSTRUCT_MSG( "Error!\n" "File pointer at &01 register is 0.\n" "Interrupt 0:" size_t_pf "!\n", function)); } }; auto noFunction = [this](size_t interrupt) { throw RUNTIME_EXCEPTION(CONSTRUCT_MSG( "Error!\n" "No function " size_t_pf " of " size_t_pf " interrupt.\n", static_cast<size_t>(regs[1]), interrupt)); }; switch (static_cast<size_t>(get(data.args[0]))) { /************************************************** * Files stuff *************************************************/ case 0: { /************************************************** * Function selection *************************************************/ switch (static_cast<size_t>(regs[0])) { /************************************************** * Load standard file ptr to r02 * * r01 -- id of standard file * |-- 0 - stdin * |-- 1 - stdout * |-- 2 - stderr *************************************************/ case 0: { FILE *stdf[] = { stdin, stdout, stderr }; if (static_cast<size_t>(regs[1]) > 2) { throw RUNTIME_EXCEPTION(CONSTRUCT_MSG( "Error!\n" "In interrupt 0,0:\n" "not admitted id of standard file.\n" "Only values between 0 and 2 are allowed!\n")); } regs[2] = *reinterpret_cast<double *>(&(stdf[static_cast<size_t>(regs[1])])); break; } /************************************************** * Output to file. * * r01 -- pointer to file. * r02 -- output format. * r03 -- output value. * * Output formats: * - n -- number * - c -- character * - s -- string * - x -- hexadecimal number * - b -- binary number * - o -- octal number * * Output values by formats: * - n -- number * - c -- ASCII character id * - s -- string pointer * - x -- number * - b -- number * - o -- octal number *************************************************/ case 1: { FILE *out = *reinterpret_cast<FILE **>(®s[1]); char fmt = static_cast<char>(regs[2]); checkf(out, 1); switch (fmt) { case 'n': { ::std::fprintf(out, "%lg", regs[3]); break; } case 'c': { ::std::fprintf(out, "%c", static_cast<uint8_t>(regs[3])); break; } case 's': { ::std::fprintf(out, "%s", mm->getString(static_cast<size_t>(regs[3])).c_str()); break; } case 'x': case 'o': { ::std::fprintf(out, getFmtString(static_cast<char>(regs[2])).c_str(), *reinterpret_cast<size_t *>(®s[3])); break; } default: throw RUNTIME_EXCEPTION(CONSTRUCT_MSG( "Error!\n" "Forbidden format for 0,1 interrupt.")) } break; } /************************************************** * Input from file * * r01 -- pointer to file * r02 -- input format * r03 -- input place *************************************************/ case 2: { FILE *in = reinterpret_cast<FILE *>(*reinterpret_cast<void **>(®s[1])); checkf(in, 2); switch (static_cast<char>(regs[2])) { case 'n': { ::std::fscanf(in, "%lg", ®s[3]); break; } case 'c': { char tmp = 0; ::std::fscanf(in, "%c", &tmp); regs[3] = tmp; break; } case 's': { ::std::string str; char tmp = 0; bool beg = true; do { if (beg) beg = false; else str += tmp; tmp = fgetc(in); } while (tmp && !isspace(tmp)); mm->writeString(static_cast<size_t>(regs[3]), str); break; } case 'x': case 'o': { int64_t res; ::std::fscanf(in, getFmtString(static_cast<char>(regs[2])).c_str(), &res); break; } default: { throw RUNTIME_EXCEPTION(CONSTRUCT_MSG( "Error!\n" "Forbidden format for 0,2 interrupt.")) } } } /************************************************** * Open file. * * r01 will be pointer to opened file. * * r02 -- pointer to path's string * r03 -- pointer to format's string * * In case of fail, an exception will be thrown. *************************************************/ case 3: { ::std::string path = mm->getString(static_cast<size_t>(regs[2])); ::std::string fmt = mm->getString(static_cast<size_t>(regs[3])); FILE *res = fopen(path.c_str(), fmt.c_str()); if (!res) { throw RUNTIME_EXCEPTION(CONSTRUCT_MSG( "Error!\n" "Can't open '%s' file with '%s' mode: %s!\n", path.c_str(), fmt.c_str(), ::std::strerror(errno))); } regs[1] = *reinterpret_cast<double *>(&res); break; } /************************************************* * Close file. * * r01 -- pointer to file being closed. ************************************************/ case 4: { FILE *fd = reinterpret_cast<FILE *>(*reinterpret_cast<void **>(®s[1])); checkf(fd, 4); fclose(fd); break; } default: { noFunction(0); } } break; } /************************************************** * Windows stuff *************************************************/ case 1: { /************************************************** * Function selection *************************************************/ switch (static_cast<size_t>(regs[0])) { /************************************************** * Create window * * r01 -- width of new window * r02 -- height of new window * r03 -- pointer to window title string * r04 -- window flags * * r05 will be window's id. *************************************************/ case 0: { LLCCEP_exec::window *wnd = new (::std::nothrow) LLCCEP_exec::window; if (!wnd) { throw RUNTIME_EXCEPTION(CONSTRUCT_MSG( "Error!\n" "Can't allocate memory for window: %s", ::std::strerror(errno))); } int width = static_cast<int>(regs[1]), height = static_cast<int>(regs[2]); wnd->resize(width, height); wnd->show(); wnd->setWindowTitle(QApplication::translate( "emulator", mm->getString(static_cast<size_t>(regs[3])).c_str())); wnd->begin(width, height); wnd->setAntialiased(true); regs[4] = windows.size(); windows.push_back(wnd); break; } case 1: { LLCCEP_exec::window *wnd = getWindow(); wnd->painter().drawPoint(static_cast<int>(regs[2]), static_cast<size_t>(regs[3])); break; } case 2: { LLCCEP_exec::window *wnd = getWindow(); wnd->painter().setPen(QColor(static_cast<QRgb>(regs[2]))); break; } case 3: { LLCCEP_exec::window *wnd = getWindow(); wnd->close(); delete wnd; windows.erase(windows.begin() + static_cast<size_t>(regs[1])); break; } case 4: { LLCCEP_exec::window *wnd = getWindow(); regs[3] = wnd->getKeyboardButtonState((static_cast<size_t>(regs[2]) > 0xFF)? (0): (static_cast<size_t>(regs[2]))); regs[4] = wnd->getMousePos().x(); regs[5] = wnd->getMousePos().y(); regs[6] = wnd->getMouseButtons(); break; } case 5: { LLCCEP_exec::window *wnd = getWindow(); regs[2] = wnd->pos().x(); regs[3] = wnd->pos().y(); regs[4] = wnd->size().width(); regs[5] = wnd->size().height(); break; } case 6: { LLCCEP_exec::window *wnd = getWindow(); wnd->resize(static_cast<int>(regs[2]), static_cast<int>(regs[3])); break; } case 7: { LLCCEP_exec::window *wnd = getWindow(); wnd->move(static_cast<int>(regs[2]), static_cast<int>(regs[3])); break; } case 8: { LLCCEP_exec::window *wnd = getWindow(); wnd->setWindowTitle(mm->getString(static_cast<size_t>(regs[2])).c_str()); break; } case 9: { LLCCEP_exec::window *wnd = getWindow(); wnd->setWindowFlags(Qt::WindowFlags(static_cast<int>(regs[2]))); break; } default: { noFunction(1); } } break; } default: { throw RUNTIME_EXCEPTION(CONSTRUCT_MSG( "Error!\n" "No swi #" size_t_pf, static_cast<size_t>(get(data.args[0])))); } } SOFTCORE_OK; }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { // Parse parameters if(nrhs < 3) { mexErrMsgIdAndTxt( "baslerDriver:Error:ArgumentError", "Not enough arguments. Use help baslerGetParameter for further information."); } else if(nrhs > 4) { mexErrMsgIdAndTxt( "baslerDriver:Error:ArgumentError", "Too many arguments. Use help baslerGetParameter for further information."); } const int i_cam_number = (int)mxGetScalar(prhs[0]); const std::string s_param_name(mxArrayToString(prhs[1])); const std::string s_param_type(mxArrayToString(prhs[2])); // Map string to parameter type std::map<std::string,ParamType> paramMap = boost::assign::map_list_of ("Float",ParamType::Float) ("Int",ParamType::Int) ("Bool",ParamType::Bool) ("String",ParamType::String); // Get verbose parameter bool b_verbose = 0; if(nrhs == 4) { b_verbose = (int)mxGetScalar(prhs[3]) != 0; } // Initiatlize Pylon Pylon::PylonAutoInitTerm auto_init_term; try { // Get the transport layer factory. Pylon::CTlFactory& tlFactory = Pylon::CTlFactory::GetInstance(); // Get all attached devices Pylon::DeviceInfoList_t devices; int i_num_of_cameras = tlFactory.EnumerateDevices(devices); if ( i_num_of_cameras == 0 ) { throw RUNTIME_EXCEPTION( "No camera found."); } // Check if camera exists if (i_cam_number > i_num_of_cameras-1 ) { throw RUNTIME_EXCEPTION("No camera with this index exists."); } // Create camera object Pylon::CInstantCamera camera(tlFactory.CreateDevice(devices[i_cam_number])); // Open Camera camera.Open(); if(b_verbose) { mexPrintf("Using camera \"%s\"\n", camera.GetDeviceInfo().GetModelName().c_str()); } // Find type of parameter switch(paramMap[s_param_type]) { case ParamType::Float: { double d_param_value = BaslerHelper::get_float( &camera,s_param_name.c_str(),b_verbose); plhs[0] = mxCreateDoubleScalar(d_param_value); break; } case ParamType::Int: { int i_param_value = BaslerHelper::get_int( &camera,s_param_name.c_str(),b_verbose); plhs[0] = mxCreateNumericMatrix(1,1,mxINT64_CLASS,mxREAL); int64_t* p_output = (int64_t*) mxGetData(plhs[0]); p_output[0] = i_param_value; break; } case ParamType::Bool: { bool b_param_value = BaslerHelper::get_bool( &camera,s_param_name.c_str(),b_verbose); plhs[0] = mxCreateLogicalScalar(b_param_value); break; } case ParamType::String: { std::string s_param_value = BaslerHelper::get_string( &camera,s_param_name.c_str(),b_verbose); plhs[0] = mxCreateString(s_param_value.c_str()); break; } default: { mexErrMsgIdAndTxt( "baslerDriver:Error:ArgumentError", "Cannot detect type of parameter value."); break; } } // Close camera camera.Close(); } catch (GenICam::GenericException &e) { // Error handling. mexErrMsgIdAndTxt("baslerDriver:Error:CameraError",e.GetDescription()); } return; }