📄 ttcreateinterrupthandler.cpp
字号:
#define KERNEL_MATLAB#include "../ttkernel.h" RTsys *rtsys;#include "../createhandler.cpp"#include "getrtsys.cpp"void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] ){ rtsys = getrtsys() ; // Get pointer to rtsys // Check number and type of arguments. if (nrhs < 3 || nrhs > 4) { mexErrMsgTxt("ttCreateInterruptHandler: Wrong number of input arguments!\nUsage: ttCreateInterruptHandler(name, priority, codefcn) \n ttCreateInterruptHandler(name, priority, codefcn, data)"); } if (mxIsChar(prhs[0]) != 1) { mexErrMsgTxt("ttCreateInterruptHandler: name must be a string"); } if (!mxIsDouble(prhs[1])) { mexErrMsgTxt("ttCreateInterruptHandler: priority must be a number"); } if (mxIsChar(prhs[2]) != 1 || mxGetM(prhs[2]) != 1) { mexErrMsgTxt("ttCreateInterruptHandler: codeFcn must be a non-empty string"); } char name[100]; mxGetString(prhs[0], name, 100); double priority = *mxGetPr(prhs[1]); char codeFcn[100]; mxGetString(prhs[2], codeFcn, 100); // Make sure that the code function exists in Matlab path // and that the code function is syntactically correct. mxArray *lhs[1]; mxArray *rhs[1]; rhs[0] = mxDuplicateArray(prhs[2]); mexCallMATLAB(1, lhs, 1, rhs, "exist"); int number = (int) *mxGetPr(lhs[0]); if (number == 0) { printf("ttCreateInterruptHandler: codeFcn '%s' not in path! Interrupt handler '%s' not created!\n", codeFcn, name); plhs[0] = mxCreateScalarDouble(0.0); return; } // Create handler if (ttCreateInterruptHandler(name, priority, NULL)) { // Add name of code function (m-file) and data variable HandlerNode *n = (HandlerNode*) rtsys->handlerList->getLast(); n->getHandler()->codeFcnMATLAB = new char[strlen(codeFcn)+1]; strcpy(n->getHandler()->codeFcnMATLAB, codeFcn); char dataname[100]; char blockhandle[16]; if (nrhs == 4) { // data specified // Create globally unique name for data: gcbh + handlername + "_handler_" mexCallMATLAB(1, lhs, 0, NULL, "gcbh"); // Get block handle sprintf(blockhandle, "%f", *(mxGetPr(lhs[0]))); strcpy(dataname, blockhandle); strcat(dataname, name); strcat(dataname, "_handler_"); // Write data structure to global workspace mxArray* data = mxDuplicateArray(prhs[3]); mexPutVariable("global", dataname, data); mxDestroyArray(data); n->getHandler()->dataMATLAB = new char[strlen(dataname)+1]; strcpy(n->getHandler()->dataMATLAB, dataname); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -