Main Content


Write command to remote host over TCP/IP and read response

Since R2020b



    response = writeread(t,command) writes the ASCII text command followed by the terminator to the remote host specified by the TCP/IP client t, then reads the ASCII text returned from the remote host. You can use this function to query the remote host. The function suspends MATLAB® execution until the specified command is sent to the remote host and a response is received.


    collapse all

    Create a TCP/IP client connection to an instrument. In this example, the instrument connected to this network is a Keysight Technologies® (formerly Agilent Technologies®) X-Series Signal Analyzer (N9030A, PXA Signal Analyzer). The specified IP address and port are unique to this example.

    t = tcpclient("",5025)
    t = 
      tcpclient with properties:
                  Address: ''
                     Port: 5025
        NumBytesAvailable: 0
      Show all properties, functions

    Write an instrument identification SCPI command to the instrument and read the response.

    ans = 
    "Agilent Technologies,N9030A,US00071181,A.14.16"

    The instrument response to the *IDN? command identifies the name of the instrument.

    Input Arguments

    collapse all

    TCP/IP client, specified as a tcpclient object.

    Example: writeread(t,"*IDN?") sends an ASCII text command to the TCP/IP client t.

    ASCII text command to write to device, specified as a character vector or string scalar.

    Example: writeread(t,"*IDN?") sends the ASCII command *IDN?.

    Data Types: char | string

    Version History

    Introduced in R2020b