Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

ipc with matlab

217 views
Skip to first unread message

stroller

unread,
Sep 12, 2005, 8:20:55 PM9/12/05
to
hi,

i'd like to get some inter process communication (ipc) working
between a matlab session and another 3rd party cad vendor.

is this doable?

anyone got experience with this?

rgds.

lemon

unread,
Sep 13, 2005, 3:50:26 AM9/13/05
to
Hi

Exactly on ipc, i haven't done anything. What i have done was to
implement a Socket as a MEX file.
The interface with the outside was with options open, read, write,
close.
MatlabSocket( option, parameters).
You can do a lot of things with a MEX file; the only limitation is that
only the MEX process can take the initiative to contact the other
processes. Not meaning, naturally, that the communication must be
unilateral.

Hope this helps.

Lemon

Bjorn Gustavsson

unread,
Sep 13, 2005, 3:58:43 AM9/13/05
to
There is a TCP/IP toolbox in the matlab central file exchange, that
might do what you want, or be a good starting point.

HTH,
Bjorn

Kolumb?n S?ndor

unread,
Mar 20, 2009, 1:15:03 PM3/20/09
to
I am facing the same challege myself.

The simplest way to realize any IPC is to use files as communicational layer. The problem with this approach is its poor performance (file access is wery slow, and you have to use possing to see if there was any change). This is not an option for for performance reasons, but it might help you out as a last resort.

In Unix/Linux environment one could use shared memory files. This eliminates the performance loss caused by hard drive IO, but the polling remains. If you are a U/L user, you would know more about shared memory usage. As I am working under Windows, I am not able to help you more if you choose this direction.

If you encounter any other solutions for the problem, let me know, because I'am still searching :D

Bests,

Kolumb?n

stroller <smcb...@hotmail.com> wrote in message <ef13d...@webx.raydaftYaTP>...

Kolumb?n S?ndor

unread,
Mar 29, 2009, 8:45:03 AM3/29/09
to
I was able to manage IPC between Matlab and my application.

My task was the following:
- I had an algorithm running on my server
- There was a wabpage for tuning the parameters of the algorithm
- I had to make it possible for the users the change the parameters of the algorithm online. This means that while the matlab function was still running I had to be albe to chnage the values of some variables it was using.

My solution:
(this works on windows only, but the principle can be adaped to Unix/Linux as well except the usage of aspx)

- I created a simple application that played the role of the parameter server (from now on PS).
- The webpage was created using aspx technology. When a parameter was changed on the web, the aspx code notified the PS and changed the value of the parameter. The code of the webpage communicated with the PS through remoting.

Here is the actual IPC between Matlab and the PS:

- I created a simple C++ Mex function ([param] = GetParameter(name)) that aquires the value of the parameter with the given name.

- About creating mex funtions is VisualStudio: http://www.codeproject.com/KB/cpp/mexFunction.aspx?df=100&forumid=23357&exp=0&select=1067204&tid=943171

- This mexfenction did the actual IPC with my application. I used WCF and NamedPipes (on U/L, u can use named pipes as well). So, this mex function asked the PS for the value of the given parameter and then returned it.

An other approach would be, to create a dll (or lib) from a .m file (Matlab function) and call that function whenewer a parameters value is changed. By defining the values as global variables this should do the trick. This method would eliminate the polling behaviour of the previously described method. However, there is a problem with this approch. Since the Matlab does not support multithread programing, the function that would modify the value of the global variable, would be executed only after the main funtion executed (which would use the changed variable). This is why Matlab has to poll the values it wants to use.

Hope that helps somebody in the futuer...

Bests,

Kolumb?n

stroller <smcb...@hotmail.com> wrote in message <ef13d...@webx.raydaftYaTP>...

Sandip

unread,
Jul 7, 2009, 2:02:01 AM7/7/09
to
Hi Kolumb,
Can you write the step to use wcf proxy in MATLAB. Basically I am interested in using WCF COM Proxy in MATLAB.
Thanks and Regards
Sandip Kumar
-------------Reply Separator-----------------------
"Kolumb?n S?ndor" <almax...@gmail.com> wrote in message <gqnqgf$m60$1...@fred.mathworks.com>...

Kolumb?n S?ndor

unread,
Jul 7, 2009, 2:27:02 AM7/7/09
to
Hi Sandip!

I can help you a bit, but I'm realy swamped with job, I'll be breef.

In order to help you, please give me some answers on your knowlidge about the related topcis.

You say, that you want to access a WCF COM proxy from Matlab. I suppose you are using Visual Studio for building your WCF application. Two questions here: which programing language do you use? If not C++ (I suspect your answer will be C#), are you familiar with the usage of COM proxies in C++?

The topic is related to MEX functions. Have you ever used one? How much do you know about them?

If you give me these answers I will help you to move forward with this project.

Bests,

Kolumb?n

"Sandip " <sand...@yahoo.com> wrote in message <h2uocp$m6c$1...@fred.mathworks.com>...

Sandip

unread,
Jul 7, 2009, 5:33:02 AM7/7/09
to
Hi Kolumb,

I know mex programming a bit .

I am using both .NET based Proxy(as u guessed it right C#) and COM Proxy for my project. COM Proxy is something, I am using for the backward compatibility of my projects(It works good). Now I have to replace certain communication object in MATLAB project and I have decided that I will use COM Proxy for communication with respect to uniformity in backward compatibility of my project. But even if it is possible to use .NET wcf dll, directly, it will serve my purpose.

I think I can find way(on internet) to consume WCF service in C++.

So if we can use doing by mex programming(C++) let me know the steps involved.

Thanks and Regards
Sandip Kumar

------------------------------- Reply Separator-----------------------------------
"Kolumb?n S?ndor" <almax...@gmail.com> wrote in message <h2uprm$pjm$1...@fred.mathworks.com>...

Kolumb?n S?ndor

unread,
Jul 7, 2009, 6:58:01 AM7/7/09
to
If you are familiar with MEX programming, then you are done.

You can do anything inside a MEX function as long as it involves only C++ codes. Since the assembly of the MEX function will run in the appdomain of the Matlab, it will fall if any C# code is loaded.

Here is what I did:

- I had a complete project with communication lines, just like your proxies.
- First, I create a simple C++ application which was able to connect to the existing communication architecture. This means that I was able to receive the desired datastructures in C++ environment.
- Second, I created the MEX function that used the codes of the previously developed C++ project. Since the C++ <-> old project communication was ready, the only thing to do was to convert the C++ structures into mwArrays to pass it back to the Matlab.

The only downside of this solution is, that the communication must be initiated by Matlab.

The major (one day or so) effort was to write the C++ WCF code, it is much harder than its C# correspondent. After that it is just a regular MEX function. I've never used COM in C++, so I'm not able to help on that.

If you have any other questions, feel free to ask.

Best,

Kolumb?n

"Sandip " <sand...@yahoo.com> wrote in message <h2v4oe$ar2$1...@fred.mathworks.com>...

Sandip

unread,
Jul 7, 2009, 7:34:02 AM7/7/09
to
Hi Kolumb,

Thanks for your advice and reply!!! It is very helpful!!!

I can sum your proposals as:
1. Generate a C++ WCF Proxy, which is possible. Then create the MEX function with it. A good approach!!!
2. I write C++ moniker to communicate using WCF COM proxy. First test it on simple C++ environment and then create MEX out of the function.

Above solution will add one more tier to my communication line. I thought that .NET Proxy could be used directly. I will add this as another point:

3. Use .NET proxy DLL directly into the MATLAB environment if it is feasible.

Thanks once again for your quick advice and help on this topic Kolumb!!!

Thanks and Regards,
Sandip Kumar
--------------------------------Reply Separator----------------------------------------
"Kolumb?n S?ndor" <almax...@gmail.com> wrote in message <h2v9np$456$1...@fred.mathworks.com>...

Sandip

unread,
Jul 7, 2009, 7:40:04 AM7/7/09
to
Hi Kolumb,

Thanks for your advice and reply!!! It is very helpful!!!


I can sum your proposals as:
1. Generate a C++ WCF Proxy, which is possible. Then create the MEX function with it. A good approach!!!
2. I write C++ moniker to communicate using WCF COM proxy. First test it on simple C++ environment and then create MEX out of the function.


Above solution will add one more tier to my communication line. I thought that .NET Proxy could be used directly. I will add this as another point:


3. Use .NET proxy DLL directly into the MATLAB environment if it is feasible.


Thanks once again for your quick advice and help on this topic Kolumb!!!


Thanks and Regards,
Sandip Kumar

"Kolumb?n S?ndor" <almax...@gmail.com> wrote in message <h2v9np$456$1...@fred.mathworks.com>...

Kolumb?n S?ndor

unread,
Jul 7, 2009, 8:00:17 AM7/7/09
to
I'll have to disappoint you. Since I am writing the wast majority of my code in C# I wanted to write "C# MEX functions", it wasn't possible.

Then I tried to add a simple C++ project to my solution (the project of the MEX function) and simply access the C# variables of my program. When a C# object would get into the scope of a Matlab initiated code, then the call failed. At least for me.

If you succeed to solve the problem whitout the additional communication overhead, please post your results here, so the future generations can learn from it.

Best,

Kolumb?n

"Sandip " <sand...@yahoo.com> wrote in message <h2vc6k$fs5$1...@fred.mathworks.com>...

Sandip

unread,
Jul 7, 2009, 8:39:02 AM7/7/09
to
Hi Kolumb,

I will update here if I am successful.

Thanks and Regards,
Sandip Kumar

-------------------------------------------Reply Separator----------------------------------
"Kolumb?n S?ndor" <almax...@gmail.com> wrote in message <h2vdch$3hd$1...@fred.mathworks.com>...

0 new messages