www.gusucode.com > vnt工具箱matlab源码程序 > vnt/vnt/+can/+ni/+xnet/NIXNET.m
classdef (Hidden) NIXNET % NIXNET National Instruments NI-XNET library function wrapping class. % % This class wraps and presents the functions available in the % National Instruments NI-XNET library. 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 2013-2015 The MathWorks, Inc. methods (Static) function SessionRef = nxSystemOpen() % Call the vendor driver function. [status, SessionRef] = mexNIXNET('nxSystemOpen'); % Check the return status for an error condition. can.ni.xnet.NIXNET.checkStatus(status, 'nxSystemOpen'); end function nxSystemClose(SessionRef) % Call the vendor driver function. status = mexNIXNET('nxSystemClose', SessionRef); % Check the return status for an error condition. can.ni.xnet.NIXNET.checkStatus(status, 'nxSystemClose'); end function SessionRef = nxCreateSession(DatabaseName, ClusterName, List, Interface, Mode) % Call the vendor driver function. [status, SessionRef] = mexNIXNET('nxCreateSession', DatabaseName, ClusterName, List, Interface, Mode); % Check the return status for an error condition. can.ni.xnet.NIXNET.checkStatus(status, 'nxCreateSession'); end function nxClear(SessionRef) % Call the vendor driver function. status = mexNIXNET('nxClear', SessionRef); % Check the return status for an error condition. can.ni.xnet.NIXNET.checkStatus(status, 'nxClear'); end function DatabaseRef = nxdbOpenDatabase(DatabaseName) % Call the vendor driver function. [status, DatabaseRef] = mexNIXNET('nxdbOpenDatabase', DatabaseName); % Check the return status for an error condition. can.ni.xnet.NIXNET.checkStatus(status, 'nxdbOpenDatabase'); end function nxdbCloseDatabase(DatabaseRef, CloseAllRefs) % Call the vendor driver function. status = mexNIXNET('nxdbCloseDatabase', DatabaseRef, CloseAllRefs); % Check the return status for an error condition. can.ni.xnet.NIXNET.checkStatus(status, 'nxdbCloseDatabase'); end function nxConnectTerminals(SessionRef, source, destination) % Call the vendor driver function. status = mexNIXNET('nxConnectTerminals', SessionRef, source, destination); % Check the return status for an error condition. can.ni.xnet.NIXNET.checkStatus(status, 'nxConnectTerminals'); end function nxDisconnectTerminals(SessionRef, source, destination) % Call the vendor driver function. status = mexNIXNET('nxDisconnectTerminals', SessionRef, source, destination); % Check the return status for an error condition. can.ni.xnet.NIXNET.checkStatus(status, 'nxDisconnectTerminals'); end function PropertyValue = nxGetProperty(SessionRef, PropertyID, PropertyStyle) % Call the vendor driver function. [status, PropertyValue] = mexNIXNET('nxGetProperty', SessionRef, PropertyID, PropertyStyle); % Check the return status for an error condition. can.ni.xnet.NIXNET.checkStatus(status, 'nxGetProperty'); end function PropertySize = nxGetPropertySize(SessionRef, PropertyID) % Call the vendor driver function. [status, PropertySize] = mexNIXNET('nxGetPropertySize', SessionRef, PropertyID); % Check the return status for an error condition. can.ni.xnet.NIXNET.checkStatus(status, 'nxGetPropertySize'); end function nxSetProperty(SessionRef, PropertyID, PropertyValue) % Call the vendor driver function. status = mexNIXNET('nxSetProperty', SessionRef, PropertyID, PropertyValue); % Check the return status for an error condition. can.ni.xnet.NIXNET.checkStatus(status, 'nxSetProperty'); end function [state, fault] = nxReadState(SessionRef, StateID) % Call the vendor driver function. [status, state, fault] = mexNIXNET('nxReadState', SessionRef, StateID); % Check the return status for an error condition. can.ni.xnet.NIXNET.checkStatus(status, 'nxReadState'); % Perform any conversions or adjustments needed on the output. switch StateID case can.ni.xnet.Utility.nxState_CANComm % Convert some of the numeric status values to more usable % string values. state.CommunicationState = can.ni.xnet.Utility.nxCANComm_Get_CommState_Values(state.CommunicationState); state.LastError = can.ni.xnet.Utility.nxCANComm_Get_LastErr_Values(state.LastError); case {can.ni.xnet.Utility.nxState_TimeCurrent, ... can.ni.xnet.Utility.nxState_TimeCommunicating, ... can.ni.xnet.Utility.nxState_TimeStart} % Check for a value of 0, which means no time is set. if state == 0 % Return an empty datetime object as there is no time % to report. state = datetime.empty(); else % Convert to MATLAB datetime objects. Per NI documenation, % time is reported as time in 100 ns increments since Jan 1, % 1601 12:00 AM UTC dt = datetime(1601, 1, 1, 0, 0, 0); dt.TimeZone = 'UTC'; % Add the 100 ns increments to the time as milliseconds. dt = dt + milliseconds(double(state) * 100 * 1e-6); % Adjust the timezone of the object to the current time % zone of the system. dt.TimeZone = datetime().SystemTimeZone; % Return the final datetime object. state = dt; end end end function string = nxStatusToString(status) % Call the vendor driver function. string = mexNIXNET('nxStatusToString', status); 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', ... 'National Instruments NI-XNET', ... functionName, ... dec2hex(bitcmp(abs(status) - 1, 'uint32')), ... can.ni.xnet.NIXNET.nxStatusToString(status))); end end end end