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 client interface is supported on the same platforms as MATLAB®. For updates to the list of currently supported platforms, seeSystem Requirements.
Make sure you can create your TCP/IP client object. You create a client object with thetcpclient
函数,它要求uires the name of the remote host as an input argument. You also need to specify the remote port value.
Each client object is associated with one instrument. For example, to create a client 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 HTTPget
orpost
commands. You can also use theurlread
orwebread
functions to communicate with web servers.
Many TCP/IP servers expect header information inside the TCP/IP packet.
SeeWrite and Read Data over TCP/IP Interfacefor an example of communication over TCP/IP.
You can also use thevisadev
interface with a VISA-TCP/IP resource name instead of thetcpclient
interface for TCP/IP communication with instruments.
Make sure the correct data type—for exampleint16
,uint16
,double
—is being used withread
andwrite
. Use the same data type as the instrument. If reading and writing data types other thanuint8
orint8
, make sure theByteOrder
is correct.