how to read LAN data's in m-file

hi,
I sent data from my pc to another pc, only the values sent shows the data. while i am reading in another pc, its not getting read. where sholud i do the mistake?
t=tcpip('192.168.1.4',80) // another pc name
bytesToRead=50;
t.BytesAvailableFcnMode='byte'
t.BytesAvailableFcnCount=bytesToread
fopen(t)
pause(3)
fwrite(t,1:255)
pause(3)
fclose(t)
now, in inspector element, i can see changes in valuesent=255 whereas, the same program only i did in another pc for reading
t=tcpip('192.168.1.4',80) // another pc name
bytesToRead=50;
t.BytesAvailableFcnMode='byte'
t.BytesAvailableFcnCount=bytesToread
fopen(t)
pause(3)
fread(t,255)
pause(3)
fclose(t)
instead of writing. but, there i am not able to see changes in inspector element.how should i do this?

 채택된 답변

Walter Roberson
Walter Roberson 2012년 7월 30일

0 개 추천

t=tcpip('192.168.1.4',80) is the command to use on a "client" (the one that initiates the conversation) that needs to connect to a "server" (the one that the conversation is initiated to.)
So it is fine to use it on the first PC to start the conversation to the second PC (provided the second PC's IP address is 192.168.1.4), but when you use it on the second PC, if the second PC really is 192.168.1.4, it would be a request to connect from the second PC's MATLAB to the second PC's web server. On the second PC, you need to instead use a tcpip() command indicating that you want to receive conversations. See the text starting with "Start a TCP/IP server socke" over in http://blogs.mathworks.com/loren/2011/05/27/transferring-data-between-two-computers-using-matlab/

추가 답변 (3개)

Deepa Darshan
Deepa Darshan 2012년 7월 31일
편집: Walter Roberson 2012년 7월 31일

1 개 추천

I have developed the code based on m-file,not on the instrument control toolbox. also, if i use instrumnet control toolbox, can i read and write data between different pc's?

댓글 수: 1

Walter Roberson
Walter Roberson 2012년 7월 31일
The command tcpip() is not part of basic MATLAB: it is part of the Instrument Control Toolbox.
Your version of MATLAB has an Instrument Control Toolbox which is too old to support acting as a TCP server. To communicate between PCs, you need to do one of:
  1. switch to udp instead of tcp; or
  2. switch to the File Exchange contribution "tcpupdip"; or
  3. upgrade your MATLAB and Instrument Control Toolbox version

댓글을 달려면 로그인하십시오.

Deepa Darshan
Deepa Darshan 2012년 7월 30일
편집: Walter Roberson 2012년 7월 30일

0 개 추천

hi,
Thanks for your kind reply. somehow, i got an idea now, also i tried.But the thing is, i am using R2010a.
here, the tcpip('ipaddress',port) only this facility available. whereas, in the given link, they suggest to use
tcpip('ipadress',port,'NetworkRole',server)
this format, which is not available in R2010a. also, i am getting an warning like,
specified amount of data was not returned within the timeout period.
how much time, should i give,hope it depends on data only know? what else is the problem in the given code?
t=tcpip('192.168.1.1',80)
set(t,'InputBufferSize',1000);
set(t,'TimeOut',30);
fopen(t);
z=fread(t,25);
fclose(t)
this i am checking to read data's from server directly, not between pc's.
how to read from server directly?
regards,
chinny

댓글 수: 1

Walter Roberson
Walter Roberson 2012년 7월 30일
R2010a cannot act as a TCP server when you use the Instrument Control Toolbox. It can receive UDP but not TCP.
The work-around is to use the MATLAB File Exchange contribution named "tcpudpip"

댓글을 달려면 로그인하십시오.

Deepa Darshan
Deepa Darshan 2012년 8월 4일

0 개 추천

ok, let me try it..
thanks, chinny

카테고리

도움말 센터File Exchange에서 Instrument Control Toolbox Supported Hardware에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by