Code covered by the BSD License  

Highlights from
MATLAB Support Package for Velleman K8055/VM110 Experiment Board

MATLAB Support Package for Velleman K8055/VM110 Experiment Board

by

 

MATLAB library for communicating with a Velleman K8055/VM110 USB Experiment Interface Board

vellboard.util.CheckMethods
function CheckMethods
% Test script for the Velleman K8055 Experiment Board. Invokes all the
% class's methods with a variety of valid and invalid values and checks
% both functionality and error handling. Will not catch errors relating to
% the hardware interface itself.

%   Copyright 2011 The MathWorks, Inc.

fprintf('\n========================\n')

try
    a = vellboard.ExperimentBoard('test');
catch EXC
    fprintf('\nError in creating ExperimentBoard object\n');
    throw(EXC);
end

fprintf('\n==Misc==\n');
testParams(@a.getActiveDevices,{''},'skip')
testParams(@a.setCurrentDevice,{(0:3)'},{'';' ''dummystr'' ';'[1 1]';1.1;-1;4},{'vellboard:ImproperArguments';'MATLAB:invalidType';'MATLAB:expectedScalar';'MATLAB:expectedInteger';'MATLAB:notGreaterEqual'; 'MATLAB:notLessEqual'})
testParams(@a.version,{''},'skip')

fprintf('\n\n==Analog In==\n');
testParams(@a.readAnalog,{(1:2)'},{'';' ''dummystr'' ';'[1 1]';1.1;0;3},{'vellboard:ImproperArguments';'MATLAB:invalidType';'MATLAB:expectedScalar';'MATLAB:expectedInteger';'MATLAB:notGreaterEqual'; 'MATLAB:notLessEqual'})
testParams(@a.readAnalogAll,{''},'skip')

fprintf('\n\n==Analog Out==\n');
testParams(@a.writeAnalog,{[1,0;2,255]},{'';1;' ''dummystr'',''dummystr'' ';'[1 1],[1 1]',;[1.1 1.1];[0 0];[3 0];[1 -1];[1,257]},{'vellboard:ImproperArguments';'vellboard:ImproperArguments';'MATLAB:invalidType';'MATLAB:expectedScalar';'MATLAB:expectedInteger';'MATLAB:notGreaterEqual'; 'MATLAB:notLessEqual';'MATLAB:notGreaterEqual'; 'MATLAB:notLessEqual'})
testParams(@a.writeAnalogAll,{'[0 0]';'[255 255]'},{'';' ''dummystr'' ';1;'[1.1 1.1]';'[-1,-1]';'[257,257]'},{'vellboard:ImproperArguments';'MATLAB:invalidType';'MATLAB:incorrectSize';'MATLAB:expectedInteger';'MATLAB:notGreaterEqual'; 'MATLAB:notLessEqual'})

fprintf('\n\n==Digital In==\n');
testParams(@a.readDigital,{(1:5)'},{'';' ''dummystr'' ';'[1 1]';1.1;0;6},{'vellboard:ImproperArguments';'MATLAB:invalidType';'MATLAB:expectedScalar';'MATLAB:expectedInteger';'MATLAB:notGreaterEqual'; 'MATLAB:notLessEqual'})
testParams(@a.readDigitalAll,{''},'skip')

fprintf('\n\n==Digital Out==\n');
testParams(@a.writeDigital,{[1,0;2,1]},{'';1;' ''dummystr'',''dummystr'' ';'[1 1],[1 1]',;[1.1 .1];[0 -1];[9 2];[1 2]},{'vellboard:ImproperArguments';'vellboard:ImproperArguments';'MATLAB:invalidType';'MATLAB:expectedScalar';'MATLAB:expectedInteger';'MATLAB:notGreaterEqual'; 'MATLAB:notLessEqual';'MATLAB:expectedBinary'})
testParams(@a.writeDigitalAll,{'[0 0 0 0 0 0 0 0]';'[1 1 1 1 1 1 1 1]'},{'';' ''dummystr'' ';1;'[2 2 2 2 2 2 2 2]'},{'vellboard:ImproperArguments';'MATLAB:invalidType';'MATLAB:incorrectSize';'MATLAB:expectedBinary'})

fprintf('\n\n==Counters==\n');
testParams(@a.readCounter,{(1:2)'},{'';' ''dummystr'' ';'[1 1]';1.1;0;3},{'vellboard:ImproperArguments';'MATLAB:invalidType';'MATLAB:expectedScalar';'MATLAB:expectedInteger';'MATLAB:notGreaterEqual'; 'MATLAB:notLessEqual'})
testParams(@a.readCounterAll,{''},'skip')
testParams(@a.resetCounter,{(1:2)'},{'';' ''dummystr'' ';'[1 1]';1.1;0;3},{'vellboard:ImproperArguments';'MATLAB:invalidType';'MATLAB:expectedScalar';'MATLAB:expectedInteger';'MATLAB:notGreaterEqual'; 'MATLAB:notLessEqual'})
testParams(@a.setCounterDebounceTime,{[1,0;2,5000]},{'';1;' ''dummystr'',''dummystr'' ';'[1 1],[1 1]',;[1.1 1.1];[0 0];[3 0];[1 -1];[1,5001]},{'vellboard:ImproperArguments';'vellboard:ImproperArguments';'MATLAB:invalidType';'MATLAB:expectedScalar';'MATLAB:expectedInteger';'MATLAB:notGreaterEqual'; 'MATLAB:notLessEqual';'MATLAB:notGreaterEqual'; 'MATLAB:notLessEqual'})

fprintf('\n')

try
    delete(a);
catch EXC
    fprintf('\nError in deleting ExperimentBoard object\n');
    throw(EXC);
end

fprintf('\n========================\n')
end




% Tests the provided function with the provided arguments and outputs a
% message if there's an error. Can take scalars or complete set of
% arguments formmatted as a string.
% Not for user consumption
function testParams(funchandle,pterms,nterms,nexception)
if ~(isa(pterms,'char') && strcmp(pterms,'skip'))
    for i = 1:size(pterms,1)
        for r = 1:size(pterms{i},1)
            if isnumeric(pterms{i}(1))
                evalstr = ['funchandle(' num2str(pterms{i}(r,1))];
                for c = 2:size(pterms{i},2)
                    evalstr = [evalstr ',' num2str(pterms{i}(r,c))]; %#ok<*AGROW>
                end
                evalstr = [evalstr ');'];
            else
                evalstr = ['funchandle(' pterms{i} ');'];
            end
            
            try
                eval(evalstr);
            catch EXC
                fprintf('Execution of "%s" failed for argument %s with exception ID %s!\n',func2str(funchandle),num2str(pterms{i}(r,:)),EXC.identifier)
            end
        end
    end
end

if ~(isa(nterms,'char') && strcmp(nterms,'skip'))
    for i = 1:size(nterms,1)
        for r = 1:size(nterms{i},1)
            state = 0;
            if isnumeric(nterms{i}(1))
                evalstr = ['funchandle(' num2str(nterms{i}(r,1))];
                for c = 2:size(nterms{i},2)
                    evalstr = [evalstr ',' num2str(nterms{i}(r,c))];
                end
                evalstr = [evalstr ');'];
            else
                evalstr = ['funchandle(' nterms{i} ');'];
            end
            
            try
                eval(evalstr);
            catch EXC
                state = state + 1;
                if strcmp(EXC.identifier,nexception{i});
                    state = state + 1;
                end
            end
            switch(state)
                case 0
                    fprintf('"%s" failed to catch error for argument %s!\n',func2str(funchandle),num2str(nterms{i}(r,:)))
                case 1
                    fprintf('"%s" failed with an unincluded error %s for argument %s!\n',func2str(funchandle),EXC.identifier,num2str(nterms{i}(r,:)))
            end
        end
    end
end
end

Contact us