% vellscope.setup
% Setup function for the MATLAB Support Package for Velleman PCSGU250.
% Run this before trying any other functions in vellscope. Installs the
% PCSGU250 SDK, does some necessary modifications to its file structure,
% and adds the package to the MATLAB search path so it is accessable
% anywhere.
% MATLAB Support Package for Velleman PCSGU250
% Version 1.0
% Copyright 2011 The MathWorks, Inc.
function setup
packageParentDir = fileparts(fileparts(mfilename('fullpath')));
defaultVellemanDir = fullfile(getenv('SYSTEMDRIVE'), 'Velleman');
mainpageUrl = 'http://www.vellemanusa.com/us/enu/product/view/?id=524708';
pcsgu250Url = 'http://www.vellemanusa.com/downloads/files/downloads/pcsgu250_dll_rev1.zip';
choice = questdlg({'You need the Software Development Kit for PCSGU250', ['(from ' mainpageUrl ')']}, ...
'SDK for PCSGU250', 'Download and Install', 'Skip this step', 'Cancel', 'Download and Install');
switch choice
case 'Download and Install'
if ~exist(defaultVellemanDir', 'dir')
mkdir(defaultVellemanDir);
end
zipFile = fullfile(defaultVellemanDir, 'pcsgu250_dll_rev1.zip');
h = waitbar(0.25, 'Downloading the SDK (~ 2.5 MB) ...');
try
urlwrite(pcsgu250Url, zipFile);
catch
delete(h)
error('vellscope:DownloadFailed',['Unable to download the SDK. Check your internet connection.' char(10)...
'If you are connected to the internet and still see this error,' char(10)...
'see README.pdf for troubleshooting information.']);
end
waitbar(0.75, h, 'Unzipping the SDK ...');
try
unzip(zipFile, defaultVellemanDir);
catch
delete(h);
error('vellscope:UnzipFailed',['Unable to unzip the SDK' char(10)...
'See README.pdf for troubleshooting instructions.']);
end
delete(h);
SDKDir = fullfile(defaultVellemanDir, 'PCSGU250_DLL');
fprintf('# Installed Velleman Software Development Kit (SDK) to %s\n', SDKDir);
case 'Skip this step'
if ispref('vellscope', 'SDKDir')
SDKDir = getpref('vellscope', 'SDKDir');
isOK = vellscope.Prefs.checkSDKDirectory(SDKDir);
if isOK,
fprintf('# Found existing Velleman PCSGU250 Software Development Kit (SDK): %s\n', SDKDir);
getDirFromUser = false;
else
getDirFromUser = true;
end
else
getDirFromUser = true;
end
if getDirFromUser
SDKDir = uigetdir(getenv('SYSTEMDRIVE'), 'Specify the "PCSGU250_DLL" folder that contains Velleman PCSGU250 Software Development Kit');
[isOK,msg] = vellscope.Prefs.checkSDKDirectory(SDKDir);
if isOK
fprintf('# Setting Velleman Software Development Kit (SDK) directory to %s\n', SDKDir);
else
error(msg);
end
end
case 'Cancel'
fprintf('# Cancelling Velleman package setup\n');
return;
end
% At this point, SDKDir should be a valid (& verified) location
%% save the directory
pref = vellscope.Prefs;
pref.SDKDir = SDKDir;
fprintf('# Added Velleman package to MATLAB path\n');
%% add package to MATLAB path
addpath(packageParentDir);
result = savepath;
if result==1
nl = char(10);
msg = ['# Unable to save updated MATLAB path (<a href="http://www.mathworks.com/support/solutions/en/data/1-9574H9/index.html?solution=1-9574H9">why?</a>)' nl ...
' To save the path, you can: ' nl ...
' 1) Exit MATLAB ' nl ...
' 2) Right-click the MATLAB icon and select "Run as administrator" ' nl ...
' 3) Re-run vellscope.setup ' nl ...
];
disp(msg);
else
fprintf('# Added ''%s'' to MATLAB path\n', packageParentDir);
end
nl = char(10);
msg = ['You can now navigate to any other directory and use the Velleman package. ' nl ...
'See <a href="matlab:edit(''+vellscope/example1.m'')">this example</a> to get started' nl ...
];
disp(msg);
end