Main Content

read

Read data from VISA resource

    Description

    data= read(v,count)reads the number of values specified bycountfrom the VISA resourcevand returns the data as a row or column vector of doubles or text. The function suspends MATLAB®execution until the specified number of values is read or a timeout occurs.

    example

    data= read(v,count,datatype)reads the number of values specified bycountin the form specified bydatatypeand returns the data. Thedatatypeargument is a character vector of a standard MATLAB data type. For all numericdatatypetypes,datais a row vector of double values. For the text typedatatypevalues of"char"or"string",datais of the specified type.

    Examples

    collapse all

    Create a connection to a VISA resource. This example shows a connection to a device with the aliasCOM4using the VISA-Serial interface.

    v = visadev("COM4");

    Read five values ofuint32data from the VISA resourcev.

    data = read(v,5,"uint32");

    The five values are a total of 20 bytes ofuint32data.

    Input Arguments

    collapse all

    VISA resource, specified as avisadevobject.

    Example:read(v,5)reads data from the VISA resourcev.

    Number of values to read, specified as a positive integer value. Ifcountis greater than theNumBytesAvailableproperty ofv, the function suspends MATLAB execution and waits until it reads the specified amount of data or a timeout occurs.

    Example:read(v,2)reads two values ofuint8data.

    Data Types:single|double|int8|int16|int32|int64|uint8|uint16|uint32|uint64

    Size and format of each value, specified as a character vector or string.datatypedetermines the number of bytes to read for each value and the interpretation of those bytes as a MATLAB data type.

    Example:read(v,1,"uint16")reads one value ofuint16data. Each uint16 value is two bytes.

    Data Types:char|string

    版本历史

    Introduced in R2021a