How do I get MATLAB to read an ASCII String through TCPIP?
3 views (last 30 days)
Show older comments
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")
0 Comments
Answers (1)
Dheeraj
on 28 Feb 2024
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 Comment
Walter Roberson
on 28 Feb 2024
To clarify:
You do not need to fopen() a tcpclient(): you just go ahead and use the object.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!