I am trying to send/receive data between two computers running Matlab
with the tcpip object.
From what I can tell, there is no way to have Matlab "LISTEN" for the
other computer to open a TCP connection.
Can someone verify this?
I find it strange we have the ability to open TCP connections, but do
not have the ability to allow another application to open a TCP
connection with Matlab.
Has anyone been able to get Matlab to listen for tcpip connections?
Before I make this project more complicated, I want to make sure I am
not missing an easier route.
Thanks,
Steve
Subject: TCP communication of 2 computers running Matlab
"steven.bak" <steven.bak@gmail.com> wrote in message
news:7ada5081-a6ba-4243-91ae-bf7596897068@z66g2000hsc.googlegroups.com...
>I am trying to send/receive data between two computers running Matlab
> with the tcpip object.
> From what I can tell, there is no way to have Matlab "LISTEN" for the
> other computer to open a TCP connection.
>
> Can someone verify this?
> I find it strange we have the ability to open TCP connections, but do
> not have the ability to allow another application to open a TCP
> connection with Matlab.
>
> Has anyone been able to get Matlab to listen for tcpip connections?
> Before I make this project more complicated, I want to make sure I am
> not missing an easier route.
Hi Steve,
The TCPIP client implementation was initially for communicating with
instruments that handled the server side. We are listening to feedback from
customers regarding server sockets. For now, it is possible to use the UDP
connections while binding to LocalPorts.
On Jun 13, 5:52 pm, "Trent Jarvi" <tja...@mathworks.com> wrote:
> "steven.bak" <steven....@gmail.com> wrote in message
>
> news:7ada5081-a6ba-4243-91ae-bf7596897068@z66g2000hsc.googlegroups.com...
>
> >I am trying to send/receive data between two computers running Matlab
> > with the tcpip object.
> > From what I can tell, there is no way to have Matlab "LISTEN" for the
> > other computer to open aTCPconnection.
>
> > Can someone verify this?
> > I find it strange we have the ability to openTCPconnections, but do
> > not have the ability to allow another application to open aTCP
> > connection with Matlab.
>
> > Has anyone been able to get Matlab to listen for tcpip connections?
> > Before I make this project more complicated, I want to make sure I am
> > not missing an easier route.
>
> Hi Steve,
>
> The TCPIP client implementation was initially for communicating with
> instruments that handled the server side. We are listening to feedback from
> customers regarding server sockets. For now, it is possible to use the UDP
> connections while binding to LocalPorts.
>
> >> u=udp('localhost', 'LocalPort', 15000, 'RemotePort', 15001);
> >> u2=udp('127.0.0.1','LocalPort', 15001, 'RemotePort', 15000);
> >> fopen(u);
> >> fopen(u2);
> >> fprintf(u, 'echo this string\n');
> >> fscanf(u2)
>
> ans =
>
> echo this string
Trent,
Thank you for your response. It has been helpful. I am seeing some
weird behavior while using fread on a UDP object.
%-------- Computer Writing data
u=udp('192.168.1.135', 'LocalPort', 15000, 'RemotePort', 15001);
set(u, 'OutputBufferSize', 4048);
set(u, 'ByteOrder', 'littleEndian');
fopen(u);
data = [1:512];
fwrite(u,data,'int16');
I first execute the code that will receive, then execute the code to
write.
I enter this command on the receiving computer: (u2 displays 512
BytesAvailable)
A = fread(u2,512,'int16')
A contains the values 257-512 in a double array. What happened to
1-256? (u2 displays 0 BytesAvailable and 256 BytesReceived)
If I redo the test with:
A = fread(u2,512,'int16=>int16')
I get an error. Error using udp.fread at 211. Invalid PRECISION
specified.
The help on fread said to specify the destination type because DOUBLE
was default. How can I read that udp object and store it into an
int16? AND Get ALL the data?
Thanks,
I hope this isn't too unclear, It has been a long day.
Steve
Subject: TCP communication of 2 computers running Matlab
"steven.bak" <steven.bak@gmail.com> wrote in message <b04cd41d-91cc-
4e00-884a-d4387b008a27@m36g2000hse.googlegroups.com>...
> On Jun 13, 5:52 pm, "Trent Jarvi" <tja...@mathworks.com> wrote:
> > "steven.bak" <steven....@gmail.com> wrote in message
> >
> > news:7ada5081-a6ba-4243-91ae-
bf7596897068@z66g2000hsc.googlegroups.com...
> >
> > >I am trying to send/receive data between two computers running
Matlab
> > > with the tcpip object.
> > > From what I can tell, there is no way to have Matlab "LISTEN" for the
> > > other computer to open aTCPconnection.
> >
> > > Can someone verify this?
> > > I find it strange we have the ability to openTCPconnections, but do
> > > not have the ability to allow another application to open aTCP
> > > connection with Matlab.
> >
> > > Has anyone been able to get Matlab to listen for tcpip connections?
> > > Before I make this project more complicated, I want to make sure I am
> > > not missing an easier route.
> >
> > Hi Steve,
> >
> > The TCPIP client implementation was initially for communicating with
> > instruments that handled the server side. We are listening to feedback
from
> > customers regarding server sockets. For now, it is possible to use the
UDP
> > connections while binding to LocalPorts.
> >
> > >> u=udp('localhost', 'LocalPort', 15000, 'RemotePort', 15001);
> > >> u2=udp('127.0.0.1','LocalPort', 15001, 'RemotePort', 15000);
> > >> fopen(u);
> > >> fopen(u2);
> > >> fprintf(u, 'echo this string\n');
> > >> fscanf(u2)
> >
> > ans =
> >
> > echo this string
>
> Trent,
> Thank you for your response. It has been helpful. I am seeing some
> weird behavior while using fread on a UDP object.
>
> %-------- Computer Writing data
> u=udp('192.168.1.135', 'LocalPort', 15000, 'RemotePort', 15001);
> set(u, 'OutputBufferSize', 4048);
> set(u, 'ByteOrder', 'littleEndian');
> fopen(u);
> data = [1:512];
> fwrite(u,data,'int16');
>
> %-------- Computer Recieving Data
> u2=udp('192.168.1.122', 'LocalPort', 15001, 'RemotePort', 15000);
> set(u2, 'InputBufferSize', 4048, 'ByteOrder', 'littleEndian');
> fopen(u2)
>
>
>
> I first execute the code that will receive, then execute the code to
> write.
> I enter this command on the receiving computer: (u2 displays 512
> BytesAvailable)
>
> A = fread(u2,512,'int16')
>
> A contains the values 257-512 in a double array. What happened to
> 1-256? (u2 displays 0 BytesAvailable and 256 BytesReceived)
> If I redo the test with:
> A = fread(u2,512,'int16=>int16')
> I get an error. Error using udp.fread at 211. Invalid PRECISION
> specified.
> The help on fread said to specify the destination type because DOUBLE
> was default. How can I read that udp object and store it into an
> int16? AND Get ALL the data?
>
>
> Thanks,
> I hope this isn't too unclear, It has been a long day.
>
> Steve
Hi Steve,
The argument passed to fread helps the function interpret the data in the
buffer. In order to convert the received data to int16 or any other datatype
you might want to use either 'typecast' or converting functions like int16()
depending upon your usecase.
Hope this helps.
-Ankit
Subject: TCP communication of 2 computers running Matlab
Ankit, Thanks for the cast help, but that did not address my problem.
(It does help however B = cast(A,'int16') in order to play the audio
back via wavplay(B) )
I believe there is a bug when using fread on a UDP object.
I am sending int16 data with fwrite:
data = [1:512]
data1 = cast(data, 'int16')
fwrite(u,data1,'int16');
Receiving end is broke.
1. A = fread(u2,512,'int16'); %% A is of type Double. How can I
specify the output type to be int16???
OR
2. A = fread(u2,512,'int16=>int16'); %% Error using udp.fread at
211Invalid Precision Specified...... This is directly out of help
file, why the error?
Finally
A = fread(u2,1,'int16')
ans =
1
2
.
.
.
256
3. WHY did it read 256 values instead of 1 (Specified by count)???
Seems to read 512 regardless of what is specified by count.
Questions are numbered above 1, 2, and 3. Any assistance is greatly
appreciated!
Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for
all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content.
Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available
via MATLAB Central. Read the complete Disclaimer prior to use.