Forums

How to call C program from Matlab?

Started by Tan Thiam Huat April 11, 2002
Hi All,

I have a simple C program (io.c) for I/O functions. How do I call the C program
from Matlab. I understand there is a mex function to do that. But there is still
a lot of technical details which I am quite confused, example the mxArray, etc.
could anyone help?

The purpose of io.c program is merely to control the pins of the I/O card of
8255. I could compile that with Labwindows/CVI. But I need to interface with
Matlab, because I need to interface other programs in Matlab.

outp( 0x143,0x80); /* Control Register */
outp( 0x140,0xff); /* Port A: Pin 1 to Pin 8 */
outp( 0x141,0xff); /* Port B: Pin 9 to Pin 16 */
outp( 0x142,0xff); /* Port C: Pin 17 to Pin 24 */

/* 0x143, 0x80, etc are all in HEX. */

do we need a Visual C++ program to integrate with Matlab? That means I need to
convert my io.c to rename as io.cpp? then I type
>> mex io.cpp
from Matlab prompt?

Thanks so much. Would appreciate if someone could help me by today.

Best regards,
Thiam Huat



/************************************************************************/
/* */
/* This example shows how you can use the ANSI C stdio functions in */
/* LabWindows/CVI to display and retrieve text information from the */
/* Standard I/O window. Notice how the Standard I/O window can be */
/* scrolled once you have generated the data. */
/* */
/************************************************************************/

#include <utility.h int main ()
{

/* Channel 1, U6 */
outp( 0x143,0x80); /* Control Register */
outp( 0x140,0xff); /* Port A: Pin 1 to Pin 8 */
outp( 0x141,0xff); /* Port B: Pin 9 to Pin 16 */
outp( 0x142,0xff); /* Port C: Pin 17 to Pin 24 */

}



Hello :),

I did some mex programming and some digital image
processing implementation for my final year project.
Attached is the report I have compiled from my final
year thesis and hope this will help you to understand
mex-programming better.

Best regard,
Matthew Tan

--- Tan Thiam Huat <> wrote:
> Hi All,
>
> I have a simple C program (io.c) for I/O functions.
> How do I call the C program from Matlab. I
> understand there is a mex function to do that. But
> there is still a lot of technical details which I am
> quite confused, example the mxArray, etc. could
> anyone help?
>
> The purpose of io.c program is merely to control the
> pins of the I/O card of 8255. I could compile that
> with Labwindows/CVI. But I need to interface with
> Matlab, because I need to interface other programs
> in Matlab.
>
> outp( 0x143,0x80); /* Control Register */
> outp( 0x140,0xff); /* Port A: Pin 1 to Pin 8
> */
> outp( 0x141,0xff); /* Port B: Pin 9 to Pin 16
> */
> outp( 0x142,0xff); /* Port C: Pin 17 to Pin 24
> */
>
> /* 0x143, 0x80, etc are all in HEX. */
>
> do we need a Visual C++ program to integrate with
> Matlab? That means I need to convert my io.c to
> rename as io.cpp? then I type
> >> mex io.cpp
> from Matlab prompt?
>
> Thanks so much. Would appreciate if someone could
> help me by today.
>
> Best regards,
> Thiam Huat


Attachment (not stored)
MexReport.pdf
Type: application/pdf