Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Real time communication between two matlabs running on Windows and Mac

Subject: Real time communication between two matlabs running on Windows and Mac

From: Patrick Mineault

Date: 9 Sep, 2010 04:01:46

Message: 1 of 8

We have a Mac which is used for presenting visual stimuli through
Matlab, and another machine running Windows that records physiological
signals (spikes from neurons) and stores them. The system is set up
such that the Mac can send TTL pulses to the PC so that we can sync up
the visual presentation and the spikes, and analyze the experiment
offline.

The problem I have now is that I want to adjust the stimulus online
based on the number of spikes I record, so that I can tailor the
stimulus to drive the neurons best. So basically I need the Mac to be
able to tell the PC to:

1. start recording spike times
2. stop recording spike times and send them back to the Mac

The company which sells the electrophysiological rig has libraries to
read the spike data online from a user-written program running on a
Windows machine, either on the PC that does the recording or some
other machine connected through ethernet with the machine that records
the spikes. In particular, they have a Matlab library which can read
the data I require, and it's pretty easy to work with.

So the problem boils down to having the Mac Matlab controlling the
Windows Matlab remotely. What is the least painful way to do this?
There's a few ways I thought of doing this, including:

- Creating a Java server running inside Matlab on the PC that listens
in to signals on a port
- ssh or telnet into the Windows machine from the Mac and send
commands to open up a console matlab session and run a specified file
with the -R flag
- Writing python scripts running on the Windows machine to access the
Matlab Engine, and call those scripts remotely through a web server

All these ideas are really hacky, I'd prefer something more
straightforward. Suggestions?

Subject: Real time communication between two matlabs running on Windows and Mac

From: John

Date: 9 Sep, 2010 20:01:10

Message: 2 of 8

Patrick Mineault <patrick.mineault@gmail.com> wrote in message <b95255ea-7cd6-47b2-b3a1-263dcd838e7c@y3g2000vbm.googlegroups.com>...
> We have a Mac which is used for presenting visual stimuli through
> Matlab, and another machine running Windows that records physiological
> signals (spikes from neurons) and stores them. The system is set up
> such that the Mac can send TTL pulses to the PC so that we can sync up
> the visual presentation and the spikes, and analyze the experiment
> offline.
>
> The problem I have now is that I want to adjust the stimulus online
> based on the number of spikes I record, so that I can tailor the
> stimulus to drive the neurons best. So basically I need the Mac to be
> able to tell the PC to:
>
> 1. start recording spike times
> 2. stop recording spike times and send them back to the Mac
>
> The company which sells the electrophysiological rig has libraries to
> read the spike data online from a user-written program running on a
> Windows machine, either on the PC that does the recording or some
> other machine connected through ethernet with the machine that records
> the spikes. In particular, they have a Matlab library which can read
> the data I require, and it's pretty easy to work with.
>
> So the problem boils down to having the Mac Matlab controlling the
> Windows Matlab remotely. What is the least painful way to do this?
> There's a few ways I thought of doing this, including:
>
> - Creating a Java server running inside Matlab on the PC that listens
> in to signals on a port
> - ssh or telnet into the Windows machine from the Mac and send
> commands to open up a console matlab session and run a specified file
> with the -R flag
> - Writing python scripts running on the Windows machine to access the
> Matlab Engine, and call those scripts remotely through a web server
>
> All these ideas are really hacky, I'd prefer something more
> straightforward. Suggestions?

I am currently trying to do something similar to get matlab one computer to open up an instance on another and tell it to do something. If that is at all similar to what you are trying to do then I suggest you look at the function actxserver. To run it you will need this folowing line:

h = actxserver('matlab.desktop.application', 'machine', machine2) where machine2 is the name of the windows machine.

In all of my work I have been using a windows-to-windows connection so Im not sure if this is going to work. I have also had access denied errors which were not resolved until I gained admin access on both computers.

This method uses DCOM which is talked about somewhat in the MathWorks help, I would suggest looking into it.

Subject: Real time communication between two matlabs running on Windows

From: Patrick Mineault

Date: 10 Sep, 2010 17:39:38

Message: 3 of 8

Unfortunately ActiveX is a Microsoft technology which means it can't
be used on the Mac computer.

On Sep 9, 4:01 pm, "John " <jrazz...@usc.edu> wrote:
> Patrick Mineault <patrick.minea...@gmail.com> wrote in message <b95255ea-7cd6-47b2-b3a1-263dcd838...@y3g2000vbm.googlegroups.com>...
> > We have a Mac which is used for presenting visual stimuli through
> > Matlab, and another machine running Windows that records physiological
> > signals (spikes from neurons) and stores them. The system is set up
> > such that the Mac can send TTL pulses to the PC so that we can sync up
> > the visual presentation and the spikes, and analyze the experiment
> > offline.
>
> > The problem I have now is that I want to adjust the stimulus online
> > based on the number of spikes I record, so that I can tailor the
> > stimulus to drive the neurons best. So basically I need the Mac to be
> > able to tell the PC to:
>
> > 1. start recording spike times
> > 2. stop recording spike times and send them back to the Mac
>
> > The company which sells the electrophysiological rig has libraries to
> > read the spike data online from a user-written program running on a
> > Windows machine, either on the PC that does the recording or some
> > other machine connected through ethernet with the machine that records
> > the spikes. In particular, they have a Matlab library which can read
> > the data I require, and it's pretty easy to work with.
>
> > So the problem boils down to having the Mac Matlab controlling the
> > Windows Matlab remotely. What is the least painful way to do this?
> > There's a few ways I thought of doing this, including:
>
> > - Creating a Java server running inside Matlab on the PC that listens
> > in to signals on a port
> > - ssh or telnet into the Windows machine from the Mac and send
> > commands to open up a console matlab session and run a specified file
> > with the -R flag
> > - Writing python scripts running on the Windows machine to access the
> > Matlab Engine, and call those scripts remotely through a web server
>
> > All these ideas are really hacky, I'd prefer something more
> > straightforward. Suggestions?
>
> I am currently trying to do something similar to get matlab one computer to open up an instance on another and tell it to do something. If that is at all similar to what you are trying to do then I suggest you look at the function actxserver. To run it you will need this folowing line:
>
> h = actxserver('matlab.desktop.application', 'machine', machine2) where machine2 is the name of the windows machine.
>
> In all of my work I have been using a windows-to-windows connection so Im not sure if this is going to work. I have also had access denied errors which were not resolved until I gained admin access on both computers.
>
> This method uses DCOM which is talked about somewhat in the MathWorks help, I would suggest looking into it.

Subject: Real time communication between two matlabs running on Windows

From: Thomas Clark

Date: 10 Sep, 2010 18:18:05

Message: 4 of 8

Patrick,

I'm not a huge specialist on this - but an alternative option occurred to me...

Can you have the computers communicate via a serial port (universal protocol) and send a particular word down the port for start, stop, etc? Have a serial port object open in MATLAB (windows) listening for a particular word then executing some code when it receives it?

Hope this helps!

Tom

Subject: Real time communication between two matlabs running on Windows

From: Patrick Mineault

Date: 10 Sep, 2010 19:13:04

Message: 5 of 8

Unfortunately the Mac doesn't have a serial port and it seems from a
quick Google search it is not straightforward to get a USB to serial
port adapter going.

On Sep 10, 2:18 pm, "Thomas Clark" <t.cl...@remove.spamcantab.net>
wrote:
> Patrick,
>
> I'm not a huge specialist on this - but an alternative option occurred to me...
>
> Can you have the computers communicate via a serial port (universal protocol) and send a particular word down the port for start, stop, etc? Have a serial port object open in MATLAB (windows) listening for a particular word then executing some code when it receives it?
>
> Hope this helps!
>
> Tom

Subject: Real time communication between two matlabs running on Windows

From: Walter Roberson

Date: 10 Sep, 2010 19:41:57

Message: 6 of 8

On 10-09-10 02:13 PM, Patrick Mineault wrote:
> Unfortunately the Mac doesn't have a serial port and it seems from a
> quick Google search it is not straightforward to get a USB to serial
> port adapter going.

Reading back to your original post, it seems unlikely that for your purposes
that it is time critical as to exactly when you stop recording the spikes, and
I _suspect_ that it is not especially critical as to exactly when you start
recording the spikes.

USB to serial ports adapters cannot trivially be used for anything that
requires timing to less than about 40 ms, but if 1/25th of a second is good
enough for you, then it should be very straight-forward code.

Subject: Real time communication between two matlabs running on Windows

From: Yair Altman

Date: 11 Sep, 2010 18:21:04

Message: 7 of 8

You can try to use Java to connect your computers. The good thing about Java is that it works across different platform technologies, so Windows can communicate with Macs and vice versa. There are many possible variants. Here are several implementation resources for Matlab - one of these will surely be right for you:

http://www.mathworks.com/matlabcentral/fileexchange/23728-tcpip-distributed-waitbar
http://www.mathworks.com/matlabcentral/fileexchange/24524-tcpip-communications-in-matlab
http://www.mathworks.com/matlabcentral/fileexchange/24525-a-simple-udp-communications
http://www.mathworks.com/matlabcentral/fileexchange/27999-ssh-from-matlab-updated

http://iheartmatlab.blogspot.com/2008/08/tcpip-socket-communications-in-matlab.html

A high-level Java-based communications package called jPar was published here: http://www.mathworks.com/matlabcentral/fileexchange/24924-jpar-parallelizing-matlab and described in this paper: http://www.ia.pw.edu.pl/~karbowsk/jpar/jpar-para08-abstract.pdf

Also see MEX-based http://www.mathworks.com/matlabcentral/fileexchange/345-tcpudpip-toolbox-2-0-6

Yair Altman
http://UndocumentedMatlab.com

Subject: Real time communication between two matlabs running on Windows

From: Patrick Mineault

Date: 11 Sep, 2010 22:52:03

Message: 8 of 8

Interesting. The DAQ demo in the TCP/UDP/IP toolbox (http://
www.mathworks.com/matlabcentral/fileexchange/345-tcpudpip-toolbox-2-0-6)
seems to be almost exactly what I need. Mex sounds like a better
solution for me than Java because the stimulation computer (the Mac)
has to have a lot of instances of Matlab going so we're using -nojvm.

One question though. Should I use TCP or UDP for this application? I
don't really need the spikes in realtime. It seems that with TCP on
the server side I would simply wait for an incoming connection and
then start sending spikes over the connection (uint8 unit number,
double timestamp => 9 bytes). I guess I should do a handshake
beforehand so I can sync the two signals, right? Am I wrong in
thinking that when I receive the data it won't necessarily be 9 bytes
at a time, and that the data may even be cut in the middle of a 9 byte
message, so I need to take that into account? To stop receiving the
spikes, can I simply disconnect on the client side and then the server
has access to the information that the client is disconnected?

With UDP am I mistaken in thinking that on the server side I can't
know if a client is connected (unless I make the client and server
handshake explicitly)? Let's say I simply continuously forward spikes
on the server side to a port whether anyone is listening or not. Is
this possible? Is this a problem? Will the client receive all the
previous spikes that were sent on this port, or do the packets that
weren't listened to go into a black hole?

Thanks,

Patrick

On Sep 11, 2:21 pm, "Yair Altman" <altmany...@gmailDEL.comDEL> wrote:
> You can try to use Java to connect your computers. The good thing about Java is that it works across different platform technologies, so Windows can communicate with Macs and vice versa. There are many possible variants. Here are several implementation resources for Matlab - one of these will surely be right for you:
>
> http://www.mathworks.com/matlabcentral/fileexchange/23728-tcpip-distr...http://www.mathworks.com/matlabcentral/fileexchange/24524-tcpip-commu...http://www.mathworks.com/matlabcentral/fileexchange/24525-a-simple-ud...http://www.mathworks.com/matlabcentral/fileexchange/27999-ssh-from-ma...
>
> http://iheartmatlab.blogspot.com/2008/08/tcpip-socket-communications-...
>
> A high-level Java-based communications package called jPar was published here:http://www.mathworks.com/matlabcentral/fileexchange/24924-jpar-parall...and described in this paper:http://www.ia.pw.edu.pl/~karbowsk/jpar/jpar-para08-abstract.pdf
>
> Also see MEX-basedhttp://www.mathworks.com/matlabcentral/fileexchange/345-tcpudpip-tool...
>
> Yair Altmanhttp://UndocumentedMatlab.com

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us