MATLAB: Does the ANALOGINPUT object not acquire any data when I use an external trigger provided by a DIGITALIO object using Data Acquisition Toolbox 2.14 (R2009a)

conditionData Acquisition Toolboxedgetriggertriggerconditiontriggertype

I am attempting to acquire data using an NI PXI-6120 board using the Data Acquisition Toolbox 2.14 (R2009a). I am using an External Hardware Trigger to start the data acquisition. I am providing this trigger signal using a digital signal generated by a DIGITALIO object.
I am use the code-snippet below to perform the acquisition:
dio = digitalio('nidaq', 'Dev1');
addline(dio, 4, 'Out'); %Addline 4
putvalue(dio, 0); %Set value to Lo.
% Include code for creating and setting up AnalogOuput (AO) object
% Include code for creating and setting up AnalogInput (AI) object
start([ai ao]);
pause(1);
putvalue(dio, 0); %Set value to Lo again.
pause(1);
putvalue(dio, 1); %Set value to Hi.
pause(31);
[data,time]=getdata(ai,1*fs);
However, when I execute this code, I receive the following error:
??? A timeout occurred during GETDATA.
Error ==> NL_AM_sin_external_trigger_FreqMeasur2_stereo2_2chInput_NI at 457
[data,time]=getdata(ai,1*fs);
Error event occurred at 17:53:33 for the object: nidaqmxDev1-AI.
A timeout occurred during GETDATA.
My code appears to be correct. Why do I receive this error message?

Best Answer

The use of an external hardware trigger using Digital Signal source is specified by setting the "TriggerType" property to "HWDigital". When doing so, the condition which initiates the data acquisition is controlled by the "TriggerCondition" property. For National Instruments boards, this value is by default set to "NegativeEdge" i.e. the trigger occurs when the negative (falling) edge of a digital signal is detected.
In the code snippet above, only a rising edge occurs when you write a value "1" to the DIGITALIO line. Hence, as no trigger is received, no data will be acquired which results in the call to the GETDATA function timing out.
To ensure that data has been acquired, you can use one of the following methods:
1. Set the "TriggerCondition" property to "PositiveEdge" or
2. Generate a negative edge on the trigger signal by using the following code snippet:
putvalue(dio, 1);
start([ai ao]);
putvalue(dio, 0);