07-31-2013 04:56 PM
Well, after some searching through the NI forums, and reading through the link that you posted, I note that several other people have observed the same problem, and it's even noted in the readme file with the sample DLL: "This is a problem with Matlab dll’s, as you cannot initialize again once you have terminated. This results in being able to run the dll only once."
Unfortunately I don't see any posts from someone who has solved it, and I don't think the initialize and terminate functions actually help here. If you never call terminate, can you run it more than once? What if you don't call terminate, and you ignore any error that occurs at initialize?
The name mangling in the DLL suggests the person who put together that example did not completely understand what they were doing. The functions should have all been configured as C exports, so the function names would be correct.
One post noted that if you use fixed-size arrays instead of matrices, you can avoid using a wrapper DLL; I'm not sure if you're doing this.
08-01-2013 09:10 AM
I found the same source you did. That's why the author suggested dividing the procedure into three functions. So you initialize the Matlab DLL first, and now you are free to call the DLL until the Terminate function is called. If all these is happening in LabVIEW, it is a big problem because LabVIEW has to be completely shut down. So I have to initialize as the first step in the code, and don't call Terminate() until the code is about to shut down.
I tried it, and it worked as above said. It might not be convenient, but I guess I will have to deal with it every time Matlab is involved.
Thanks for your help. I am glad it all worked out.