MEX-file Interfacing
Jeffrey Irlanda
Ron Earl B. Tablatin


back to CE150




The main objective of computer interfacing is to allow the user to receive and/or send data out to the real world using the input/output ports. One of the most popular ways to interface is to use the parallel port. For our project, out goal is to control a remote controlled car using the computer via the parallel port. Voice commands will be issued by the user, interpreted by the computer, and then sent to the remote control of the car via the parallel port, which in turn sends the command to the car itself.

The programming language to be used in the project is crucial, since it must have both the capability for complex mathematics (for analyzing the voice) and the capability of controlling the ports (for data transmission). But the software need not be programmed using one language alone, since compatible programs can be made to communicate to each other, one will do the voice recognition and the other will control the parallel port. The first plan was to use Matlab for the voice recognition and Visual Basic for the control of the parallel port. But it proved to be very difficult for the two programs to communicate pass data to each other, so another approach must be done.

Matlab has a built-in utility called MEX. MEX is used to convert FORTRAN or C-code to MATLAB Executable ("MEX") format. MEX-files are dynamically linked subroutines that can be called from within MATLAB as regular MATLAB functions. With this, a simple C program that sends data through the parallel port was made, and then compiled using the MEX utility. A DLL was created, and this in turn is the one called from within Matlab. The choice of embedding assembly language in the C program instead of using the built-in function outport/outportb was because outport/outportb won't compile to MEX format. The reason is still unknown, but the most likely culprit is the compiler itself.

Listed below are the C++ source codes that were compiled to MEX-file format:


Punta0.cpp:

#include #include "mex.h"
void mexFunction ( int nlhs, mxArray *plhs[ ], int nrhs, const mxArray *prhs[ ] ){
asm { mov al,0x00
mov dx,0x378
out dx,al
}
}

Punta1.cpp:

#include
#include "mex.h"

void mexFunction ( int nlhs, mxArray *plhs[ ], int nrhs, const mxArray *prhs[ ] ){
asm { mov al,0x01
mov dx,0x378
out dx,al
}
}

Punta2.cpp:

#include
#include "mex.h"
void mexFunction ( int nlhs, mxArray *plhs[ ], int nrhs, const mxArray *prhs[ ] ){
asm { mov al,0x02
mov dx,0x378
out dx,al
}
}

Punta4.cpp:

#include
#include "mex.h"

void mexFunction ( int nlhs, mxArray *plhs[ ], int nrhs, const mxArray *prhs[ ] ){
asm { mov al,0x04
mov dx,0x378
out dx,al
}
}

Punta5.cpp:

#include
#include "mex.h"

void mexFunction ( int nlhs, mxArray *plhs[ ], int nrhs, const mxArray *prhs[ ] ){
asm { mov al,0x05
mov dx,0x378
out dx,al
}
}

Punta6.cpp:

#include #include "mex.h"

void mexFunction ( int nlhs, mxArray *plhs[ ], int nrhs, const mxArray *prhs[ ] ){
asm { mov al,0x06
mov dx,0x378
out dx,al
}
}

Punta8.cpp:

#include
#include "mex.h"

void mexFunction ( int nlhs, mxArray *plhs[ ], int nrhs, const mxArray *prhs[ ] ){
asm { mov al,0x08
mov dx,0x378
out dx,al
}
}

Punta9.cpp:

#include
#include "mex.h"

void mexFunction ( int nlhs, mxArray *plhs[ ], int nrhs, const mxArray *prhs[ ] ){
asm { mov al,0x09
mov dx,0x378
out dx,al
}
}

Punta10.cpp:

#include
#include "mex.h"

void mexFunction ( int nlhs, mxArray *plhs[ ], int nrhs, const mxArray *prhs[ ] ){
asm { mov al,0x0A
mov dx,0x378
out dx,al
}
}




back to CE150