Monday, June 30, 2008

Wrapping up MATLAB/LabView Problem

So here is some final thoughts on the problem of compiling MATLAB code into C shared libraries to use with LabView; before I forget about it all now that I decided to stop worrying about it:

- The first problem is that Matlab uses a custom data type called MxArray, and one needs to create a wrapper function that takes in standard data types (doubles, integers, etc.) and calls the appropriate Matlab compiled functions with the arguments passed as MxArrays.

- After creating the wrapper, you can re-compile it all to end up with a .dll and a .h file.

- These files can be used with the function library node sub-vi in LabView, and the appropriate functions should show up. However...

- The first function to call is one that loads the global MCR (Matlab Complie Runtime or something similar), which should only be stopped after one finishes using any Matlab libraries.

- Then one can call the set of initialization functions for each matlab function complied into the shared librarry. After initializing, one can call the excecuting function, and lastly the terminate function. The initalization/termination funciton basically create a new local MCR instance for each one.

- The last step is to call the global termination, to stop the global MCR.

- This all sounds fine, until you start implementing it. It is just a PITA to get it working.

Tuesday, June 10, 2008

PHP server setup status

I've been trying to get the server running with the energy data visualization code I've been working on. it has not yet been a success, but here's my progress so far:

I could not get the installed version of php working with apache, though i added the necessary directives. There was no module binary for php in the apache/modules directory, but I found one elsewhere (in the php installation dir). However, that module threw some error about "garbled module" when I tried to restart the apache httpd server (using apachectl).

Next plan: install a fresh version of php which will be able to compile the module from source. Downloaded php 5, but it didn't like apache's apxs library. Then I downloaded php 4, removed the currently installed version of php 4 (using RPM) and tried to build the module. It complained that if I didn't specify a path to the mysql directory, other apache modules might not be able to access the mysql database. This might be a problem, but it's one for another day. I compiled the module, and was able to restart apache and get a php file to load properly - yeah!

However, the database code did not work; it just threw an error about not being able to connect to localhost as daemon@localhost with no password. When I explicitly included the link_identifier in the mysql_select_db function, I instead got this error:
"Client does not support authentication protocol requested by server; consider upgrading MySQL client"

I suspect that the final solution may include removing the RPM versions of apache and mysql and compiling everything from scratch. Or move the project off of cee-landscaper and onto sensor2.andrew and see if the default installation is wprking any better over there...

Wednesday, June 4, 2008

Compiling Matlab code into Shared Libraries

It's been a long time since our last post. Many things have happened since, and even though we intended to use this blog as a progress report log, I am starting to realize that it will be more similar to a "Lessons Learned" kind of log, at least during the early stages.

Today I spent a few hours trying to get some .m files working in LabView by compiling them into .dll shared libraries, and importing them using the new Shared Library Import Wizard that came out on v8.2 of LabView. Read lots of forum threads, and spent some time staring at the command line prompt.

So far, I've managed to compile the code by using the following:

mcc -a neededmatfiles.mat -W lib:libraryName -T link:lib filestocomiple.m

This results in a .dll and some other necessary files.

It turns out, however, that the choice of compiler (which can be configured using "mbuild -setup" is an important one. The Lcc-win32 compiler that comes with Matlab doesn't seem to be doing the work, and I've read on some forums that the Visual Studio 7.0 compiler is our best bet. So now I'm looking for a computer with it, since the "free" student version (DreamSpark) is not so easy to get.

Update (06/06/08): I might have found the solution here:
http://forums.ni.com/attachments/ni/170/7347/1/dllmatlablabview.pdf