|On this page…|
You start an analog input object with the start function. For example, to start the analog input object ai:
ai = analoginput('winsound') addchannel(ai,1:2) start(ai)
After start is issued, the Running property is automatically set to On, and both the device object and hardware device execute according to the configured and default property values.
While you are acquiring data with an analog input object, you can preview the data with the peekdata function. peekdata takes a "snapshot" of the most recent data but does not remove data from the engine. For example, to preview the most recent 500 samples acquired by each channel contained by ai:
data = peekdata(ai,500);
Because previewing data is usually a low-priority task, peekdata does not guarantee that all requested data is returned. You can preview data at any time while the device object is running. However, you cannot use peekdata in conjunction with hardware triggers because the device is idle until the hardware trigger is received.
While the analog input object is running, you can log acquired data to the engine (memory) or to a disk file. However, before you can log data a trigger must occur. You configure an analog input trigger with the TriggerType property. For a detailed description of triggers, see Configure Analog Input Triggers.
When the trigger occurs, the Logging property is automatically set to On and data acquired from the hardware is logged to the engine or a disk file. You extract logged data from the engine with the getdata function. For example, to extract all logged samples for each channel contained by ai:
data = getdata(ai);
getdata blocks the MATLAB® Command Window until all the requested data is returned to the workspace. You can extract data any time after the trigger occurs. You can also return sample-time pairs with getdata. For example, to extract 500 sample-time pairs for each channel contained by ai:
[data,time] = getdata(ai,500);
time is an m-by-1 array containing relative time values for all m samples. Time is measured relative to the time the first sample is logged, and is measured continuously until the acquisition stops. You can read more detail in the getdata reference page.
You can log data to disk with the LoggingMode property. You can replay data saved to disk with the daqread function. Refer to Log Information to Disk for more information about LoggingMode and daqread.
An analog input object can stop under one of these conditions:
You issue the stop function.
The requested number of samples is acquired.
A run-time hardware error occurs.
A time-out occurs.
When the device object stops, the Running and Logging properties are automatically set to Off. At this point, you can reconfigure the device object or immediately issue another start command using the current configuration.