File: DaqWaitButtonDumbTest1408FS.m

package info (click to toggle)
psychtoolbox-3 3.0.19.14.dfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 86,796 kB
  • sloc: ansic: 176,245; cpp: 20,103; objc: 5,393; sh: 2,753; python: 1,397; php: 384; makefile: 193; java: 113
file content (49 lines) | stat: -rw-r--r-- 1,139 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
% DaqWaitButtonDumbTest1408FS.m
%
% A quick and dirty demo on how to poll the digital inputs
% of a USB-1408FS as fast as possible, without overhead.
%
% This is essentially a stripped down version of DaqDIn() with
% some polling loops wrapped around and a options.secs value of
% zero for essentially polling with no timeout.
%

daq = DaqFind;
reportId = 3;
TheReport = uint8(0);
NumberOfPorts = 2;

if IsWin
 % Windows needs some minimal polling time:
 options.secs = 0.001;
else
 options.secs = 0.000;
end

PsychHID('ReceiveReportsStop',daq);
PsychHID('GiveMeReports',daq);
PsychHID('ReceiveReports',daq, options);

while 1
% Emit query to device:
PsychHID('SetReport',daq,2,reportId, TheReport);

% Wait for result from device:
inreport = [];
while isempty(inreport)
% Yield some minimum amount of time to other processes if you want to be
WaitSecs('YieldSecs', 0);
% New data available?
inreport = PsychHID('GetReport',daq,1,reportId,NumberOfPorts+1);
end

% inreport contains latest button query result: Button pressed?
if inreport(3) ~= 255
% yes: Done!
break;
end

% No. Repeat sampling...
end

fprintf('Change detected! Bye.\n');