www.gusucode.com > vnt工具箱matlab源码程序 > vnt/vnt/canSupport.m
function canSupport() % canSupport Vehicle Network Toolbox troubleshooting utility. % % canSupport() returns diagnostic information for all installed hardware % devices and saves output to the text file 'cansupport.txt' in the % current working directory. % % Examples: % canSupport() % Authors: JDP % Copyright 2007-2015 The MathWorks, Inc. % Set the output filename. filename = 'cansupport.txt'; % Delete the output file if one already exists. if (~isempty(dir(filename))) try delete(filename); catch err error(message('vnt:canSupport:UnableToDeleteFile')); end end % Open the file for writing. fid = fopen(filename, 'w'); % Error if the file was unable to be opened. if (fid == -1) error(message('vnt:canSupport:UnableToOpenFile')); end % Set an onCleanup function for the file to close it on completion % or error. c = onCleanup(@() fclose(fid)); % Variables cr and sp represent strings that are repeatedly used. cr = sprintf('\n'); sp = '----------'; % Display a status message to the command window. disp('Generating diagnostic information ...'); % Write the MATLAB, OS, and Toolbox version information. if isdeployed() fprintf(fid, 'Toolbox version info is not available in deployed applications.\n'); else fprintf(fid, evalc('ver(''vnt'')')); end % Retrieve and write the hardware information. try hwInfo = canHWInfo; canHWInfoStr = evalc('disp(hwInfo)'); catch err %#ok<NASGU> canHWInfoStr = 'Retrieval of CAN hardware information failed.'; end fprintf(fid, [cr, sp, ' AVAILABLE HARDWARE ', sp, cr, cr, '%s'], canHWInfoStr); canHWInfoGetStr = evalc('get(hwInfo)'); fprintf(fid, [cr, '%s'], canHWInfoGetStr); % Write the CAN vendor and channel information. for vendorCount = 1:numel(hwInfo.VendorInfo) % Write the vendor header. fprintf(fid, [cr, sp,' %s DEVICES ', sp, cr, cr], upper(hwInfo.VendorInfo(vendorCount).VendorName)); % Get the driver data information. fprintf(fid, ['DRIVER INFORMATION:', cr]); switch hwInfo.VendorInfo(vendorCount).VendorName case 'Vector' [~, driverData] = can.vector.XLDriverLibrary.xlGetDriverConfig(); for ii = 1:numel(driverData) fprintf(fid, '%s', evalc('driverData(ii)')); fprintf(fid, ['ChannelMask: 0b%s', cr],... dec2bin(driverData(ii).channelMask)); fprintf(fid, ['ChannelBusCapabilities: 0b%s 0x%s', cr],... dec2bin(driverData(ii).channelBusCapabilities),... dec2hex(driverData(ii).channelBusCapabilities)); fprintf(fid, ['DriverVersion: 0x%s', cr], dec2hex(driverData(ii).driverVersion)); end case 'Kvaser' channelCount = can.kvaser.CANLib.canGetNumberOfChannels(); for ii = 0:(channelCount - 1) driverData = can.kvaser.CANLib.canGetChannelData(ii); %#ok<NASGU> fprintf(fid, '%s', evalc('driverData')); end case 'NI' channelCount = can.ni.xnet.Utility.getAllChannelInfo(); for ii = 1:numel(channelCount) fprintf(fid, '%s', evalc('channelCount(ii)')); end case 'PEAK-System' channelCount = can.peaksystem.pcanbasic.Utility.getAllChannelInfo(); for ii = 1:numel(channelCount) fprintf(fid, '%s', evalc('channelCount(ii)')); end end % Write the vendor information. fprintf(fid, [cr, 'VENDOR INFORMATION: ']); canVendorInfoStr = evalc('get(hwInfo.VendorInfo(vendorCount))'); fprintf(fid, [cr, cr, '%s'], canVendorInfoStr); % Write the channel header. fprintf(fid, ['AVAILABLE CHANNELS: ', cr, cr]); % Write the channel information. for channelCount = 1:numel(hwInfo.VendorInfo(vendorCount).ChannelInfo) canChannelInfoStr = evalc('get(hwInfo.VendorInfo(vendorCount).ChannelInfo(channelCount))'); fprintf(fid, '%s', canChannelInfoStr); end % Write a header for channel creation for each vendor. fprintf(fid, [cr, cr, sp,' CAN CHANNEL OBJECT CREATION - ',... upper(hwInfo.VendorInfo(vendorCount).VendorName), ' ', sp, cr, cr]); % Loop through the channel count and create CAN channel objects for each % channel for each vendor. for channelCount = 1:numel(hwInfo.VendorInfo(vendorCount).ChannelInfo) % Obtain the constructor for the channel. constructorStr = [hwInfo.VendorInfo(vendorCount).ChannelInfo(channelCount).ObjectConstructor]; % Connect to the channel and write the result. try % Connect and write status. evalc(['canCh = ', constructorStr]); fprintf(fid, ['%s', ' -- SUCCEEDED', cr, cr], constructorStr); % Disp the connection and write the result. canChInfoStr = evalc('disp(canCh)'); fprintf(fid, canChInfoStr); % Get the properties of the connection and write the result. canChInfoStr = evalc('get(canCh)'); fprintf(fid, [canChInfoStr, cr, cr]); catch err % Write as failed on error. fprintf(fid, ['%s', ' -- FAILED', cr, cr, err.identifier, cr, err.message], constructorStr); fprintf(fid, [cr, cr, cr, cr]); end end % Channel loop. end % Vendor loop. % Write MATLABROOT directory. if isdeployed mlRoot = ctfroot; else mlRoot = matlabroot; end fprintf(fid, [cr, sp, ' MATLAB ROOT DIRECTORY ', sp, cr, cr, '%s', cr], mlRoot); % Write MATLAB path. fprintf(fid, [cr, sp, ' MATLAB PATH ', sp, cr, '%s'], evalc('path')); % Write memory information. fprintf(fid, [cr, sp, ' MATLAB MEMORY STATE ', sp, cr, cr, '%s'], evalc('memory')); % Write file footer. fprintf(fid, [cr, sp, sp,' END TEST ', sp, sp, cr]); fprintf(fid, [cr, 'This information has been saved in the text file: ', cr, ... '%s', cr], filename); fprintf(fid, [cr, 'If any errors occurred, please submit a technical support request at:', cr, ... 'http://www.mathworks.com/contact_TS.html', cr]); % Display text output to user. if ~isdeployed() edit(filename) end end