writeread

Write command to serial port and read response

Description

example

response = writeread(device,command) writes the ASCII text command followed by the terminator to the specified serial port device, then reads the ASCII text returned from the device and assigns it to response. You can use this function to query an instrument connected to the serial port. The function blocks MATLAB and waits until the command and response are complete, or a timeout occurs.

Examples

collapse all

Write an instrument identification query to a serial instrument and read the response. writeline automatically includes the defined terminator.

s = serialport("COM3",9600);
configureTerminator(s,"CR")
 ⋮
resp = writeread(s,"*IDN?");

Input Arguments

collapse all

Serial port, specified as a serialport object.

Example: serialport()

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

Example: "IDN?"

Data Types: char | string

Output Arguments

collapse all

ASCII text response from device, returned as a string. The terminator is not included.

Introduced in R2019b