%This function opens the CAN channel if not yet open.  Stores result in the
%base workspace for convenience. So the return value from this function or
%canch1 in the base workspace can be used subsequently.

function [canch] = OpenCANChannel()

if(ismember('canch1',evalin('base','who')) == 0)
 canch1 = canChannel('PEAK-System', 'PCAN_USBBUS1');
 configBusSpeed(canch1, 125000);
 %configBusSpeed(canch1, 500000);
 start(canch1)
 assignin('base','canch1',canch1);
end

canch = evalin('base','canch1');


end