mex file and gpib link

1 visualización (últimos 30 días)
Vlad
Vlad el 11 de Jun. de 2014
Respondida: Dekun Pei el 16 de Jun. de 2014
Hello everyone.
I have the following question. I adjust some device via gpib-connection. In main m-file I write:
glink=gpib('ni', 0 , 1);
Can I call my mex-file with glink parameter: myMex(glink)? I mean, there is a string somewhere in mex-file:
fopen(glink);
fprintf(glink, '*IDN?');
fscanf(glink);
fclose(glink);
And how can I check glink is an object? Does the 'mxIsObject' exist?

Respuestas (2)

James Tursa
James Tursa el 11 de Jun. de 2014
To examine what the class name is for a variable in a mex routine you can use mxGetClassName:
E.g.,
char *classname;
classname = mxGetClassName(prhs[0]);
Then you can test classname against any particular string (e.g., "glink") to see if it is an object of that class.

Dekun Pei
Dekun Pei el 16 de Jun. de 2014
In addition to what James said, I would be careful with using "fopen", "fprintf", "fscanf" and "fclose" in your mex file. These functions in MATLAB are overloaded to support instrument objects. However, this is NOT the case in mex file as the C/C++ version of these function will be used and they are most definitely not set up to handle MATLAB objects.
If you must use them on glink in a C/C++ mex file, call them through "mexCallMATLAB" (<http://www.mathworks.com/help/matlab/apiref/mexcallmatlab.html)>, which essentially calls these function in MATLAB.

Categorías

Más información sobre External Language Interfaces en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by