Comunicating Programs

Started by
8 comments, last by Kris2456 17 years, 11 months ago
Hi. Im making a small program for my dad which involves 2 little cars, now one of the cars should move, depending on what a variable from matlab says the distance is. My problem is, how do i get that variable in matlab, to be passed on to my C++ program. I have thought of using a file, however this would really need to be dynamic, so that as soon as the variable is changed, it will affect the distance of the car at the same time. Does anyone know what i should do for this?
------------ "Here lies a toppled God,His fall was not a small one,We but built his pedastle,A narrow, and a tall one" Frank Herbert (Dune:Messiah)
Advertisement
With Windows, you can set up a file change notification so that your application receives a special message when the file - that you register for monitoring - changes.

See FindFirstChangeNotification and it's "sister" functions on MSDN.

Niko Suni

Is there a way, to make one program "send" the information in the variable to the other. The FindFirstChangeNotification method seems to use files, which is not what i want (unless i read the description wrong)
------------ "Here lies a toppled God,His fall was not a small one,We but built his pedastle,A narrow, and a tall one" Frank Herbert (Dune:Messiah)
If you go to the Mathworks site for matlab you will find the information you need.

Look at this.. http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_external/

Look for the COM and DDE capabilites. This will allow your program to directly communicate with Matlab and Matlab to communicate with your program. This should do all that you need.

theTroll
Quote:Original post by Kris2456
Is there a way, to make one program "send" the information in the variable to the other. The FindFirstChangeNotification method seems to use files, which is not what i want (unless i read the description wrong)


You specifically said that you thought about using a file for this purpose, so I gave you advice on how to do that.

However, if Matlab indeed supports using COM interfaces, it would probably be easier to go for that route instead of custom files.

Niko Suni

I had a trawl through their website, however i could not find specifically how to integrate my two programs. Do any of you know maybe a simpler tutorial (something where i can learn about COM's) that i could use. Thanks in advance.
------------ "Here lies a toppled God,His fall was not a small one,We but built his pedastle,A narrow, and a tall one" Frank Herbert (Dune:Messiah)
COM is a pretty big subject. Just do a search on google for COM, basics and what langauge you are using. It is going to take you a little bit of time to get the COM basics down so you can integrate your program.

theTroll
I'd recomend leaving COM alone and just using a plain C dll, which matlab can also call (as described on the page linked above).
Is the variable or information you're talking about, somehow displayed in matlab (whatever that is), such as in a label of some sort? If so, get WinSpector , and run it while matlab is running, figure out which control is the one with the information (Make it show an example value such as 1337 which you could then identify within winspector), after doing so, write down the specifications (Handles, etc.) and the you can use the FindWindow calls (I believe you'll also need FindWindowEx to find the control within the window?) to retrieve the handle to the control, you can then do a SendMessage or GetWindowText (Or what was it called? I think that's what it was called) on it to retrieve the value. Polling could be a bit inefficient, but this is probably the most dirtiest way you can do what you want, you can for example poll ever second to second and a half probably, see if the value has changed and act accordingly. (Possibly 'hooking' might be of some use here? Thugh I don't know exactly how it'd be implimented)

EDIT: I don't know much about what the program you're talking about is, but I just skimmed over the docs and it seems like you can build your own subroutine into it, which you could then possibly use to inform your own program of the value changes?

Just my two cents.
How would i go about using a DLL to transfer data between them. I thought DLL's could only hold static functions and variables.
------------ "Here lies a toppled God,His fall was not a small one,We but built his pedastle,A narrow, and a tall one" Frank Herbert (Dune:Messiah)

This topic is closed to new replies.

Advertisement