mex file: monitoring (continuously) variables defined in matlab functions

3 ビュー (過去 30 日間)
Enrico  Boscolo
Enrico Boscolo 2015 年 6 月 17 日
回答済み: Andrew Schenk 2015 年 6 月 18 日
I have a TCP_IP camera and a GUI with some calc. functions written in matlab. Using mex file from c++ (provided by camera’s vendor), I’m able to open/close camera library and connection. The cpp allows changing some camera parameters like exposure. I’ d like to know if it is possible to monitor real time some variables (defined and changed in matlab) using mex file and when one of these changes the mex file does some operations on camera (ex. changing the exposure). One solution is to call the mex file every time a parameter in matlab is changed: but this method is quite inefficient. I guessed to write a sort of “thread” with a while loop inside the mex where the parameters/variables from matlab are transferred and could be monitored…but this method seems impracticable: I don’t know how to transfer variables from matlab continuously without calling the mex file every time. Any suggestion? Many thanks
Enrico
  1 件のコメント
James Tursa
James Tursa 2015 年 6 月 17 日
"... but this method is quite inefficient ..."
Inefficient in what way? Are you having some type of speed or throughput issue with your current code, or what?

サインインしてコメントする。

回答 (1 件)

Andrew Schenk
Andrew Schenk 2015 年 6 月 18 日
The best way of updating MATLAB variable values to an external library is to call the MEX function. It is not possible for the MEX file to "watch" a MATLAB variable. every time the parameter changes in MATLAB. That being said, here are some suggestions to improve the performance of your application:
If you are updating many parameters, you could pass them as a vector into the MEX function instead of calling the MEX function individually for each parameter.
From the description it sounds as if you have a single MEX function that opens the TCP connection, submits parameter changes, and then closes the connection. The overhead of opening and closing the connection is likely much larger than the parameter update. In this case it would be best to create three separate MEX functions to:
  • Open the connection and return a handle
  • Take the handle and parameter and submit the parameter update using the vendor's API
  • Close the connection
This would be similar to the fopen, fwrite, fclose functions used in MATLAB for file I/O.
Finally, instead of having a callback in the GUI for when parameters change and automatically calling the MEX function, you could add an "Apply" button in the GUI that would call the MEX function with the parameter values only when clicked.

カテゴリ

Help Center および File ExchangeMATLAB Compiler についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by