-
Notifications
You must be signed in to change notification settings - Fork 0
/
seDAQ.m
174 lines (134 loc) · 6.02 KB
/
seDAQ.m
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
classdef seDAQ < handle
% returns DAQ object/struct containing information to send out event codes
% to data acquisition device.
%
properties
isPresent = false; % whether the DAQ device is present or not
deviceNum = NaN; % number-pointer to DAQ device
lastCode = NaN; % value of last eventCode that was successfully sent out
end % properties
properties(Hidden = true, Constant = true)
RESP = 'resp'; %
EVENT = 'event';
EVENT_PORT = 0; % value to send eventCode out of event port
RESP_PORT = 1; % value to send eventCode out of response port
CONFIG_OUTPUT = 0; % value to designate if port as output
CONFIG_INPUT = 1; % value to designate if port as input
RESET_EVENTCODE = 0; % arbitrary number for resets
TIME_DELAY = 0.010; % (secs) time duration to leave event codes on after sending them out
EVENT_CODE_LIMIT = 255; % max event code
end
properties(Hidden = true)
pcIO; % input/output (IO) object to send event codes on PCs
BIOSEMI = 'Biosemi';
BRAINPRODUCTS = 'BrainProducts';
end
methods
function obj = seDAQ()
if ismac
obj.deviceNum = DaqDeviceIndex();
obj.isPresent = ~isempty(obj.deviceNum);
if(obj.isPresent)
configPorts(obj); % Basic DAQ-device Setup %
end
elseif ispc
buttonname=questdlg('Please select data acquisition system:','DAQ?',obj.BIOSEMI, obj.BRAINPRODUCTS, obj.BIOSEMI);
switch buttonname
case obj.BIOSEMI
obj.deviceNum = hex2dec('2050');
case obj.BRAINPRODUCTS
obj.deviceNum = hex2dec('2030');
end
obj.pcIO = io64();
obj.isPresent = ~io64(obj.pcIO);
end
end % daq constructor method
function configPorts(obj)
display(sprintf('Configuring ports %d and %d as output ports', obj.EVENT_PORT, obj.RESP_PORT));
DaqDConfigPort(obj.deviceNum, obj.EVENT_PORT, obj.CONFIG_OUTPUT); % configure as output port
DaqDConfigPort(obj.deviceNum, obj.RESP_PORT, obj.CONFIG_OUTPUT); % configure as output port
end % configPorts method
function sendEventCode(obj, eventCode)
% SENDEVENTCODE Sends event/response eventCode out to DAQ device.
% CODE must be an integer 1-254
if(obj.isPresent && (0 < eventCode < obj.EVENT_CODE_LIMIT))
if ismac
DaqDOut(obj.deviceNum, obj.EVENT_PORT, eventCode); % Send event code
WaitSecs(obj.TIME_DELAY);
DaqDout(obj.deviceNum, obj.EVENT_PORT, obj.RESET_EVENTCODE); % Clear event code
WaitSecs(obj.TIME_DELAY);
elseif ispc
io64(obj.pcIO, obj.deviceNum, eventCode);
WaitSecs(obj.TIME_DELAY);
io64(obj.pcIO, obj.deviceNum, obj.RESET_EVENTCODE);
WaitSecs(obj.TIME_DELAY);
end
elseif(~obj.isPresent)
fprintf('Error:\tDAQ device not present\n\tEvent code %03d not sent\n',eventCode);
elseif(~(0 < eventCode <= obj.EVENT_CODE_LIMIT))
fprintf('Warning:\tEvent code exceeds limit (%d)\n\t\tEvent code %03d not sent\n', obj.EVENT_CODE_LIMIT, eventCode);
end
end
end % methods
end
% function value = resetPorts(obj)
%
% if(obj.isPresent)
%
% display('Resetting response and event ports')
%
% DaqDOut(obj.deviceNum, obj.RESP_PORT, obj.RESET_EVENTCODE);
% DaqDOut(obj.deviceNum, obj.EVENT_PORT, obj.RESET_EVENTCODE);
%
%
% else
% value = 'DAQ device not present';
% display(value);
% end
%
% end
%
% function value = sendResponseCode(obj, eventCode)
% % SENDEVENTCODE Sends stimulus/response eventCode out to DAQ device.
% % PORT_WD must be either 'resp' or 'event'
% % CODE must be an integer 0-255
%
% if(obj.isPresent)
%
% value = DaqDOut(obj.deviceNum, obj.RESP_PORT, eventCode);
%
% else
% value = 'DAQ device not present';
% fprintf('%s\n', value);
% end
%
% end
%
% function value = sendCode(obj, port_wd, eventCode)
% % SENDEVENTCODE Sends event/response eventCode out to DAQ device.
% % PORT_WD must be either 'resp' or 'event'
% % CODE must be an integer 0-255
%
% if(obj.isPresent)
%
% switch port_wd
%
% case obj.RESP
%
% value = DaqDOut(obj.deviceNum, obj.RESP_PORT, eventCode);
%
% case obj.EVENT
%
% value = DaqDOut(obj.deviceNum, obj.EVENT_PORT, eventCode);
%
% otherwise
% error('Wrong port specified');
% end
%
% else
% value = 'Error: DAQ device not present';
% fprintf('%s\n Event code %03d not sent\n', value,eventCode);
% end
%
% end
%