TCP/IP Explorer
Connect to and communicate with TCP/IP server
Description
The TCP/IP Explorer app creates a TCP/IP client connection to an existing TCP/IP server. After you connect to a server, you can communicate with it, plot and analyze data, export data to the workspace, and generate MATLAB® code.
Using this app, you can:
Configure TCP/IP communication properties.
Send binary or string data from the TCP/IP client to the connected server.
Read binary or string data sent to the TCP/IP client from the connected server.
Plot data in a figure window.
Analyze data by viewing it in the Signal Analyzer app.
Export data to the workspace.
Generate a MATLAB Live Script file that uses the
tcpclient
interface.
You can use this app only as a client and not as a server. For information on creating a TCP/IP server, see Communicate Using TCP/IP Server Sockets.
Open the TCP/IP Explorer App
MATLAB Toolstrip: On the Apps tab, under Test and Measurement, click the app icon.
MATLAB command prompt: Enter
tcpipExplorer
.
Examples
Parameters
Write SectionData Format
— Select type of write operation
Binary
(default) | ASCII-Terminated String
Data Type
— Select MATLAB data type to write
uint8
| int8
| uint16
| int16
| uint32
| int32
| uint64
| int64
| single
| double
| char
| string
Specify the data type of the data to write from the TCP/IP client to the connected server. This parameter determines the number of bytes to write for each value and the interpretation of those bytes as a MATLAB data type.
Dependencies
If you set the Data Format to ASCII-Terminated
String
, the only possible value for this parameter is
string
.
This parameter can be set to uint64
or
int64
only if you select the Workspace
Variable option instead of Data to Write.
Data to Write
— Specify numeric or ASCII data to write
numeric | character vector | string scalar
Specify the data to write from the TCP/IP client to the connected server. The data is written as the type specified by Data Type, regardless of the format in this parameter.
Select either this parameter or Workspace Variable to write data.
Workspace Variable
— Select workspace variable to write
workspace variable
Select an existing workspace variable to write from the TCP/IP client to the connected server. The data is written as the type specified by Data Type, regardless of the data type of the variable in the workspace.
If Data Format is Binary
, you can
select the following types of workspace variables:
Row (1-by-
N
) or column (N
-by-1) vector of numeric values1-by-
N
character vector1-by-1 string scalar
If Data Format is ASCII-Terminated
String
, you can select the following types of workspace variables:
1-by-
N
character vector1-by-1 string scalar
Select either this parameter or Data to Write to write data.
Write
— Write data using specified settings
button
Click this button to write the data specified in Data to Write
or Workspace Variable from the TCP/IP client to the connected
server as the specified Data Type. If Data
Format is ASCII-Terminated String
, the write
terminator specified by the Terminator
property is automatically appended to the data being written.
This button is equivalent to performing the write
or
writeline
functions.
Data Format
— Select type of read operation
Binary
(default) | ASCII-Terminated String
Data Type
— Select MATLAB data type to read
uint8
| int8
| uint16
| int16
| uint32
| int32
| uint64
| int64
| single
| double
| char
| string
Specify the data type of the data received by the TCP/IP client from the connected server. This parameter determines the number of bytes to read for each value and the interpretation of those bytes as a MATLAB data type.
Dependencies
If you set the Data Format to ASCII-Terminated
String
, the only possible value for this parameter is
string
.
Num Values to Read
— Specify number of values of selected Data Type to read
numeric
Specify the number of values to read as a positive integer. This parameter must be less than or equal to Values Available. If you leave this parameter empty, the client reads all available values using the specified Data Type.
Dependencies
To enable this parameter, set Data Format to
Binary
.
Values Available
— Maximum possible number of values of selected Data Type that can be read
numeric
This property is read-only.
This is the number of values available to read in the format specified by Data Type.
Dependencies
To enable this parameter, set Data Format to
Binary
.
Read
— Read data using specified settings
button
Click this button to read data received by the TCP/IP client from the connected
server. If Data Format is Binary
, read
the number of values specified by Num Values to Read in the form
specified by Data Type. If Data Format is
ASCII-Terminated String
, read data until the first
occurrence of the read terminator specified by the Terminator
property.
This button is equivalent to the read
or readline
functions.
Display
— Select format to view data in Communication Log
Default
(default) | Binary
| ASCII
| Hexadecimal
View the data in the Data column of the Communication
Log as Binary
, ASCII
,
or Hexadecimal
, as applicable based on the data type. This
parameter does not change the original value or data type of the data. For more
information about these formats, see Data Type Conversion.
Clear
— Clear Communication Log
button
Click this button to clear all the contents of the Communication Log.
Plot
— Plot selected row of data
button
Click this button to open a new figure window that plots the data currently selected in the Communication Log. You can select only one row of data, and the selected data must be numeric.
Unlike Write and Read, this operation is not captured in the MATLAB Code Log pane.
Signal Analyzer
— View selected row of data in Signal Analyzer app
button
Click this button to launch the Signal Analyzer app and send it the data currently selected in the Communication Log. You can select only one row of data, and the selected data must be a numeric vector.
You must have Signal Processing Toolbox™ installed to use the Signal Analyzer app.
Workspace Variable
— Specify name of workspace variable to export data to
valid variable name
Edit the name of the workspace variable that you want to export data to. The
Export Selected Row
and Export Communication
Log
options in Export save your data in the
workspace as the variable specified by this parameter.
You must specify a valid MATLAB variable name that does not already exist in the workspace. If you specify an invalid name, it is automatically changed to a valid variable name.
Export
— Export Communication Log data or MATLAB code
Export Selected Row
| Export Communication Log
| Generate MATLAB Script
Click this button to select one of the following options for exporting data from this app:
Export Selected Row
— Save the data currently selected in the Communication Log to the workspace as the variable specified by Workspace Variable. The data is saved as its Data Type.Export Communication Log
— Save all of the Communication Log data to the workspace as atimetable
with the variable name specified by Workspace Variable.Generate MATLAB Script
— Generate a MATLAB Live Script file populated with the content in MATLAB Code Log and open it in the Live Editor.
Address
— Server name or IP address
character vector
This property is read-only.
Server name or IP address, returned as a character vector. This property is set during TCP/IP Connection configuration.
Port
— Server port
numeric
This property is read-only.
Server port, returned as a number between 1 and 65535, inclusive. This property is set during TCP/IP Connection configuration.
ConnectTimeout
— Allowed time to connect to server
10
(default) | numeric
This property is read-only.
Allowed time in seconds to connect to the server, specified as a numeric value. This property specifies the maximum time to wait for a connection request to the specified server to succeed or fail. This property is set during TCP/IP Connection configuration.
EnableTransferDelay
— Allow delayed acknowledgement from server
true
(default) | false
This property is read-only.
Allow delayed acknowledgement from server, specified as logical
true
or false
. This property indicates whether
Nagle's algorithm is on or off for the connection.
If this property is true
, the client collects small segments of
outstanding data and sends them in a single packet when acknowledgement (ACK) arrives
from the server. Set this property to false
if you want to
immediately send data to the network. If a network is slow, you can improve its
performance by enabling the transfer delay. However, on a fast network acknowledgements
arrive quickly and the difference between enabling or disabling the transfer delay is
negligible.
This property is set during TCP/IP Connection configuration.
NumBytesAvailable
— Number of bytes available to read
numeric
This property is read-only.
Number of bytes available to read, returned as a numeric value.
Terminator
— Terminator characters for data
LF
(default) | CR
| CR/LF
| 0 to 255
Terminator characters for reading and writing ASCII-terminated data, specified as
LF
, CR
,
CR/LF
, or a number from 0 to 255. The read terminator is
followed by the write terminator and the two are separated by a comma. Click the
vertical ellipsis icon to specify read and write terminator character values
separately.
ByteOrder
— Sequential order of bytes
little-endian
(default) | big-endian
Sequential order in which bytes are arranged into larger numerical values. If the
byte order is little-endian
, then the remote server stores
the first byte in the first memory address. If the byte order is
big-endian
, then the remote server stores the last byte in
the first memory address.
Configure the byte order to match the appropriate value for your server.
Timeout
— Allowed time to complete operations
10 (default) | numeric
Allowed time in seconds to complete read operations, specified as a numeric value.
Version History
Introduced in R2021b