Data Acquisition Toolbox Support Package for Digilent Analog Discovery hardware (R2012a / R2012b)

by

 

02 Oct 2012 (Updated )

Analog Input/Output (foreground clocked/non-clocked) support for Digilent Analog Discovery.

daq.di.internal.ChannelRecord
classdef ChannelRecord < handle
    % ChannelRecord: Index/Count of Channels in a subsystem
    %
    %   Used exclusively by daq.di.Session for keeping track of channels in
    %   a subsystem.
    %   This undocumented class may be removed in a future release.
    
    % Copyright 2013 The MathWorks, Inc.

    properties (GetAccess = {?daq.di.internal.ChannelRecord, ?daq.di.Session}, ...
            SetAccess = private)
        Indices
        Count
    end
    
    methods
        function obj = ChannelRecord()
            obj.Indices = [];
            obj.Count = 0;
        end
        
        function obj = addChannel(obj, index)
            indices = obj.Indices;
            containsChannelIndex = (indices == index);
            
            % If the object does not contain the channel index, then add
            % it.
            if ~any(containsChannelIndex)
                % Addition is not guaranteed to preserve min:max order
                % We always want to sort/remove duplicates
                indices(end+1) = index;
                indices = unique(indices);
                obj.Indices = indices;
                obj.Count = length(indices);
            end
        end
        
        function obj = removeChannel(obj, index)
            indices = obj.Indices;
            containsChannelIndex = (indices == index);

            % If we find a matching index, remove it
            if any(containsChannelIndex)
                obj.Count = obj.Count - 1;
                indices(containsChannelIndex) = [];
                obj.Indices = indices;
            end
        end

        % Removing indices necessitates reducing existing indices that
        % exceed the index by 1 (all indices "shift" over)
        function obj = shiftIndicesByOne(obj, limitingIndex)
            indices = obj.Indices;
            threshold = indices > limitingIndex;
            indices(threshold) = indices(threshold)-1;
            obj.Indices = indices;            
        end        
        
        % Remove an index and adjust indices that exceed it accordingly
        function obj = removeChannelAndShiftIndex(obj, index)
            obj.removeChannel(index);
            obj.shiftIndicesByOne(index);
        end
        
        function delete(obj)
            obj.Indices = [];
            obj.Count = 0;
        end
    end
end

Contact us