Transmission Control Protocol (TCP) is a transport protocol layered on top of the Internet Protocol (IP) and is one of the most highly used networking protocols. You can use network socket communication to connect to remote hosts to read and write data.
If you are having trouble connecting to or communicating with your remote host, try these troubleshooting tips.
TCP/IP is supported on these platforms:
Linux®
macOS
Windows® 10
The TCP/IP interface is supported on the same platforms as MATLAB®. For updates to the list of currently supported platforms, see System Requirements.
Make sure you can create your TCP/IP object. You create a TCP/IP object
with the tcpclient
function, which requires the name of
the remote host as an input argument. You also need to specify the remote
port value.
Each TCP/IP object is associated with one instrument. For example, to create a TCP/IP object for a Sony/Tektronix® AWG520 Arbitrary Waveform Generator, you use the remote host name of the instrument and the port number, which can be found in the instrument documentation.
t = tcpclient("sonytekawg.yourdomain.com",4000);
After you connect to the device, you can communicate with it. If sending and receiving does not work, you can check the following:
Make sure the data is being sent in the format expected by the server.
If you connect to a web server, you might need to send HTTP
get
or post
commands. You
can also use the urlread
or
webread
functions to communicate with web
servers.
Many TCP/IP servers expect header information inside the TCP/IP packet.
See Write and Read Data over TCP/IP Interface for an example of communication over TCP/IP.
You can also use the visa
interface with a VISA TCP/IP resource
name instead of the tcpclient
interface for TCP/IP communication
with instruments.
Make sure the correct data type—for example int16
,
uint16
, double
—is being used with
read
and write
. Use the same data type as
the instrument. If reading and writing data types other than
uint8
or int8
, make sure the
ByteOrder
is correct.