/* outp function for MATLAB 5.x By Gerox Programmed by Gerox 1999.July 6 This is only works under Windows95/98 */ #include #include #include #include #include #include "mex.h" void errorr(int line){ mexPrintf("Usage:\n"); mexPrintf(" outp('0x300','0x20'); string hex mode \n"); mexPrintf(" outp('300','20'); string dec mode \n"); mexPrintf(" outp(300,20); scalar mode \n"); mexPrintf(" [addr,data]=outp('300','20'); output check \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 != 2) errorr(__LINE__); if ((nlhs == 2) || (nlhs == 0)); 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 (mxIsNumeric(prhs[1]) && mxIsDouble(prhs[1])) data = mxGetScalar(prhs[1]); else if (mxIsChar(prhs[1])) { mxGetString(prhs[1],buf,buflen); if(buf[1] == 'x') sscanf(buf,"%x",&i); else sscanf(buf,"%d",&i); data = (double)i; } else errorr(__LINE__); _outp((int)ioadr,(int)data); if(nlhs == 2) { plhs[0] = mxCreateDoubleMatrix(1,1,mxREAL); double* pdata = mxGetPr(plhs[0]); pdata[0] = ioadr; plhs[1] = mxCreateDoubleMatrix(1,1,mxREAL); double* pdata2 = mxGetPr(plhs[1]); pdata2[0] = data; } return; }