gusucode.com > vnt工具箱matlab源码程序 > vnt/vnt/+can/+vector/Utility.m
classdef (Hidden) Utility % Utility Supporting functionality for toolbox operations. % % This class implements internal functionality required for toolbox % operation. These methods are not intended for external use. % Methods contained here are applicable to Vector devices only. % Authors: JDP % Copyright 2007-2014 The MathWorks, Inc. properties (Constant, GetAccess = 'private') % SupportedDeviceStrings - Lists the names of all Vector device % types supported by the toolbox. SupportedDeviceStrings = { ... 'Virtual', ... 'CANcardX', ... 'CANcardXL', ... 'CANcaseXL', ... 'CANboardXL_PCIe', ... 'CANboardXL_PXI', ... 'CANcardXLe', ... 'VN1610', ... 'VN1611', ... 'VN1630', ... 'VN1640', ... 'VN7600', ... 'VN8900' }; % SupportedDeviceCodes - Lists the numeric device codes as defined % by Vector for all of their device types supported by the % toolbox. SupportedDeviceCodes = [... 1, ... 2, ... 15, ... 21, ... 25, ... 27, ... 43, ... 55, ... 63, ... 57, ... 59, ... 41, ... 45 ]; end properties (Constant) % Hardware identification constants. XL_BUS_COMPATIBLE_CAN = uint32(hex2dec('00000001')); XL_BUS_ACTIVE_CAP_CAN = uint32(hex2dec('00010000')); end methods (Static) function found = isDriverAvailable() % isDriverAvailable Verifies the presence of a Vector driver. % % This method is used internally to check if a driver interface % for Vector devices is installed on the system. It returns true % if the driver was identified, otherwise returns false. try % Silence load library warnings to prevent potential BaT stalls. import com.mathworks.toolbox.testmeas.util.mwSystem.*; com.mathworks.toolbox.testmeas.util.mwSystem.silenceLoadLibrary(); % Open the Vector driver interface. can.vector.XLDriverLibrary.xlOpenDriver(); catch err %#ok<NASGU> % Return on error. found = false; return; end % Set the vendor as found. found = true; % Close the driver. can.vector.XLDriverLibrary.xlCloseDriver(); end function supported = isDeviceSupported(device) % isDeviceSupported Verify if a device is supported by the toolbox. % % This method is used internally to check if a given device is % supported by the toolbox. It returns true if the DEVICE is % supported, otherwise false. DEVICE can be a device name as a % string or a numeric device code. % Check the type of the input. if ischar(device) % Check for the string present in the suppported device % list by looking for a string match. supported = ~isempty(strmatch(lower(device), lower(can.vector.Utility.SupportedDeviceStrings), 'exact')); else % Look for a match of supported device codes. supported = any(device == can.vector.Utility.SupportedDeviceCodes); end end function deviceString = deviceCodeToString(deviceCode) % deviceCodeToString Translate a Vector device code to a string. % % This method is used internally to tranlate a numeric Vector % device code into a string representing the name of the same % type of device. % Look for a match of supported device string name. deviceString = char(can.vector.Utility.SupportedDeviceStrings(... deviceCode == can.vector.Utility.SupportedDeviceCodes)); end function deviceCode = deviceStringToCode(deviceString) % deviceStringToCode Translate a Vector device string to a code. % % This method is used internally to tranlate a Vector device name % string into a numeric code representing the same type of device. % Look for a match of supported device code. deviceCode = can.vector.Utility.SupportedDeviceCodes(... strmatch(lower(deviceString), lower(can.vector.Utility.SupportedDeviceStrings), 'exact')); end function data = getDriverData(deviceCode, deviceIndex, deviceChannelIndex) % getDriverData Retrieve Vector driver info for a device. % % This method is used internally to look up detailed device and % channel information in the Vector driver interface. This % information is returned as a structure. % Call for the Vector driver data. [~, driverData] = can.vector.XLDriverLibrary.xlGetDriverConfig(); % Find the index into the driver data array for the specified % device channel. Adjust for 0 indexing in the Vector driver, % except for VN8900 devices. if deviceCode == 45 data = driverData(deviceCode == [driverData.hwType] &... (deviceIndex - 1) == [driverData.hwIndex] &... (deviceChannelIndex) == [driverData.hwChannel]); else data = driverData(deviceCode == [driverData.hwType] &... (deviceIndex - 1) == [driverData.hwIndex] &... (deviceChannelIndex - 1) == [driverData.hwChannel]); end end end end