gusucode.com > vnt工具箱matlab源码程序 > vnt/vntblks/vntmasks/private/privatevntsldevicecheck.m
function [errMsg paramsStruct] = privatevntsldevicecheck(paramsStruct) %PRIVATEVNTSLDEVICECHECK Checks for device configuration validity and updates parameters. % % [ERRMSG PARAMSSTRUCT] = PRIVATEVNTSLDEVICECHECK(PARAMSSTRUCT) % does device validation for VNT Simulink model. Updates structure % information in the return structure, PARAMSSTRUCT, information and % device selected in block, BLOCKHANDLESTR. % % This function is shared between start() call for Replay, Transmit, % Receive and Log blocks in Vehicle Network Toolbox. % SS 03-20-11 % Copyright 2011-2015 The MathWorks, Inc. % Set error message errMsg = []; paramsStruct = localGetDeviceInformation(paramsStruct); % Find if there are multiple Receive blocks. if strcmpi(paramsStruct.Vendor, 'PEAK-System') device = get_param(paramsStruct.BlockName, 'Device'); receiveBlocks = find_system(paramsStruct.Parent, ... 'LookUnderMasks', 'all', ... 'MaskType', 'CAN Receive', ... 'Device', device); if ( strcmpi(get(paramsStruct.BlockHandle, 'MaskType'), 'CAN Receive') ) if ( length(receiveBlocks)>1 ) msgStrings = privatevntslstring('errorstrings'); errMsg = sprintf(msgStrings.MultipleNIReceive); return; end end end % Get the converter path. arch = computer('arch'); paramsStruct.MLLibraryPath = fullfile(toolboxdir('vnt'), 'vnt', 'private', arch); paramsStruct.SLLibraryPath = fullfile(toolboxdir('vnt'), 'vntblks', 'vntmex', arch); switch (lower(paramsStruct.Vendor)) case 'vector' paramsStruct.PluginPath = 'vectorxlplugin'; paramsStruct.WrapperPath = 'slvectorxlwrapper'; case 'kvaser' paramsStruct.PluginPath = 'kvasercanlibplugin'; paramsStruct.WrapperPath = 'slkvaserwrapper'; case 'ni' paramsStruct.PluginPath = 'nicanplugin'; paramsStruct.WrapperPath = 'slnicanwrapper'; case 'ni-xnet' paramsStruct.PluginPath = 'nixnetplugin'; paramsStruct.WrapperPath = 'slnixnetwrapper'; case 'peak-system' paramsStruct.PluginPath = 'peakpcanbasicplugin'; paramsStruct.WrapperPath = 'slpeaksystempcanbasicwrapper'; end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function paramsStruct = localGetDeviceInformation(paramsStruct) % Device is in the following format: % 'Vector CANcaseXL 1 (Channel 1)' paramsStruct.Device = get_param(paramsStruct.BlockHandle, 'Device'); % Get the vendor name. [paramsStruct.Vendor, rem] = strtok(paramsStruct.Device); paramsStruct.Vendor = lower(paramsStruct.Vendor); % Get the device name [fullDeviceName, rem] = strtok(rem, '('); fullDeviceName = strtrim(fullDeviceName); indices = strfind(fullDeviceName, ' '); % There will be a space always % Get the information for the device. switch lower(paramsStruct.Vendor) case {'ni'} % Get the channel data. paramsStruct.DeviceCode = 0; channelInfo = can.ni.Utility.getChannelInfoByInterface(rem(2:end-1)); paramsStruct.DeviceName = channelInfo.Series; paramsStruct.SerialNumber = channelInfo.SerialNumber; paramsStruct.DeviceIndex = channelInfo.InterfaceNumber; paramsStruct.DeviceChannelIndex = channelInfo.PortIndex; case {'ni-xnet'} % Get the channel data. paramsStruct.DeviceCode = 0; channelInfo = can.ni.xnet.Utility.getChannelInfoByInterface(rem(2:end-1)); paramsStruct.DeviceName = channelInfo.Device.ProductName; paramsStruct.SerialNumber = channelInfo.Device.SerialNumber; paramsStruct.DeviceIndex = channelInfo.Interface.Number; paramsStruct.DeviceChannelIndex = channelInfo.Interface.PortNumber; case {'peak-system'} % Get the channel data. channelInfo = can.peaksystem.pcanbasic.Utility.getChannelInfoByInterface(rem(2:end-1)); paramsStruct.DeviceCode = can.peaksystem.pcanbasic.Utility.ChannelNamesMap(channelInfo.Handle); paramsStruct.DeviceName = channelInfo.HardwareName; paramsStruct.SerialNumber = channelInfo.SerialNumber; paramsStruct.DeviceIndex = channelInfo.DeviceNumber; paramsStruct.DeviceChannelIndex = channelInfo.ControllerNumber; otherwise paramsStruct.DeviceName = lower(fullDeviceName(1:indices(end)-1)); % Ignore the last space % Get the device index paramsStruct.DeviceIndex = str2double(fullDeviceName(indices(end)+1:end)); [~, rem] = strtok(rem); % Get the channel index and convert to numeric paramsStruct.DeviceChannelIndex = str2double(rem(2:end-1)); if strcmpi(paramsStruct.Vendor, 'vector') paramsStruct.DeviceCode = can.vector.Utility.deviceStringToCode(paramsStruct.DeviceName); driverData = can.vector.Utility.getDriverData(paramsStruct.DeviceCode, ... paramsStruct.DeviceIndex, ... paramsStruct.DeviceChannelIndex); paramsStruct.SerialNumber = driverData.serialNumber; paramsStruct.DeviceName = driverData.name; elseif strcmpi(paramsStruct.Vendor, 'kvaser') % Open the driver interface. can.kvaser.CANLib.canInitializeLibrary(); paramsStruct.DeviceCode = can.kvaser.Utility.translateDeviceCode(paramsStruct.DeviceName); driverData = can.kvaser.Utility.getDriverData(paramsStruct.DeviceCode, ... paramsStruct.DeviceIndex, ... paramsStruct.DeviceChannelIndex); paramsStruct.SerialNumber = driverData.CardSerialNumber; paramsStruct.DeviceName = driverData.DeviceName; end end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%