/* *Compile the mex file: mex LabJackSetDAC.c -L "LabJackud.lib" */ #include #include #include "mex.h" #include "C:\Program Files (x86)\LabJack\Drivers\LabJackUD.h" //taken from U3simple Examle code //This is our simple error handling function that is called after every UD //function call. This function displays the errorcode and string description //of the error. It also has a line number input that can be used with the //macro __LINE__ to display the line number in source code that called the //error handler. It also has an iteration input is useful when processing //results in a loop (getfirst/getnext). void ErrorHandler (LJ_ERROR lngErrorcode, long lngLineNumber, long lngIteration) { char err[255]; if (lngErrorcode != LJE_NOERROR) { ErrorToString(lngErrorcode,err); printf("Error number = %d\n",lngErrorcode); printf("Error string = %s\n",err); printf("Source line number = %d\n",lngLineNumber); printf("Iteration = %d\n\n",lngIteration); if(lngErrorcode > LJE_MIN_GROUP_ERROR) //Quit if this is a group error. return; } } void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { //taken from U3simple Examle code LJ_ERROR lngErrorcode; long lngGetNextIteration; double dblDriverVersion; long lngIOType=0, lngChannel=0; double dblValue=0; double Value2=9999,Value3=9999,Value4=9999; double ValueDIBit=9999,ValueDIPort=9999,ValueCounter=9999; LJ_HANDLE lngHandle=0; char ch; //My variables long DACID; double Voltage; //Get MATLAB Input Arguments (RHS) DACID=(long)mxGetScalar(prhs[0]); Voltage=(double)mxGetScalar(prhs[1]); //Open the first found LabJack U3. lngErrorcode = OpenLabJack (LJ_dtU3, LJ_ctUSB, "1", 1, &lngHandle); ErrorHandler(lngErrorcode, __LINE__, 0); //Start by using the pin_configuration_reset IOType so that all //pin assignments are in the factory default condition. lngErrorcode = ePut (lngHandle, LJ_ioPIN_CONFIGURATION_RESET, 0, 0, 0); ErrorHandler(lngErrorcode, __LINE__, 0); printf("Setting Voltage in channel %d = %f\n",DACID,Voltage); lngErrorcode = eDAC (lngHandle,DACID,Voltage,0,0,0); ErrorHandler(lngErrorcode, __LINE__, 0); }