/* inp function for MATLAB 5.x By Gerox Programmed by Gerox 1999.July 6 This is only works under Windows95/98 */ #include #include #include #include "mex.h" void errorr(int line){ mexPrintf("Usage:\n"); mexPrintf(" data = inp('0x300'); string hex mode\n"); mexPrintf(" data = inp('300'); string dec mode \n"); mexPrintf(" data = inpp(300); scalar mode \n"); mexPrintf(" [addr,data]=inp('300'); output check mode \n"); mexPrintf(" Gerox(c) 1999 July 6 All rights reserved. \n"); mexPrintf(" This is only works under Windows95/98\n"); mexPrintf(" [%s]line %d\n",__FILE__,line); mexErrMsgTxt(""); } void mexFunction(int nlhs,mxArray *plhs[],int nrhs,const mxArray * prhs[]) { int i; char buf[256]; int buflen = 255; double ioadr,data; if(nrhs != 1) errorr(__LINE__); if((nlhs == 0)|| (nlhs == 1)|| (nlhs == 2)); else errorr(__LINE__); if (mxIsNumeric(prhs[0]) && mxIsDouble(prhs[0])) ioadr = mxGetScalar(prhs[0]); else if (mxIsChar(prhs[0])) { mxGetString(prhs[0],buf,buflen); if(buf[1] == 'x') sscanf(buf,"%x",&i); else sscanf(buf,"%d",&i); ioadr = (double)i; } else errorr(__LINE__); if(nlhs == 2) { plhs[0] = mxCreateDoubleMatrix(1,1,mxREAL); double* pdata = mxGetPr(plhs[0]); pdata[0] = ioadr; plhs[1] = mxCreateDoubleMatrix(1,1,mxREAL); pdata = mxGetPr(plhs[0]); pdata[0] = (double)_inp((int)ioadr); } else if(nlhs < 2) { plhs[0] = mxCreateDoubleMatrix(1,1,mxREAL); double* pdata = mxGetPr(plhs[0]); pdata[0] = (double)_inp((int)ioadr); } return; }