Using Mex with Classes
Show older comments
I have written a mex file to 1. Initialize hardware. 2. Get Data. 3. Close & Exit hardware.
----Some_App.cpp----
void mexFunction(parms)
{
handle = init_hw();
alloc_mem(handle);
get_data();
copy_to_mxDoubleMatrix();
exit_hw(handle);
}
This works fine.
I have to change it such a way that init_hw(); is in a different class. Using this handle, I need to be able to allocate_mem(handle), get_data()... say a 100 times, then exit_hw(handle); as the init_hw() takes long to run I don't want to init_hw() everytime.
Can I do something to separate them into classes and use like
handle = Some_App.init_hw();
for i = 1:100
array = Some_App.acquire(handle); /*All Memalloc, read go into this class*/
end
Some_App.exit_hw(handle);
Any Tutorials/Help/Links can be useful. Thanks
Accepted Answer
More Answers (2)
Kaustubha Govind
on 9 Jan 2013
0 votes
There might be other solutions to this, but if you'd like to maintain the handle inside the MEX-function, you could try declaring it as a persistent array which is initialized when the MEX-file is loaded and deleted when the MEX-file is unloaded.
Another approach (that I haven't tested out), if you are able to store the handle in MATLAB code, might be to create a MATLAB class that stores the handle and has methods called init_hw, acquire, exit_hw, etc. Each of these methods might be wrappers to different MEX-functions that perform the actual operation.
Sridutt Nayak
on 10 Jan 2013
Edited: Sridutt Nayak
on 10 Jan 2013
0 votes
Categories
Find more on External Language Interfaces in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!