gusucode.com > vnt工具箱matlab源码程序 > vnt/vnt/canChannel.m

    function channel = canChannel(varargin)
% canChannel Construct a CAN channel connected to a device.
%
%   CHANNEL = canChannel(...) returns  a channel connected to a given 
%   device channel from a specified vendor. Additional information needed 
%   for canChannel is dependent upon the vendor.
%
%   For CAN devices from Vector and Kvaser, arguments must be specified as follows:
%
%     CHANNEL = canChannel(VENDOR, DEVICE, DEVICECHANNELINDEX)
%
%       VENDOR - Name of the device provider as a string.
%       DEVICE - Device to use as a string that is a combination of the 
%           device type and a device index, such as 'CANCaseXL 1'.
%       DEVICECHANNELINDEX - Numeric channel on the specified device.
%
%   For CAN devices from NI, arguments must be specified as follows:
%
%     CHANNEL = canChannel(VENDOR, DEVICE)
%
%       VENDOR - Name of the device provider as a string.
%       DEVICE - The interface number (such as 'CAN0') defined for the
%           channel in NI Measurement & Automation Explorer.
%
%   For CAN devices from PEAK-System, arguments must be specified as follows:
%
%     CHANNEL = canChannel(VENDOR, DEVICE)
%
%       VENDOR - Name of the device provider as a string.
%       DEVICE - The interface number (such as 'PCAN_USBBUS1') defined for
%           the channel.
%
%   Use canHWInfo to obtain a list of available devices.
%
%   Example: 
%       info = canHWInfo()
%       ch1 = canChannel('Vector', 'CANCaseXL 1', 1)
%       ch2 = canChannel('Kvaser', 'USBcan Professional 1', 1)
%       ch3 = canChannel('NI', 'CAN3')
%       ch4 = canChannel('PEAK-System', 'PCAN_USBBUS1')
%
%   See also VNT. 

% Authors: JDP
% Copyright 2007-2015 The MathWorks, Inc.
% $Revision: 1.1.6.8.4.1 $

% Check the argument count.
narginchk(2,3);

if (exist('can.mathworks.Utility','class')==8)
% Validate the vendor argument.
vendor = validatestring(varargin{1}, ...
    {'Vector', 'Kvaser', 'NI', 'PEAK-System','MathWorks'}, ...
    'canChannel', 'VENDOR');
else
% Validate the vendor argument.
vendor = validatestring(varargin{1}, ...
    {'Vector', 'Kvaser', 'NI', 'PEAK-System'}, ...
    'canChannel', 'VENDOR');
end

% Create a CAN channel based on the requested vendor.
switch vendor
    case 'Vector'
        channel = can.vector.Channel(vendor, varargin{2:end});
        
    case 'Kvaser'
        channel = can.kvaser.Channel(vendor, varargin{2:end});
        
    case 'MathWorks'
        channel = can.mathworks.Channel(vendor, varargin{2:end});        
        
    case 'NI'
        % Validate the device string.
        validateattributes(varargin{2}, {'char'}, ...
            {'nonempty', 'row'}, 'Channel', 'DEVICE', 2);

        channel = can.ni.xnet.Channel(vendor, varargin{2:end});

    case 'PEAK-System'
        channel = can.peaksystem.pcanbasic.Channel(vendor, varargin{2:end});
end

end