TCP/IP and UDP Interface

Communication using the TCP/IP clients and servers or UDP protocol

Use the TCP/IP and UDP interfaces for reading and writing both binary data and ASCII data. You use different functions for the different data types – fprintf and fscanf for ASCII operations, and fread and fwrite for binary data. You can also do asynchronous operations using other functions.

Functions

expand all

tcpipCreate TCPIP object
udpCreate UDP object
echotcpipStart or stop TCP/IP echo server
echoudpStart or stop UDP echo server
resolvehostNetwork name or network address
tmtoolOpen Test & Measurement Tool
fopenConnect interface object to instrument
fcloseDisconnect interface object from instrument
freadRead binary data from instrument
fwriteWrite binary data to instrument
fscanfRead data from instrument, and format as text
fprintfWrite text to instrument
readasyncRead data asynchronously from instrument
stopasyncStop asynchronous read and write operations
binblockreadRead binblock data from instrument
binblockwriteWrite binblock data to instrument
fgetlRead line of text from instrument and discard terminator
fgetsRead line of text from instrument and include terminator
queryWrite text to instrument, and read data from instrument
scanstrRead data from instrument, format as text, and parse
clearRemove instrument objects from MATLAB workspace
deleteRemove instrument objects from memory
instrhwinfoInformation about available hardware
instrfindRead instrument objects from memory to MATLAB workspace
instrfindallFind visible and hidden instrument objects
instrresetDisconnect and delete all instrument objects
flushinputRemove data from input buffer
flushoutputRemove data from output buffer
instrcallbackDisplay event information when event occurs

Blocks

expand all

Query InstrumentQuery or read instrument data
To InstrumentSend simulation data to instrument
TCP/IP ReceiveReceive data over TCP/IP from specified remote machine
TCP/IP SendSend data over TCP/IP to specified remote machine
UDP ReceiveReceive data over UDP network from specified remote machine
UDP SendSend data over UDP network to specified remote machine

Examples and How To

TCP/IP Client

Create a TCP/IP Object

Create a TCP/IP object to establish a connection between MATLAB® and the remote host.

TCP/IP Communication with a Remote Host

These are the minimum steps required to communicate with a remote host over TCP/IP.

Rules for Completing Read and Write Operations over TCP/IP and UDP

The rules for completing synchronous and asynchronous read and write operations are described here.

Basic Workflow to Read and Write Data over TCP/IP

This example illustrates how to use text and binary read and write operations with a TCP/IP object connected to a remote instrument.

Read and Write ASCII Data over TCP/IP

This section provides details and examples exploring ASCII read and write operations with a TCP/IP object.

Read and Write Binary Data over TCP/IP

This section provides details and examples exploring binary read and write operations with a TCP/IP object.

Asynchronous Read and Write Operations over TCP/IP

This section provides details and examples exploring asynchronous read and write operations with a TCP/IP object.

TCP/IP Server

Communicate Using TCP/IP Server Sockets

Support for Server Sockets is available for a single remote connection. You can use this connection to communicate between a client and MATLAB, or between two instances of MATLAB.

UDP

Create a UDP Object

Create a UDP object to establish a connection between MATLAB and the remote host.

UDP Communication Between Two Hosts

These are the minimum steps required to communicate between two hosts over UDP.

Rules for Completing Read and Write Operations over TCP/IP and UDP

The rules for completing synchronous and asynchronous read and write operations are described here.

Basic Workflow to Read and Write Data over UDP

This example shows the basic workflow of text read and write operations with a UDP object connected to a remote instrument.

Read and Write ASCII Data over UDP

This section provides details and examples exploring ASCII read and write operations with a UDP object.

Read and Write Binary Data over UDP

This section provides details and examples exploring binary read and write operations with a UDP object.

Asynchronous Read and Write Operations over UDP

This section provides details and examples exploring asynchronous read and write operations with a UDP object.

Concepts

TCP/IP and UDP Comparison

Transmission Control Protocol (TCP or TCP/IP) and User Datagram Protocol (UDP or UDP/IP) are both transport protocols layered on top of the Internet Protocol (IP). The two protocols are compared here.

Events and Callbacks

Enhance your instrument communication using events and callbacks.

Instrument Control Toolbox Properties

These properties are available in the toolbox.

Troubleshooting

Troubleshooting TCP/IP Interface

Try these tips if you have problems using the toolbox with the TCP/IP interface. Includes information about TCP/IP supported platforms, configuration and connection, and other interface-specific tips.

Troubleshooting UDP Interface

Try these tips if you have problems using the toolbox with the UDP interface. Includes information about UDP supported platforms and configuration and connection.

Featured Examples