forked from JorritMontijn/MNCP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
InitSGL.m
66 lines (57 loc) · 1.71 KB
/
InitSGL.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
function [hSGL,strRunName,sParamsSGL] = InitSGL(strRecording,strOutputFile)
%InitSGL Initializes SGL
% [hSGL,strRunName,sParamsSGL] = InitSGL(strRecording,strOutputFile)
% Create connection (edit the IP address)
hSGL = SpikeGL('127.0.0.1');
%retrieve channels to save
warning('off','CalinsNetMex:connectionClosed');
vecSaveChans = GetSaveChans(hSGL, 0);
warning('on','CalinsNetMex:connectionClosed');
if ~IsSaving(hSGL)
%set run name
intBlock = 0;
boolAccepted = false;
while ~boolAccepted
intBlock = intBlock + 1;
strRunName = strcat(strOutputFile,sprintf('R%02d',intBlock));
try
SetRunName(hSGL, strRunName);
boolAccepted = true;
catch
boolAccepted = false;
end
if intBlock > 99
error([mfilename ':NameNotAccepted'],'Run names are not accepted... Something is wrong');
end
end
else
intBlock = 1;
strRunName = strcat(strOutputFile,sprintf('R%02d',intBlock));
end
%set meta data, can be anything, as long as it's a numeric scalar or string
sMeta = struct();
strTime = strrep(getTime,':','_');
strRunName = strcat(strRunName,'_',strTime);
strMetaField = sprintf('recording_%s',strTime);
sMeta.(strMetaField) = strRecording;
SetMetaData(hSGL, sMeta);
%get parameters for this run
sParamsSGL = GetParams(hSGL);
%set stream IDs
vecStreamIM = [0];
intStreamNI = -1;
%get probe ID
[cellSN,vecType] = GetImProbeSN(hSGL, vecStreamIM(1));
sParamsSGL.cellSN = cellSN;
%start recording if not already recording
if ~IsSaving(hSGL)
SetRecordingEnable(hSGL, 1);
end
hTicStart = tic;
%check if output is being saved
while ~IsSaving(hSGL) && toc(hTicStart) < 1
pause(0.01);
end
if ~IsSaving(hSGL)
error([mfilename ':NotSaving'],'Data is not being saved!')
end