mex file and gpib link

3 views (last 30 days)
Vlad
Vlad on 11 Jun 2014
Answered: Dekun Pei on 16 Jun 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?

Answers (2)

James Tursa
James Tursa on 11 Jun 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 on 16 Jun 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.

Categories

Find more on External Language Interfaces in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!