DaqAInScanContinue

Hi,
I am using DaqAInScanBegin, Continue and End to get analog input from a force sensor (FSR406) through USB-1208FS. The versions of PsychToolbox and MALTAB are 3.0.17 and 9.5.0.1586782 (R2018b) Update 8. I use Windows10.

The problem I would like to ask for your help is the latency of DaqAInScanContinue.
When I set options and ran the functions as below, DaqAInScanContinue takes about 0.03 sec or more and gets multiples of 31 samples. This number 31 should be the number of samples per block from the DAQ device according to the user’s guide of USB-1208FS.

My goal is to record the input from the sensor during presenting a visual motion stimulus. Is it somehow possible to reduce the delay or keep measuring background so that I can use this function with the loop of updating the screen?


daqIndex = DaqDeviceIndex();
options = [];
options.channel = 0;
options.range = 3;
options.f = 2000;
bparams = DaqAInScanBegin(daqIndex, options);
tic
DaqAInScanContinue(daqIndex, options);
toc
[data, params]=DaqAInScanEnd(daqIndex, options);


Thanks,
Yoshiko

Sorry, I solved the issue. I had mistaken the usage of the functions. Now I use them like this and it works very well:

daqIndex = DaqDeviceIndex();
DaqAInScanBegin(daqIndex, options);
while true
    % Stimulus presentation using Screen function
    if starttiming + presentationtime < GetSecs
        DaqAInScanContinue(daqIndex, options);
        [data, params] = DaqAInScanEnd(daqIndex, options);
        break;
    end
end

Thanks,
Yoshiko

Almost. DaqAInScanContinue(daqIndex, options); must be always executed in your stimulus drawing loop, to keep data acquisition going over longer periods of time. Otherwise you’ll lose data, depending on operating system. "help DaqAInScanBegin`` demonstrates this.

There is one setting options.secs that allows to specify a timeout for how long one DaqAInScanContinue(daqIndex, options); should roughly take (in reality it may take a bit longer, depending on operating system, machine speed etc.), e.g., options.secs=0.002 for 2 msecs. Default is at least 10 msecs per call.

-mario

Thank you mario!
I had given up to use DaqAInScanContinues in drawing loops because of the latency when I uploaded the cord. I tried the option you suggested and DaqAInScanContinues gets 20000 samples in 10 seconds in a loop now :smiley:.

daqIndex = DaqDeviceIndex();
sec_duration = 10;

options = [];
options.channel = 0;
options.range = 3;
options.f = 2000;
options.count = sec_duration * options.f;
options.secs = 0.002;
daici = 0;

bparams = DaqAInScanBegin(daqIndex, options);
starttime = GetSecs;
while true
    params = DaqAInScanContinue(daqIndex, options);
    statusDaqAInContinue = DaqGetStatus(daqIndex);
    
    daici = daici + 1;
    if starttime + sec_duration < GetSecs
        [edata, eparams]=DaqAInScanEnd(daqIndex, options);
        break;
    end
    
end

fprintf('daici: %d\n', daici);
fprintf('n samples read: %d\n', size(edata, 1));
fprintf('n blocks read: %d\n', size(eparams.times, 2));
fprintf('starttime: %f\n', starttime);
fprintf('DAQ 1st block time: %f\n', eparams.times(1));
fprintf('DAQ 2nd block time: %f\n', eparams.times(2));
fprintf('DAQ lastblock time: %f\n', eparams.times(end));

I got these output when I ran the cord above on my average laptop.
daici: 914
n samples read: 20000
n blocks read: 646
starttime: 4301.689783
DAQ 1st block time: 4301.705430
DAQ 2nd block time: 4301.720357
DAQ lastblock time: 4311.689358

I checked the option in my drawing loop to get satisfiable result. Thanks a lot!

My next question is the timing of samplings. Are data sampled during the time range from the timing DaqAInBegin was run (approximately starttime in the cord) to the timing DaqAInEnd was run? Or are they sampled during the time range returned from DaqAInEnd (i.e., from eparams.times(1) to eparams.times(end) in the cord)?

Yoshiko