-
Notifications
You must be signed in to change notification settings - Fork 16
/
addRigboxPaths.m
183 lines (161 loc) · 7.78 KB
/
addRigboxPaths.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
174
175
176
177
178
179
180
181
182
183
function addRigboxPaths(varargin)
%ADDRIGBOXPATHS Adds the required paths for using Rigbox
% addRigboxPaths([savePaths, strict]) or
% addRigboxPaths('SavePaths', true, 'Strict', true)
%
% Inputs (Optional):
% savePaths (logical): If true, added paths are saved between sessions
% strict (logical): Assert toolbox & system requirements are all met
%
% Part of the Rigging toolbox
%
% 2014-01 CB
% 2017-02 MW Updated to work with 2016b
%%% Input validation %%%
% Allow positional or Name-Value pairs
p = inputParser;
p.addOptional('savePaths', true)
p.addOptional('strict', true)
p.parse(varargin{:});
p = p.Results;
%%% MATLAB version and toolbox validation %%%
sys32 = dir('C:\Windows\System32');
toolboxes = ver;
% Check that the Psychophysics Toolbox is installed (required for the
% stimulus computer only)
isInstalled = strcmp('Psychtoolbox', {toolboxes.Name});
if ~any(isInstalled) || str2double(toolboxes(isInstalled).Version(1)) < 3
warning('Rigbox:setup:toolboxRequired',...
['Could not find Psychtoolbox in MATLAB''s installed toolboxes. The'...
' stimulus computer requires Psychtoolbox v3.0 or higher to be'...
' installed. Click <a href="matlab:web(''%s'',''-browser'')">here</a>'...
' for installation instructions.'],...
'http://psychtoolbox.org/download.html#Windows');
end
if p.strict
% MATLAB must be running on Windows
assert(ispc, 'Rigbox currently only works on Windows 10')
% Microsoft Visual C++ Redistributable for Visual Studio 2015 must be
% installed, check for runtime dll file in system32 folder
assert(any(strcmpi('VCRuntime140.dll',{sys32.name})),...
'Rigbox:setup:libraryRequired',...
['Requires Microsoft Visual C++ Redistributable for Visual Studio'...
' 2015. Click <a href="matlab:web(''%s'',''-browser'')">here</a> to'...
' install.'],...
'https://www.microsoft.com/en-us/download/details.aspx?id=48145')
% Microsoft Visual C++ Redistributable for Visual Studio 2013 must be
% installed, check for runtime dll file in system32 folder
assert(any(strcmpi('msvcr120.dll',{sys32.name})),...
'Rigbox:setup:libraryRequired',...
['Requires Microsoft Visual C++ Redistributable for Visual Studio'...
' 2013. Click <a href="matlab:web(''%s'',''-browser'')">here</a> to'...
' install.'],...
'https://www.microsoft.com/en-us/download/details.aspx?id=40784')
% Check MATLAB 2018b is running
assert(~verLessThan('matlab', '9.5'), 'Requires MATLAB 2018b or later')
% Check essential toolboxes are installed (common to both master and
% stimulus computers)
requiredMissing =...
setdiff({'Data Acquisition Toolbox'},{toolboxes.Name});
assert(isempty(requiredMissing),'Rigbox:setup:toolboxRequired',...
'Please install the following MATLAB toolboxes before proceeding:\n%s',...
strjoin(requiredMissing, '\n'))
% Check that GUI Layout Toolbox is installed (required for the master
% computer only)
isInstalled = strcmp('GUI Layout Toolbox', {toolboxes.Name});
if ~any(isInstalled) ||...
str2double(erase(toolboxes(isInstalled).Version,'.')) < 230
warning('Rigbox:setup:toolboxRequired',...
['MC requires GUI Layout Toolbox v2.3 or higher to be installed.'...
' Click <a href="matlab:web(''%s'',''-browser'')">here</a> to' ...
' install.'], ['https://uk.mathworks.com/matlabcentral/fileexchange'...
'/47982-gui-layout-toolbox'])
end
% Check that the NI DAQ support package is installed (required for the
% stimulus computer only)
info = matlabshared.supportpkg.getInstalled;
if isempty(info) || ~any(contains({info.Name}, 'NI-DAQmx'))
warning('Rigbox:setup:toolboxRequired',...
['To run full experiments, the stimulus computer requires'...
' the National Instruments support package to be installed.'...
' Click <a href="matlab:web(''%s'',''-browser'')">here</a> to'...
'install.'],...
'https://www.mathworks.com/hardware-support/nidaqmx.html')
end
end
%%% Add paths %%%
% Add the main Rigbox directory, containing the main packages for running
% the experiment server and mc
root = fileparts(mfilename('fullpath'));
addpath(root);
% The cb-tools directory contains numerious convenience functions which are
% utilized by the main code. Those within the 'burgbox' directory were
% written by Chris Burgess.
addpath(fullfile(root, 'cb-tools'), fullfile(root, 'cb-tools', 'burgbox'));
% Add CortexLab paths. These are mostly extra classes that allow Rigbox to
% work with other software developed by CortexLab, including MPEP.
addpath(fullfile(root, 'cortexlab'));
% Add wheelAnalysis paths. This is a package for computing wheel velocity,
% classifying movements, etc.
addpath(fullfile(root, 'wheelAnalysis'), ...
fullfile(root, 'wheelAnalysis', 'helpers'));
% Add signals paths, this includes all the core code for running signals
% experiments. This submodule is maintained by Chris Burgess.
addpath(fullfile(root, 'signals'),...
fullfile(root, 'signals', 'mexnet'),...
fullfile(root, 'signals', 'util'));
% Add the Java paths for signals.
jcp = fullfile(root, 'signals', 'java');
if ~any(strcmp(javaclasspath, jcp)); javaaddpath(jcp); end
% Add the paths for Alyx-matlab. This submodule allows one to interact
% with an instance of an Alyx database. For more information please visit:
% http://alyx.readthedocs.io/en/latest/
addpath(fullfile(root, 'alyx-matlab'), fullfile(root, 'alyx-matlab', 'helpers'));
% Add paths for the npy-matlab. This submodule is maintained by the
% Kwik Team (https://github.com/kwikteam). It allows for the saving of
% NumPy binary files. Used by Rigbox to save data as .npy files with the
% ALF (ALex File) naming convention. For more information please visit:
% https://docs.scipy.org/doc/numpy-dev/neps/npy-format.html
addpath(fullfile(root, 'npy-matlab', 'npy-matlab'));
% Add the Java paths for Java WebSockets used for communications between
% the stimulus computer and the master computer
cbtoolsjavapath = fullfile(root, 'cb-tools', 'java');
javaclasspathfile = fullfile(prefdir, 'javaclasspath.txt');
fid = fopen(javaclasspathfile, 'a+');
fseek(fid, 0, 'bof');
closeFile = onCleanup( @() fclose(fid) );
javaclasspaths = first(textscan(fid,'%s', 'CommentStyle', '#', 'Delimiter',''));
cbtoolsInJavaPath = any(strcmpi(javaclasspaths, cbtoolsjavapath));
%%% Remind user to copy paths file %%%
if ~exist('+dat/paths','file')
template_paths = fullfile(root, 'docs', 'scripts', 'paths_template.m');
new_loc = fullfile(root, '+dat', 'paths.m');
copied = copyfile(template_paths, new_loc);
% Check that the file was copied
if ~copied
warning('Rigbox:setup:copyPaths', 'Please copy the file ''%s'' to ''%s''.',...
template_paths, new_loc);
end
end
%%% Validate that paths saved correctly %%%
if p.savePaths
assert(savepath == 0, 'Failed to save changes to MATLAB path');
if ~cbtoolsInJavaPath
fseek(fid, 0, 'eof');
n = fprintf(fid, '\n#path to CB-tools java classes\n%s', cbtoolsjavapath);
assert(n > 0, 'Could not write to ''%s''', javaclasspathfile);
warning('Rigbox:setup:restartNeeded',...
'Updated Java classpath, please restart MATLAB');
end
elseif ~cbtoolsInJavaPath
warning('Rigbox:setup:javaNotSetup',...
'Cannot use java classes without saving new classpath');
end
fprintf(... %#ok<*LTARG>
['\nAfter restarting MATLAB, navigate to the \n'...
'`Rigbox/docs/signals/docs/examples` folder, and run the command: \n'...
'`eui.SignalsTest(''signalsPong'')` in MATLAB. If Rigbox \n'...
'installation and paths set-up was successful, this command should \n'...
'launch a GUI to play the game of pong in Signals, where the player \n'...
'paddle can be controlled via the mouse.\n']);
end