Passing WORD data type from C file to mex function:
Mostrar comentarios más antiguos
Hello, I have a quick question regarding converting between data types in a mex file. I am interfacing to some hardware which calls a WORD pointer in its measuring function, but I'm having trouble passing this quantity back to Matlab as the output appears as a bunch of zeros. Below is a truncated version of the code to highlight the problem I'm having, I've removed the overhead because the code compiles and I'm fairly certain my problems are coming from the mexfunction part:
#include <windows.h>
#include "DCamUSB.h"
#include "DCamStatusCode.h"
#include "mex.h"
extern void _main();
int mainsubr(long *RetVal, double *data)
{
WORD* pDataBuff = NULL;
pDataBuff = new WORD[ nImageSize * nFrameCount];
// Acquisition execute, camera acquires data
*data = pDataBuff;
for( nCountH = 0; nCountH < nHeight; nCountH++ )
{
for( nCountW = 0; nCountW < nWidth; nCountW++ )
{
printf("%d\n", *data);
data ++;*
}
}
break;
}
// Process for exit.
DcamStop(); // Stop acquisition
delete [] pDataBuff; // Release acquisition buffer
// status
return 0;
}
// ---------------------------- MEX PART --------------------------------
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
WORD *Buffer; // measured spectra
long mrows2 = 2068, mcols2 = 1;
plhs[0] = mxCreateDoubleMatrix(mrows2, mcols2, mxREAL);
Buffer = (WORD *)mxGetData(plhs[1]);
// call main subroutine
mainsubr(Status, Buffer);
return;
}
end
The issue I suppose is the way I am calling mxGetData, but I'm not certain why it is only returning zeros. The little printf command I have in the for loop in the main subroutine is displaying the values I want in the Matlab shell, but someone I am not able to then pass these values to the array in Matlab. Any tips? I'm assuming this has something to do with recasting the WORD * into a double * somehow but it seems (according to my compiler) that this is not possible, and therefore the conversion has to take place in the mex function I suppose. Thanks for any tips you can provide.
Alexei
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre MATLAB Compiler SDK en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!