Thread Subject: Serial and TCP/IP both interfacing for serial Tunnelling

Subject: Serial and TCP/IP both interfacing for serial Tunnelling

From: SAGAR

Date: 22 Feb, 2010 16:55:10

Message: 1 of 6

 I am working on a project in which I need to send data from serial port of one PC to serial port of other PC in real time , the PCs are in the same LAN, We will give data to server PC from micro-controller and client PC will give the same data to micro-controller connected to its serial port

I have tried in both simulink and m file but it was not completely possible
Pease help me
I am student and not a professional so i know very little about MATLAB

Subject: Serial and TCP/IP both interfacing for serial Tunnelling

From: Trent Jarvi

Date: 23 Feb, 2010 00:32:32

Message: 2 of 6


"SAGAR " <sagargkoli@yahoo.com> wrote in message
news:hlucte$n99$1@fred.mathworks.com...
> I am working on a project in which I need to send data from serial port of
> one PC to serial port of other PC in real time , the PCs are in the same
> LAN, We will give data to server PC from micro-controller and client PC
> will give the same data to micro-controller connected to its serial port
> I have tried in both simulink and m file but it was not completely
> possible Pease help me I am student and not a professional so i know very
> little about MATLAB
>

Could you share the MATLAB code that you are trying? Perhaps we can
identify a problem.

Subject: Serial and TCP/IP both interfacing for serial Tunnelling

From: SAGAR

Date: 5 Mar, 2010 09:59:29

Message: 3 of 6

"Trent Jarvi" <tjarvi@mathworks.com> wrote in message <hlv7n0$f2a$1@fred.mathworks.com>...
>
> "SAGAR " <sagargkoli@yahoo.com> wrote in message
> news:hlucte$n99$1@fred.mathworks.com...
> > I am working on a project in which I need to send data from serial port of
> > one PC to serial port of other PC in real time , the PCs are in the same
> > LAN, We will give data to server PC from micro-controller and client PC
> > will give the same data to micro-controller connected to its serial port
> > I have tried in both simulink and m file but it was not completely
> > possible Pease help me I am student and not a professional so i know very
> > little about MATLAB
> >
>
> Could you share the MATLAB code that you are trying? Perhaps we can
> identify a problem.
>

to Send

%Data flow From PC with IP 172.16.20.134 to PC with IP 172.16.20.32
%On 172.16.20.134
a = serial('COM1');
fopen(a);
u = tcpip('172.16.20.32', 9091, 'LocalPort', 9090 );
fopen(u);
for i = 0:1:10
b = fgetl(a);
fwrite(u,b);
end
fclose(a);
fclose(u);

clear u;
u = instrfindall;
clear a;
a = instrfindall;
clear

To Receive

%Data flow From PC with IP 172.16.20.134 to PC with IP 172.16.20.32
%on 172.16.20.32
a = serial('COM1');
fopen(a);
u = tcpip('172.16.20.134', 9090, 'LocalPort', 9091 );
fopen(u);
for i = 0:1:10
b = fgetl(u);
fwrite(a,b);
end
fclose(a);
fclose(u);

clear u;
u = instrfindall;
clear a;
a = instrfindall;
clear

Subject: Serial and TCP/IP both interfacing for serial Tunnelling

From: Trent Jarvi

Date: 9 Mar, 2010 16:24:45

Message: 4 of 6


"SAGAR " <sagargkoli@yahoo.com> wrote in message
news:hmqkm1$h7q$1@fred.mathworks.com...
> "Trent Jarvi" <tjarvi@mathworks.com> wrote in message
> <hlv7n0$f2a$1@fred.mathworks.com>...
>>
>> "SAGAR " <sagargkoli@yahoo.com> wrote in message
>> news:hlucte$n99$1@fred.mathworks.com...
>> > I am working on a project in which I need to send data from serial port
>> > of one PC to serial port of other PC in real time , the PCs are in the
>> > same LAN, We will give data to server PC from micro-controller and
>> > client PC will give the same data to micro-controller connected to its
>> > serial port
>> > I have tried in both simulink and m file but it was not completely
>> > possible Pease help me I am student and not a professional so i know
>> > very little about MATLAB
>> >
>>
>> Could you share the MATLAB code that you are trying? Perhaps we can
>> identify a problem.
>
> to Send
>
> %Data flow From PC with IP 172.16.20.134 to PC with IP 172.16.20.32
> %On 172.16.20.134
> a = serial('COM1');
> fopen(a);
> u = tcpip('172.16.20.32', 9091, 'LocalPort', 9090 );
> fopen(u);
> for i = 0:1:10
> b = fgetl(a);
> fwrite(u,b);
> end
> fclose(a);
> fclose(u);
>
> clear u;
> u = instrfindall;
> clear a;
> a = instrfindall;
> clear
>
> To Receive
>
> %Data flow From PC with IP 172.16.20.134 to PC with IP 172.16.20.32 %on
> 172.16.20.32
> a = serial('COM1');
> fopen(a);
> u = tcpip('172.16.20.134', 9090, 'LocalPort', 9091 );
> fopen(u);
> for i = 0:1:10
> b = fgetl(u);
> fwrite(a,b);
> end
> fclose(a);
> fclose(u);
>
> clear u;
> u = instrfindall;
> clear a;
> a = instrfindall;
> clear
>

Thanks for sharing the code.

The code appears to be from a UDP example. With TCPIP, you need a server
socket on one side. MATLAB does not provide server sockets at this time.
You can replace TCPIP with UDP above or look around MATLAB Central File
Exchange for TCPIP server socket options.

Subject: Serial and TCP/IP both interfacing for serial Tunnelling

From: SAGAR

Date: 10 Mar, 2010 12:03:04

Message: 5 of 6

I have tried the above code but its not working
can somebody provide me the code

or can i do the same using simulink in matlab?

thanks in anticipation

Subject: Serial and TCP/IP both interfacing for serial Tunnelling

From: Trent Jarvi

Date: 11 Mar, 2010 00:17:21

Message: 6 of 6


"SAGAR " <sagargkoli@yahoo.com> wrote in message
news:hn81po$sep$1@fred.mathworks.com...
>I have tried the above code but its not working can somebody provide me the
>code
> or can i do the same using simulink in matlab?
> thanks in anticipation

The code appears to be fine except that you want to use FPRINTF to append a
terminator character instead of FWRITE. You may try using FREAD to see what
actual bytes you are getting. FGETL will expect a terminator character (new
line).

For Simulink, you would use the Instrument Control Toolbox product UDP Send
and UDP Receive along with the Serial send/receive..

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

Tag Activity for This Thread
Tag Applied By Date/Time
tcpip SAGAR 5 Mar, 2010 04:59:38
serial SAGAR 5 Mar, 2010 04:59:38
tcpip serial SAGAR 22 Feb, 2010 11:59:23
rssFeed for this Thread

Contact us at files@mathworks.com