gusucode.com > vnt工具箱matlab源码程序 > vnt/vnt/+can/HardwareInfo.m

    classdef HardwareInfo < hgsetget
% HardwareInfo Retrieve information on available CAN devices.
%
%   This class is the top level storage class for Vehicle
%   Network Toolbox and available CAN device information. It contains
%   basic information about the toolbox with child classes storing 
%   information about CAN devices.
%
%   See also VNT.

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

properties (SetAccess = 'private')
    % ToolboxName - The full name of the MATLAB toolbox.
    ToolboxName
    % ToolboxVersion - The currently installed version of the toolbox.
    ToolboxVersion
    % MATLABVersion - The currently installed version of MATLAB.
    MATLABVersion
    % VendorInfo - Stores information on supported CAN device vendors.
    VendorInfo
end


methods
    
    function obj = HardwareInfo()
    % HardwareInfo Construct an object containing CAN device information.
        
        % Set the toolbox name and version.
        [obj.ToolboxName, obj.ToolboxVersion] = can.HardwareInfo.getVersionInfo('vnt');
        
        % Set MATLAB version.
        [~, obj.MATLABVersion] = can.HardwareInfo.getVersionInfo('matlab');
        
        % Initialize VendorInfo as empty.
        obj.VendorInfo = can.VendorInfo.empty();
        
        % Check for the presence of Kvaser drivers/devices.
        if can.kvaser.Utility.isDriverAvailable()
            % Create the vendor child class for Kvaser.
            obj.VendorInfo(end + 1) = can.kvaser.VendorInfo();
        end
        
        if can.ni.xnet.Utility.isDriverAvailable()
            % Create the vendor child class for NI-XNET.
            obj.VendorInfo(end + 1) = can.ni.xnet.VendorInfo();
        end
            
        % Check for the presence of Vector drivers/devices.
        if can.vector.Utility.isDriverAvailable()
            % Create the vendor child class for Vector.
            obj.VendorInfo(end + 1) = can.vector.VendorInfo();
        end
        
        % Check for the presence of PEAK-System drivers/devices.
        if can.peaksystem.pcanbasic.Utility.isDriverAvailable()
            % Create the vendor child class for PEAK-System.
            obj.VendorInfo(end + 1) = can.peaksystem.pcanbasic.VendorInfo();
        end
        
        if (exist('can.mathworks.Utility','class')==8)
        % Check for the presence of MathWorks Virtual drivers/devices.
        if can.mathworks.Utility.isDriverAvailable()
            % Create the vendor child class for Mathworks Virtual CAN device.
            obj.VendorInfo(end + 1) = can.mathworks.VendorInfo();
        end
        end
        
    end
    
    function disp(obj)
    % disp Display array.
        
        % Check the number of vendors found.
        if isempty(obj.VendorInfo)
            % Display a not found message for no vendors.
            fprintf(1, 'No CAN devices detected.\n\n');

            % Display the support package installer trip wire.
            if feature('hotlinks')
                fprintf(1, ['Use the ' ...
                    '<a href="matlab: hwconnectinstaller.launchInstaller(''BaseProduct'', ''Vehicle Network Toolbox'', ''StartAtStep'', ''SelectPackage'')">' ...
                    'Support Package Installer</a> to install drivers for additional Vehicle Network Toolbox third-party devices.\n\n']);
            end
            return;
        end
        
        % Display a header.
        fprintf(1, 'CAN Devices Detected\n\n');
        
        % Make a display table for device information.
        canHWInfoTable = internal.DispTable();
        canHWInfoTable.Indent = 2;
        canHWInfoTable.ColumnSeparator = ' | ';
        canHWInfoTable.addColumn('Vendor');
        canHWInfoTable.addColumn('Device');
        canHWInfoTable.addColumn('Channel');
        canHWInfoTable.addColumn('Serial Number');
        canHWInfoTable.addColumn('Constructor');
        
        % Loop through each vendor.
        for vendorIndex = 1:numel(obj.VendorInfo)
            % Loop through the channels for each vendor.
            for channelIndex = 1:numel(obj.VendorInfo(vendorIndex).ChannelInfo)
                % The display values are specific to a given vendor.
                switch obj.VendorInfo(vendorIndex).VendorName
                    case {'Vector', 'Kvaser','MathWorks'}
                        canHWInfoTable.addRow( ...
                            obj.VendorInfo(vendorIndex).VendorName, ...
                            obj.VendorInfo(vendorIndex).ChannelInfo(channelIndex).Device, ...
                            num2str(obj.VendorInfo(vendorIndex).ChannelInfo(channelIndex).DeviceChannelIndex), ...
                            obj.VendorInfo(vendorIndex).ChannelInfo(channelIndex).DeviceSerialNumber, ...
                            obj.VendorInfo(vendorIndex).ChannelInfo(channelIndex).ObjectConstructor);
                        
                    case {'NI', 'PEAK-System'}
                        canHWInfoTable.addRow( ...
                            obj.VendorInfo(vendorIndex).VendorName, ...
                            [obj.VendorInfo(vendorIndex).ChannelInfo(channelIndex).DeviceType ...
                            ' (' obj.VendorInfo(vendorIndex).ChannelInfo(channelIndex).Device ')'], ...
                            num2str(obj.VendorInfo(vendorIndex).ChannelInfo(channelIndex).DeviceChannelIndex), ...
                            obj.VendorInfo(vendorIndex).ChannelInfo(channelIndex).DeviceSerialNumber, ...
                            obj.VendorInfo(vendorIndex).ChannelInfo(channelIndex).ObjectConstructor);
                end
            end
        end
        
        % Show the table on the screen.
        disp(canHWInfoTable);
        
        % Display a general statement directing the user to use
        % get for additional information.
        fprintf(1, '\nUse GET on the output of canHWInfo for more information.\n\n');
        
        % Display the support package installer trip wire.
        if feature('hotlinks')
            fprintf(1, ['Use the ' ...
                '<a href="matlab: hwconnectinstaller.launchInstaller(''BaseProduct'', ''Vehicle Network Toolbox'', ''StartAtStep'', ''SelectPackage'')">' ...
                'Support Package Installer</a> to install drivers for additional Vehicle Network Toolbox third-party devices.\n\n']);
        end
    end
    
end


methods (Static, Access = 'private')
    
    function [versionName, versionString] = getVersionInfo(product)
    % getVersionInfo Output version information.
    %
    %   Inputs:
    %       PRODUCT - The lookup string name of the product.
    %
    %   Outputs:
    %       VERSIONNAME - The name of the PRODUCT returned from VER.
    %       VERSIONSTRING - The version number of the PRODUCT returned from VER.
        
        try
            if isdeployed()
                % When deployed, show versions as not available.
                versionName = 'Not Available';
                versionString = 'Not Available';
            else
                % Get the version information data.
                versionInfo = ver(product);
                % Set the version strings.
                versionName = versionInfo.Name;
                versionString = [versionInfo.Version ' ' versionInfo.Release];
            end
            
        catch err %#ok<NASGU>
            % Return blank strings on error.
            versionName = '';
            versionString = '';
        end
    end
    
end
    
end