Using Mex with Classes
Mostrar comentarios más antiguos
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
Respuesta aceptada
Más respuestas (2)
Kaustubha Govind
el 9 de En. de 2013
0 votos
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
el 10 de En. de 2013
Editada: Sridutt Nayak
el 10 de En. de 2013
0 votos
Categorías
Más información sobre External Language Interfaces en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!