Using Mex with Classes
이전 댓글 표시
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
채택된 답변
추가 답변 (2개)
Kaustubha Govind
2013년 1월 9일
0 개 추천
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
2013년 1월 10일
편집: Sridutt Nayak
2013년 1월 10일
0 개 추천
카테고리
도움말 센터 및 File Exchange에서 External Language Interfaces에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!