Main Content

readwrite

Simultaneously read and write device channel data

Since R2020a

Description

example

inScanData = readwrite(d,outScanData) writes outScanData to the DataAcquisition interface output channels, and reads inScanData from the DataAcquisition interface input channels. Input and output have the same number of scans, determined by the number of rows in the matrix outScanData. By default, data is returned to inScanData as a timetable. readwrite supports only foreground clocked operations, blocking MATLAB until complete.

[inScanData,triggerTime] = readwrite(d,outScanData) performs the read and write operations, and also returns the scan trigger time to triggerTime as a datetime.

inScanData = readwrite(d,outScanData,"OutputFormat","Matrix") performs the read and write operations, returning a matrix of double values to inScanData.

[inScanData,timeStamp,triggerTime] = readwrite(___,"OutputFormat","Matrix") performs the read and write operations, also returning the scan times as a column vector of doubles to timeStamps, and the scan trigger time to triggerTime as a datenum double. The rows of the timeStamp vector correspond to the rows of the inScanData matrix.

Examples

collapse all

Configure the DataAcquisition 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

DataAcquisition 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 interface. 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

Output Arguments

collapse all

Input scan data from the device, returned as a timetable or matrix of doubles, depending on the OutputFormat setting.

You can access the scan trigger time in the timetable property inScanData.Properties.CustomProperties.TriggerTime, returned as a datetime.

Time that acquisition began, returned as a datetime if OutputFormat is "Timetable" (default), or as a double if OutputFormat is "Matrix". This information is also available as a datetime value in the timetable property inScanData.Properties.CustomProperties.TriggerTime.

Times of scan acquisitions, returned as a matrix of doubles. Each value represents relative time in seconds after the first scan. This argument is returned only when OutputFormat is specified as "Matrix".

Version History

Introduced in R2020a

See Also

Functions