mex file and gpib link

1 回表示 (過去 30 日間)
Vlad
Vlad 2014 年 6 月 11 日
回答済み: Dekun Pei 2014 年 6 月 16 日
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?

回答 (2 件)

James Tursa
James Tursa 2014 年 6 月 11 日
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 2014 年 6 月 16 日
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.

カテゴリ

Help Center および File ExchangeExternal Language Interfaces についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by