Contenu principal

readwrite

R2026b

Simultaneously read and write device channel data

Description

inScanData = readwrite(d,outScanData) writes outScanData to the output channels of the device corresponding to DataAcquisition object d and simultaneously returns the data read from the input channels. The returned data inScanData is a timetable with the same number of rows as outScanData.

[inScanData,triggerTime] = readwrite(d,outScanData) also returns the scan trigger time as a datetime.

inScanData = readwrite(d,outScanData,OutputFormat=format) sets the format of the returned data as a matrix or a timetable. The default format is timetable.

[inScanData,timeStamp,triggerTime] = readwrite(___,OutputFormat="Matrix") returns the scan data, timestamps, and trigger time as a matrix. The function returns timestamps as the second output argument only if the OutputFormat is "Matrix".

Note

The readwrite function supports only foreground clocked operations, which reset counter inputs and block MATLAB until the read and write operations are complete.

example

Examples

collapse all

Configure the DataAcquisition object to measure and generate voltage simultaneously, in the foreground.

d = daq("ni");
addinput(d,"Dev1","ai0","Voltage");
addoutput(d,"Dev1","ao0","Voltage");
outScanData = linspace(0,1,d.Rate)'; % Increase output voltage with each scan.
inScanData = readwrite(d,outScanData);

Input Arguments

collapse all

Data acquisition interface, specified as a DataAcquisition object, created using the daq function.

Example: d = daq()

Scan data for device output, specified as an M-by-N matrix, where M is the number of data scans and N is the number of output channels in the DataAcquisition object. For a single channel, the data is a column vector. Single scans are not supported by this function, so M must be greater than 1.

Data Types: double

Format of read operation output, specified as one of:

  • "TimeTable" — The function returns only scanData and triggerTime when you specify this option, as timetable and datetime values, respectively.

  • "Matrix" — The function returns scanData, timeStamp, and triggerTime as matrices when you specify this option.

Example: read(dObj,10,OutputFormat="Matrix")

Data Types: string

Output Arguments

collapse all

Input scan data from the device, returned as a timetable or M-by-N double matrix, depending on the OutputFormat setting. When inScanData is a matrix, M is the number of scans and N is the number of input channels. Each column contains the data from one channel.

The timestamp for each scan in the timetable is a duration value relative to the trigger time. You can also access the scan trigger time as a datetime value in the Properties.CustomProperties.TriggerTime property of the returned timetable variable, inScanData.

Data acquisition start time, returned as a datetime if OutputFormat is "Timetable" (default), or as a double if OutputFormat is "Matrix". The double value represents the date in the format returned by datenum. This information is also available as a datetime value in the Properties.CustomProperties.TriggerTime property of the returned timetable variable, inScanData.

Relative timestamps of data acquisition, returned as an M-by-1 double vector where M is the number of scans. Each value represents relative time in seconds after the first scan. The function returns the timestamps in the second output argument only when you set OutputFormat to "Matrix".

Version History

Introduced in R2020a