I am trying to do a simple program to access a XEM3001 board from Matlab. I followed the C++ tutorial and now I can upload a bitfile and communicate with the board using C++ code.
Now I want to do the same from Matlab using the mex compiler. I am using Visual Studio 10, Matlab R2010a, and the XEM3001_v2. I updated the mex compiler options to be able to call the VS10 compiler. I am compiling x64 code and it works well as a stand alone application (from the DOS command window).
My mex compiler works and compiles the files I want, but this is my problem: I can only access the board the first time and then the board is not released so the second time I run my compiled mex module it cannot find the board.
Now I have two programs and one of them loads the DLL and can access the FPGA board the first time. The second time there is some problem because the DLL is already loaded and Matlab crashes.
So I have another program that does not open the DLL and it compiles ok and the okCUSBcontrolpanel object is created. Is just that the code cannot find the board.
The second time I get a 0 from getDeviceCount() and -15 as the error from OpenBySerial().
Do you have any hint on how to release the board? I tried deleting the xem pointer from the C++ code and it crashes matlab. Also I found an UnregisterAll() method in the documentation but it seems to be discontinued in the last version.
In my Console Application the board is released after the program ends and I can rerun it many times, but it seems that in Matlab the DLL is holding it even after the mex command ends.
PS. I also tried to use okFrontPanelDLL_FreeLib(), but the second time you try to run the code it crashes like the DLL was not really unloaded.