gusucode.com > vnt工具箱matlab源码程序 > vnt/vnt/+can/+kvaser/CANLib.m
classdef (Hidden) CANLib % CANLib Kvaser CANLib function wrapping class. % % This class wraps and presents the functions available in Kvaser CANLib. % This is meant for internal use only and applies no input validation. % It does perform output validation on each call though and will error % should any function fail. % Authors: JDP % Copyright 2010 The MathWorks, Inc. methods (Static) function canBusOff(handle) % Call the vendor driver function. status = mexKvaserCANLib('canBusOff', handle); % Check the return status for an error condition. can.kvaser.CANLib.checkStatus(status, 'canBusOff'); end function canBusOn(handle) % Call the vendor driver function. status = mexKvaserCANLib('canBusOn', handle); % Check the return status for an error condition. can.kvaser.CANLib.checkStatus(status, 'canBusOn'); end function canClose(handle) % Call the vendor driver function. status = mexKvaserCANLib('canClose', handle); % Check the return status for an error condition. if status ~= 0 && status ~= -8 error(message('vnt:Channel:VendorDriverError', ... 'Kvaser CANLib', ... 'canClose', ... status, ... can.kvaser.CANLib.canGetErrorText(status))); end end function canFlushReceiveQueue(handle) % Call the vendor driver function. status = mexKvaserCANLib('canFlushReceiveQueue', handle); % Check the return status for an error condition. can.kvaser.CANLib.checkStatus(status, 'canFlushReceiveQueue'); end function canFlushTransmitQueue(handle) % Call the vendor driver function. status = mexKvaserCANLib('canFlushTransmitQueue', handle); % Check the return status for an error condition. can.kvaser.CANLib.checkStatus(status, 'canFlushTransmitQueue'); end function driverType = canGetBusOutputControl(handle) % Call the vendor driver function. [status, driverType] = mexKvaserCANLib('canGetBusOutputControl', handle); % Check the return status for an error condition. can.kvaser.CANLib.checkStatus(status, 'canGetBusOutputControl'); end function [freq, tseg1, tseg2, sjw, noSamp] = canGetBusParams(handle) % Call the vendor driver function. [status, freq, tseg1, tseg2, sjw, noSamp] = mexKvaserCANLib('canGetBusParams', handle); % Check the return status for an error condition. can.kvaser.CANLib.checkStatus(status, 'canGetBusParams'); end function busStatistics = canGetBusStatistics(handle) % Call the vendor driver function. [status, busStatistics] = mexKvaserCANLib('canGetBusStatistics', handle); % Check the return status for an error condition. can.kvaser.CANLib.checkStatus(status, 'canGetBusStatistics'); end function channelData = canGetChannelData(channelNumber) % Call the vendor driver function. [status, channelData] = mexKvaserCANLib('canGetChannelData', channelNumber); % Check the return status for an error condition. can.kvaser.CANLib.checkStatus(status, 'canGetChannelData'); end function [lineMode, lineModeText, resNet] = canGetDriverMode(handle) % Call the vendor driver function. [status, lineMode, lineModeText, resNet] = mexKvaserCANLib('canGetDriverMode', handle); % Check the return status for an error condition. can.kvaser.CANLib.checkStatus(status, 'canGetDriverMode'); end function statusText = canGetErrorText(statusCode) % Call the vendor driver function. [status, statusText] = mexKvaserCANLib('canGetErrorText', statusCode); % Check the return status for an error condition. can.kvaser.CANLib.checkStatus(status, 'canGetErrorText'); end function channelCount = canGetNumberOfChannels() % Call the vendor driver function. [status, channelCount] = mexKvaserCANLib('canGetNumberOfChannels'); % Check the return status for an error condition. can.kvaser.CANLib.checkStatus(status, 'canGetNumberOfChannels'); end function versionString = canGetVersion() % Call the vendor driver function. versionString = mexKvaserCANLib('canGetVersion'); end function versionString = canGetVersionEx(versionCode) % Call the vendor driver function. versionString = mexKvaserCANLib('canGetVersionEx', versionCode); end function canInitializeLibrary() % Call the vendor driver function. mexKvaserCANLib('canInitializeLibrary'); end function value = canIoCtl(handle, func, value) % Call the vendor driver function. [status, value] = mexKvaserCANLib('canIoCtl', handle, func, value); % Check the return status for an error condition. can.kvaser.CANLib.checkStatus(status, 'canIoCtl'); end function [handle, hasInitAccess] = canOpenChannel(channelNumber) % Call the vendor driver function. [handle, hasInitAccess] = mexKvaserCANLib('canOpenChannel', channelNumber); % Check the return status for an error condition. if handle < 0 error(message('vnt:Channel:VendorDriverError', ... 'Kvaser CANLib', ... 'canOpenChannel', ... status, ... can.kvaser.CANLib.canGetErrorText(handle))); end end function message = canRead(handle, count) % Call the vendor driver function. [status, message] = mexKvaserCANLib('canRead', handle, count); % Check the return status for an error condition. can.kvaser.CANLib.checkStatus(status, 'canRead'); end function [txErrCnt, rxErrCnt, ovErrCnt] = canReadErrorCounters(handle) % Call the vendor driver function. [status, txErrCnt, rxErrCnt, ovErrCnt] = mexKvaserCANLib('canReadErrorCounters', handle); % Check the return status for an error condition. can.kvaser.CANLib.checkStatus(status, 'canReadErrorCounters'); end function chipStatus = canReadStatus(handle) % Call the vendor driver function. [status, chipStatus] = mexKvaserCANLib('canReadStatus', handle); % Check the return status for an error condition. can.kvaser.CANLib.checkStatus(status, 'canReadStatus'); end function time = canReadTimer(handle) % Call the vendor driver function. time = mexKvaserCANLib('canReadTimer', handle); end function canRequestBusStatistics(handle) % Call the vendor driver function. status = mexKvaserCANLib('canRequestBusStatistics', handle); % Check the return status for an error condition. can.kvaser.CANLib.checkStatus(status, 'canRequestBusStatistics'); end function canRequestChipStatus(handle) % Call the vendor driver function. status = mexKvaserCANLib('canRequestChipStatus', handle); % Check the return status for an error condition. can.kvaser.CANLib.checkStatus(status, 'canRequestChipStatus'); end function canResetBus(handle) % Call the vendor driver function. status = mexKvaserCANLib('canResetBus', handle); % Check the return status for an error condition. can.kvaser.CANLib.checkStatus(status, 'canResetBus'); end function canSetAcceptanceFilter(handle, code, mask, isExtended) % Call the vendor driver function. status = mexKvaserCANLib('canSetAcceptanceFilter', handle, code, mask, isExtended); % Check the return status for an error condition. can.kvaser.CANLib.checkStatus(status, 'canSetAcceptanceFilter'); end function canSetBitrate(handle, bitRate) % Call the vendor driver function. status = mexKvaserCANLib('canSetBitrate', handle, bitRate); % Check the return status for an error condition. can.kvaser.CANLib.checkStatus(status, 'canSetBitrate'); end function canSetBusOutputControl(handle, driverType) % Call the vendor driver function. status = mexKvaserCANLib('canSetBusOutputControl', handle, driverType); % Check the return status for an error condition. can.kvaser.CANLib.checkStatus(status, 'canSetBusOutputControl'); end function canSetBusParams(handle, freq, tseg1, tseg2, sjw, noSamp) % Call the vendor driver function. status = mexKvaserCANLib('canSetBusParams', handle, freq, tseg1, tseg2, sjw, noSamp); % Check the return status for an error condition. can.kvaser.CANLib.checkStatus(status, 'canSetBusParams'); end function canSetDriverMode(handle, lineMode) % Call the vendor driver function. status = mexKvaserCANLib('canSetDriverMode', handle, lineMode); % Check the return status for an error condition. can.kvaser.CANLib.checkStatus(status, 'canSetDriverMode'); end function canUnloadLibrary() % Call the vendor driver function. status = mexKvaserCANLib('canUnloadLibrary'); % Check the return status for an error condition. can.kvaser.CANLib.checkStatus(status, 'canUnloadLibrary'); end function canWrite(handle, message) % Call the vendor driver function. status = mexKvaserCANLib('canWrite', handle, message); % Check the return status for an error condition. can.kvaser.CANLib.checkStatus(status, 'canWrite'); end function canWriteWait(handle, message, timeout) % Call the vendor driver function. status = mexKvaserCANLib('canWriteWait', handle, message, timeout); % Check the return status for an error condition. can.kvaser.CANLib.checkStatus(status, 'canWriteWait'); end function checkStatus(status, functionName) % checkStatus Tests the result of the vendor driver call. % % This method is used to validate the results of calling a vendor % driver function. It throws an error if the call failed. The error % will contain information from the driver on the failure mode. % % The function inputs are as follows: % status - The vendor driver function returned status code. % functionName - The name of the vendor driver function whose % status is being checked. % Throw error on a failed function call. if status ~= 0 error(message('vnt:Channel:VendorDriverError', ... 'Kvaser CANLib', ... functionName, ... num2str(status), ... can.kvaser.CANLib.canGetErrorText(status))); end end end end