1
function [status error] = NetStation(varargin)
1
function [status, error] = NetStation(varargin)
3
3
% NetStation - Basic control of the EGI/NetStation EEG recording system via
4
4
% TCP/IP network connection. (See http://www.egi.com)
6
6
% This function was developed and contributed to Psychtoolbox by Gergely Csibra, 2006-2008.
7
7
% Code is based on Rick Gilmore's routines, 2005. Thanks!
8
8
% Code adapted to PCs (and Macs with Intel architecture) by Zhao Fan, 2008.
9
% This function was modified by Matt Mollison to accommodate sending more
10
% than just int16s to Net Station (logical, int8, int16, int32, single,
52
55
% "duration" The duration of the event IN SECONDS.
54
57
% "keycode" The 4-char code of a key (e.g., 'tria').
55
% "keyvalue" The integer value of the key (>=-32767 <=32767)
58
% "keyvalue" The value of the key (any number or string)
56
59
% The keycode-keyvalue pairs can be repeated arbitrary times.
58
61
% Uses a modified version of the TCP/UDP/IP Toolbox 2.0.5, a third party GPL'ed
168
if n>=100 warning('\nNetStation synchronization did not succeed within %.1f ms\nSynchronizatoin accuracy is %.1f ms\n',NSSynchLimit,df); end
172
warning('\nNetStation synchronization did not succeed within %.1f ms\nSynchronizatoin accuracy is %.1f ms\n',NSSynchLimit,df);
169
174
%fprintf('synch: %.1f ms at the %ith attempt\n',df,n-1);
171
176
case 'startrecording'
228
send(NSIDENTIFIER,'D',uint16(15+keyn*12),int32(start*1000),uint32(duration*1000),event(1:4),int16(0),uint8(keyn));
230
id=[char(varargin{(k-1)*2+5}) ' '];
231
val=int16(varargin{k*2+4});
232
send(NSIDENTIFIER,id(1:4),'shor',uint16(2),val(1));
236
% Net Staiton GES Hardware Technical Manual Appendix G
237
val = cell2mat(varargin((k * 2) + 4));
239
% I don't understand it, but these 10 extra bytes need
243
if isa(val,'logical')
244
% will convert to int8 because NS expects 1-byte
245
% booleans but reads as int8
246
nbytes = 1 + extraBytes;
247
elseif isa(val,'int8')
248
% will convert to int16 because NS expects 2-byte
249
% short signed integers and you should use logical
250
% true/false if you meant to have boolean data
251
nbytes = 2 + extraBytes;
252
elseif isa(val,'int16')
253
nbytes = 2 + extraBytes;
254
elseif isa(val,'int32')
255
nbytes = 4 + extraBytes;
256
elseif isa(val,'single')
257
nbytes = 4 + extraBytes;
258
elseif isa(val,'double')
259
nbytes = 8 + extraBytes;
260
elseif isa(val,'char')
261
% strings get sent as single-byte characters, as
262
% explained in pnet.m
263
nbytes = length(val) + extraBytes;
265
nbytes_total = nbytes_total + nbytes;
267
send(NSIDENTIFIER,'D',uint16(15 + nbytes_total),int32(start*1000),uint32(duration*1000),event(1:4),int16(0),uint8(keyn));
270
id=[char(varargin{(k-1)*2+5}), ' '];
272
% Net Staiton GES Hardware Technical Manual Appendix G
273
val = cell2mat(varargin((k * 2) + 4));
275
if isa(val,'logical')
279
elseif isa(val,'int8')
283
elseif isa(val,'int16')
286
elseif isa(val,'int32')
289
elseif isa(val,'single')
292
elseif isa(val,'double')
295
elseif isa(val,'char')
297
nbytes = length(val);
299
send(NSIDENTIFIER,id(1:4),dtype,uint16(nbytes),val);
235
302
rep=receive(NSIDENTIFIER,1); %#ok<NASGU>