How do I get MATLAB to read an ASCII String through TCPIP?

조회 수: 3 (최근 30일)
Cassandra Troksa
Cassandra Troksa 2021년 9월 27일
댓글: Walter Roberson 2024년 2월 28일
I am trying to get MATLAB to receive/display an string from a TCPIP connection. I can successfully connect/ping between the computers and send packets using PacketSender.
A couple notes:
  • Changing tcpip to tcpclient prevents fopen from functioning, "First input must be a file name or a file identifier"
  • Changing tcpip to tcpserver returns "Can't assign requested address"
  • I've attempted to use callbacks/terminators with little success (may be doing it wrong)
  • I've attempted to use writeline/readline commands and the request times out
I am a beginner at MATLAB and not a networking person. Help is appreciated!
echotcpip("on",20000)
t = tcpip('169.254.200.29',20000); %Connection to computer & port
fopen(t)
fwrite(t,'Setup_ProfileName_ChairPosition') %Select profile & chair start position from program
pause(20)%Allows time for chair to move/for program to send confirmation string
%I'd like to dispaly the communication from the program that the chair is in its
%starting position here.
t = tcpip('169.254.200.29',20000);%Ensure connection - it doesn't stay connected without this line?
fopen(t)
fwrite(t,'Start')%Start Profile
%Display start of profile and end of profile
echotcpip("Off")

답변 (1개)

Dheeraj
Dheeraj 2024년 2월 28일
Hi,
I understand that you’re trying to establish a TCP/IP connection between MATLAB and another device to send and receive strings.
“tcpip” object is to be deprecated in future releases and it’s advised to use “tcpclient” and “tcpserver”.
“fopen” does not work with “tcpclient” instead use “fread”, “fwrite” to read and write.
You can use “fgetl”, “fgets” to read and parse string data.
Hope this helps!
  댓글 수: 1
Walter Roberson
Walter Roberson 2024년 2월 28일
To clarify:
You do not need to fopen() a tcpclient(): you just go ahead and use the object.

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

태그

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by