Пример #1
0
 /// <summary>
 /// Creates an instacne of a counter from a <see cref="DigitalSource"/>. 
 /// </summary>
 /// <remarks>
 /// This constructor should be used if an existing <see cref="DigitalSource"/> is to
 /// be shared by multiple other objects such as <see cref="Encoder">Encoders</see> or if
 /// the <see cref="DigitalSource"/> is not a DIO Channel (for instance a <see cref="AnalogTrigger"/>.
 /// <para>The counter will start couting immediately.</para>
 /// </remarks>
 /// <param name="source">The <see cref="DigitalSource"/> to count.</param>
 public Counter(DigitalSource source)
 {
     if (source == null)
         throw new ArgumentNullException(nameof(source), "Digital Source given was null");
     InitCounter(Mode.TwoPulse);
     SetUpSource(source);
 }
Пример #2
0
 public Counter(DigitalSource source)
 {
     if (source == null)
         throw new NullReferenceException("Digital Source given was null");
     InitCounter(Mode.TwoPulse);
     SetUpSource(source);
 }
Пример #3
0
        /// <inheritdoc/>
        public override void Dispose()
        {
            if (ASource != null && m_allocatedA)
            {
                ASource.Dispose();
                m_allocatedA = false;
            }
            if (BSource != null && m_allocatedB)
            {
                BSource.Dispose();
                m_allocatedB = false;
            }
            if (IndexSource != null && m_allocatedI)
            {
                IndexSource.Dispose();
                m_allocatedI = false;
            }

            ASource     = null;
            BSource     = null;
            IndexSource = null;
            int status = 0;

            HAL_FreeEncoder(m_encoder, ref status);
            CheckStatus(status);
        }
Пример #4
0
        /// <summary>
        /// Creates an instance of a Counter object from specified <see cref="DigitalSource">
        /// Digital Sources</see> for up and down counts.
        /// </summary>
        /// <remarks>
        /// The counter will start counting immediately.
        /// </remarks>
        /// <param name="encodingType">The EncodingType for the counter. <see cref="EncodingType.K4X"/> is not supported.</param>
        /// <param name="upSource">The <see cref="DigitalSource"/> to use for up counting.</param>
        /// <param name="downSource">The <see cref="DigitalSource"/> to use for down counting.</param>
        /// <param name="inverted">True to invert the direction of counting.</param>
        public Counter(EncodingType encodingType, DigitalSource upSource, DigitalSource downSource, bool inverted)
        {
            if (encodingType != EncodingType.K2X && encodingType != EncodingType.K1X)
            {
                throw new ArgumentOutOfRangeException(nameof(encodingType), "Counters only support 1X and 2X decoding!");
            }
            if (upSource == null)
            {
                throw new ArgumentNullException(nameof(upSource), "Up Source given was null");
            }
            if (downSource == null)
            {
                throw new ArgumentNullException(nameof(downSource), "Down Source given was null");
            }
            InitCounter(Mode.ExternalDirection);
            SetUpSource(upSource);
            SetDownSource(downSource);
            int status = 0;

            if (encodingType == EncodingType.K1X)
            {
                SetUpSourceEdge(true, false);
                HAL_SetCounterAverageSize(m_counter, 1, ref status);
            }
            else
            {
                SetUpSourceEdge(true, true);
                HAL_SetCounterAverageSize(m_counter, 2, ref status);
            }
            CheckStatus(status);
            SetDownSourceEdge(inverted, true);
        }
Пример #5
0
 //External direction is encoder style.
 public Counter(EncodingType encodingType, DigitalSource upSource, DigitalSource downSource, bool inverted)
 {
     InitCounter(Mode.ExternalDirection);
     if (encodingType != EncodingType.K2X && encodingType != EncodingType.K1X)
     {
         throw new ArgumentOutOfRangeException(nameof(encodingType), "Counters only support 1X and 2X decoding!");
     }
     if (upSource == null)
         throw new ArgumentNullException(nameof(upSource), "Up Source given was null");
     if (downSource == null)
         throw new ArgumentNullException(nameof(downSource), "Down Source given was null");
     SetUpSource(upSource);
     SetDownSource(downSource);
     int status = 0;
     if (encodingType == EncodingType.K1X)
     {
         SetUpSourceEdge(true, false);
         SetCounterAverageSize(m_counter, 1, ref status);
     }
     else
     {
         SetUpSourceEdge(true, true);
         SetCounterAverageSize(m_counter, 2, ref status);
     }
     CheckStatus(status);
     SetDownSourceEdge(inverted, true);
 }
Пример #6
0
        /// <summary>
        /// Sets the index source for the encoder. Resets based on the <see cref="IndexingType"/> passed.
        /// </summary>
        /// <param name="source">The <see cref="DigitalSource"/> to set as the encoder index.</param>
        /// <param name="type">The state that will cause the encoder to reset.</param>
        public void SetIndexSource(DigitalSource source, IndexingType type = IndexingType.ResetOnRisingEdge)
        {
            int status = 0;

            HAL_SetEncoderIndexSource(m_encoder, source.PortHandleForRouting,
                                      (HALAnalogTriggerType)source.AnalogTriggerTypeForRouting, (HALEncoderIndexingType)type, ref status);
            CheckStatus(status);
        }
Пример #7
0
 /// <summary>
 /// Construct an Encoder given A and B Channels.
 /// </summary>
 /// <remarks>The encoder will start counting immediately.</remarks>
 /// <param name="aChannel">The A channel DIO channel. 0-9 are on-board, 10-25 are on the MXP port.</param>
 /// <param name="bChannel">The B channel DIO channel. 0-9 are on-board, 10-25 are on the MXP port.</param>
 /// <param name="reverseDirection">True if to reverse the output, otherwise false</param>
 public Encoder(int aChannel, int bChannel, bool reverseDirection = false)
 {
     m_allocatedA = true;
     m_allocatedB = true;
     m_allocatedI = false;
     ASource      = new DigitalInput(aChannel);
     BSource      = new DigitalInput(bChannel);
     InitEncoder(reverseDirection, EncodingType.K4X);
 }
Пример #8
0
 /// <summary>
 /// Creates an instacne of a counter from a <see cref="DigitalSource"/>.
 /// </summary>
 /// <remarks>
 /// This constructor should be used if an existing <see cref="DigitalSource"/> is to
 /// be shared by multiple other objects such as <see cref="Encoder">Encoders</see> or if
 /// the <see cref="DigitalSource"/> is not a DIO Channel (for instance a <see cref="AnalogTrigger"/>.
 /// <para>The counter will start couting immediately.</para>
 /// </remarks>
 /// <param name="source">The <see cref="DigitalSource"/> to count.</param>
 public Counter(DigitalSource source)
 {
     if (source == null)
     {
         throw new ArgumentNullException(nameof(source), "Digital Source given was null");
     }
     InitCounter(Mode.TwoPulse);
     SetUpSource(source);
 }
Пример #9
0
 public Encoder(int aChannel, int bChannel, bool reverseDirection)
 {
     m_allocatedA = true;
     m_allocatedB = true;
     m_allocatedI = false;
     m_aSource = new DigitalInput(aChannel);
     m_bSource = new DigitalInput(bChannel);
     InitEncoder(reverseDirection);
 }
Пример #10
0
        /// <summary>
        /// Sets the index source for the encoder. Resets based on the <see cref="IndexingType"/> passed.
        /// </summary>
        /// <param name="channel">The DIO channel to set as the encoder index.</param>
        /// <param name="type">The state that will cause the encoder to reset.</param>
        public void SetIndexSource(int channel, IndexingType type = IndexingType.ResetOnRisingEdge)
        {
            if (m_allocatedI)
            {
                throw new AllocationException("Digital Input for Indexing already allocated");
            }

            IndexSource  = new DigitalInput(channel);
            m_allocatedI = true;
            SetIndexSource(IndexSource, type);
        }
Пример #11
0
 private static void SetFilter(DigitalSource input, int channelIndex)
 {
     if (input != null)
     {
         int status = 0;
         SetFilterSelect(input.Port, channelIndex, ref status);
         CheckStatus(status);
         int selected = GetFilterSelect(input.Port, ref status);
         CheckStatus(status);
         if (selected != channelIndex)
             throw new InvalidOperationException($"SetFilterSelect for {channelIndex} failed -> {selected}");
     }
 }
Пример #12
0
        /// <summary>
        /// Sets the down source object for the counter.
        /// </summary>
        /// <param name="source">The DigitalSource to use for counting down.</param>
        public void SetDownSource(DigitalSource source)
        {
            if (m_downSource != null && m_allocatedDownSource)
            {
                m_downSource.Dispose();
                m_allocatedDownSource = false;
            }
            m_downSource = source;
            int status = 0;

            HAL_SetCounterDownSource(m_counter, source.PortHandleForRouting, (HALAnalogTriggerType)source.AnalogTriggerTypeForRouting, ref status);
            CheckStatus(status);
        }
Пример #13
0
        /// <summary>
        /// Disable the down counting source of the counter.
        /// </summary>
        public void ClearDownSource()
        {
            if (m_downSource != null && m_allocatedDownSource)
            {
                m_downSource.Dispose();
                m_allocatedDownSource = false;
            }
            m_downSource = null;

            int status = 0;

            HAL_ClearCounterDownSource(m_counter, ref status);
            CheckStatus(status);
        }
Пример #14
0
 private static void SetFilter(DigitalSource input, int channelIndex)
 {
     if (input != null)
     {
         int status = 0;
         HAL_SetFilterSelect(input.PortHandleForRouting, channelIndex, ref status);
         CheckStatus(status);
         int selected = HAL_GetFilterSelect(input.PortHandleForRouting, ref status);
         CheckStatus(status);
         if (selected != channelIndex)
         {
             throw new InvalidOperationException($"SetFilterSelect for {channelIndex} failed -> {selected}");
         }
     }
 }
Пример #15
0
        /// <inheritdoc/>
        public override void Dispose()
        {
            UpdateWhenEmpty = true;

            ClearUpSource();
            ClearDownSource();

            int status = 0;

            HAL_FreeCounter(m_counter, ref status);
            CheckStatus(status);

            m_upSource   = null;
            m_downSource = null;
            m_counter    = 0;
        }
Пример #16
0
        private void InitCounter(Mode mode)
        {
            int status = 0;
            m_counter = InitializeCounter(mode, ref m_index, ref status);
            CheckStatus(status);

            m_allocatedUpSource = false;
            m_allocatedDownSource = false;
            m_upSource = null;
            m_downSource = null;

            MaxPeriod = 0.5;
            m_distancePerPulse = 1;

            Report(ResourceType.kResourceType_Counter, (byte)m_index, (byte)mode);
        }
Пример #17
0
        private void InitCounter(Mode mode)
        {
            int status = 0;

            m_counter = HAL_InitializeCounter((HALCounterMode)mode, ref m_index, ref status);
            CheckStatusForceThrow(status);

            m_allocatedUpSource   = false;
            m_allocatedDownSource = false;
            m_upSource            = null;
            m_downSource          = null;

            MaxPeriod        = 0.5;
            DistancePerPulse = 1;

            Report(ResourceType.kResourceType_Counter, (byte)m_index, (byte)mode);
        }
Пример #18
0
 /// <summary>
 /// Construct an Encoder given precreated A and B Channels as <see cref="DigitalSource">DigitalSources</see>.
 /// </summary>
 /// <remarks>The encoder will start counting immediately.</remarks>
 /// <param name="aSource">The A channel <see cref="DigitalSource"/></param>
 /// <param name="bSource">The B channel <see cref="DigitalSource"/></param>
 /// <param name="reverseDirection">True if to reverse the output, otherwise false</param>
 public Encoder(DigitalSource aSource, DigitalSource bSource, bool reverseDirection = false)
 {
     m_allocatedA = false;
     m_allocatedB = false;
     m_allocatedI = false;
     if (aSource == null)
     {
         throw new ArgumentNullException(nameof(aSource), "Digital Source A was null");
     }
     ASource = aSource;
     if (bSource == null)
     {
         throw new ArgumentNullException(nameof(bSource), "Digital Source B was null");
     }
     BSource = bSource;
     InitEncoder(reverseDirection, EncodingType.K4X);
 }
Пример #19
0
 public void SetIndexSource(DigitalSource source)
 {
     SetIndexSource(source, IndexingType.ResetOnRisingEdge);
 }
Пример #20
0
        public void SetIndexSource(DigitalSource source, IndexingType type)
        {
            int status = 0;

            bool activeHigh = (type == IndexingType.ResetWhileHigh) || (type == IndexingType.ResetOnRisingEdge);
            bool edgeSensitive = (type == IndexingType.ResetOnFallingEdge) || (type == IndexingType.ResetOnRisingEdge);

            SetEncoderIndexSource(m_encoder, (uint)source.ChannelForRouting,
                source.AnalogTriggerForRouting, activeHigh, edgeSensitive, ref status);
            CheckStatus(status);
        }
Пример #21
0
        public override void Dispose()
        {
            if (m_aSource != null && m_allocatedA)
            {
                m_aSource.Dispose();
                m_allocatedA = false;
            }
            if (m_bSource != null && m_allocatedB)
            {
                m_bSource.Dispose();
                m_allocatedB = false;
            }
            if (m_indexSource != null && m_allocatedI)
            {
                m_indexSource.Dispose();
                m_allocatedI = false;
            }

            m_aSource = null;
            m_bSource = null;
            m_indexSource = null;
            if (m_counter != null)
            {
                m_counter.Dispose();
                m_counter = null;
            }
            else
            {
                int status = 0;
                FreeEncoder(m_encoder, ref status);
                CheckStatus(status);
            }
        }
Пример #22
0
        public Encoder(DigitalSource aSource, DigitalSource bSource, DigitalSource indexSource) :
            this(aSource, bSource, indexSource, false)
        {

        }
Пример #23
0
 /// <summary>
 /// Removes this filter from the given digital input.
 /// </summary>
 /// <param name="input">The <see cref="DigitalSource"/> to stop filtering.</param>
 public void Remove(DigitalSource input)
 {
     SetFilter(input, 0);
 }
Пример #24
0
        public void ClearDownSource()
        {
            if (m_downSource != null && m_allocatedDownSource)
            {
                m_downSource.Dispose();
                m_allocatedDownSource = false;
            }
            m_downSource = null;

            int status = 0;
            ClearCounterDownSource(m_counter, ref status);
            CheckStatus(status);
        }
Пример #25
0
 /// <summary>
 /// Construct a <see cref="GearTooth"/> sensor given a <see cref="DigitalSource"/>.
 /// </summary>
 /// <remarks>No direction sensing is assumed.</remarks>
 /// <param name="source">An existing <see cref="DigitalSource"/> object 
 /// (such as a <see cref="DigitalInput"/></param>
 public GearTooth(DigitalSource source) : this(source, false)
 {
     
 }
Пример #26
0
 /// <summary>
 /// Construct a <see cref="GearTooth"/> sensor given a <see cref="DigitalSource"/>.
 /// </summary>
 /// <remarks>This should be used when sharing digital inputs</remarks>
 /// <param name="source">An existing <see cref="DigitalSource"/> object 
 /// (such as a <see cref="DigitalInput"/></param>
 /// <param name="directionSensitive">True to enable direction sensing.</param>
 public GearTooth(DigitalSource source, bool directionSensitive) : base(source)
 {
     DirectionSensing = directionSensitive;
 }
Пример #27
0
 /// <summary>
 /// Removes this filter from the given digital input.
 /// </summary>
 /// <param name="input">The <see cref="DigitalSource"/> to stop filtering.</param>
 public void Remove(DigitalSource input)
 {
     SetFilter(input, 0);
 }
Пример #28
0
 /// <summary>
 /// Assigns the <see cref="DigitalSource"/> to this glitch filter
 /// </summary>
 /// <param name="input">The <see cref="DigitalSource"/> to add.</param>
 public void Add(DigitalSource input)
 {
     SetFilter(input, m_channelIndex + 1);
 }
Пример #29
0
 public SWave_Encoder(DigitalSource Asource, DigitalSource Bsource, DigitalSource Indexsource)
     : base(Asource, Bsource, Indexsource)
 {
 }
Пример #30
0
 /// <summary>
 /// Construct an Encoder given precreated A, B, and Index Channels as <see cref="DigitalSource">DigitalSources</see>.
 /// </summary>
 /// <remarks>The encoder will start counting immediately.</remarks>
 /// <param name="aSource">The A channel <see cref="DigitalSource"/></param>
 /// <param name="bSource">The B channel <see cref="DigitalSource"/></param>
 /// <param name="indexSource">The Index channel <see cref="DigitalSource"/></param>
 /// <param name="reverseDirection">True if to reverse the output, otherwise false</param>
 public Encoder(DigitalSource aSource, DigitalSource bSource,
     DigitalSource indexSource, bool reverseDirection = false)
 {
     m_allocatedA = false;
     m_allocatedB = false;
     m_allocatedI = false;
     if (aSource == null)
         throw new ArgumentNullException(nameof(aSource), "Digital Source A was null");
     m_aSource = aSource;
     if (bSource == null)
         throw new ArgumentNullException(nameof(bSource), "Digital Source B was null");
     m_aSource = aSource;
     m_bSource = bSource;
     m_indexSource = indexSource;
     InitEncoder(reverseDirection);
     SetIndexSource(indexSource);
 }
Пример #31
0
        public override void Dispose()
        {
            UpdateWhenEmpty = true;

            ClearUpSource();
            ClearDownSource();

            int status = 0;
            FreeCounter(m_counter, ref status);
            CheckStatus(status);

            m_upSource = null;
            m_downSource = null;
            m_counter = IntPtr.Zero;
        }
Пример #32
0
 public Encoder(DigitalSource aSource, DigitalSource bSource,
     bool reverseDirection, EncodingType encodingType)
 {
     m_allocatedA = false;
     m_allocatedB = false;
     m_allocatedI = false;
     m_encodingType = encodingType;
     if (aSource == null)
         throw new NullReferenceException("Digital Source A was null");
     m_aSource = aSource;
     if (bSource == null)
         throw new NullReferenceException("Digital Source B was null");
     m_aSource = aSource;
     m_bSource = bSource;
     InitEncoder(reverseDirection);
 }
Пример #33
0
 public void SetDownSource(DigitalSource source)
 {
     if (m_downSource != null && m_allocatedDownSource)
     {
         m_downSource.Dispose();
         m_allocatedDownSource = false;
     }
     m_downSource = source;
     int status = 0;
     SetCounterDownSource(m_counter, (uint)source.ChannelForRouting, source.AnalogTriggerForRouting, ref status);
     CheckStatus(status);
 }
Пример #34
0
 public Encoder(DigitalSource aSource, DigitalSource bSource,
     DigitalSource indexSource, bool reverseDirection)
 {
     m_allocatedA = false;
     m_allocatedB = false;
     m_allocatedI = false;
     if (aSource == null)
         throw new NullReferenceException("Digital Source A was null");
     m_aSource = aSource;
     if (bSource == null)
         throw new NullReferenceException("Digital Source B was null");
     m_aSource = aSource;
     m_bSource = bSource;
     m_indexSource = indexSource;
     InitEncoder(reverseDirection);
     SetIndexSource(indexSource);
 }
Пример #35
0
 /// <summary>
 /// Construct a <see cref="GearTooth"/> sensor given a <see cref="DigitalSource"/>.
 /// </summary>
 /// <remarks>This should be used when sharing digital inputs</remarks>
 /// <param name="source">An existing <see cref="DigitalSource"/> object
 /// (such as a <see cref="DigitalInput"/></param>
 /// <param name="directionSensitive">True to enable direction sensing.</param>
 public GearTooth(DigitalSource source, bool directionSensitive) : base(source)
 {
     DirectionSensing = directionSensitive;
 }
Пример #36
0
 /// <summary>
 /// Assigns the <see cref="DigitalSource"/> to this glitch filter
 /// </summary>
 /// <param name="input">The <see cref="DigitalSource"/> to add.</param>
 public void Add(DigitalSource input)
 {
     SetFilter(input, m_channelIndex + 1);
 }
Пример #37
0
 /// <summary>
 /// Construct a <see cref="GearTooth"/> sensor given a <see cref="DigitalSource"/>.
 /// </summary>
 /// <remarks>No direction sensing is assumed.</remarks>
 /// <param name="source">An existing <see cref="DigitalSource"/> object
 /// (such as a <see cref="DigitalInput"/></param>
 public GearTooth(DigitalSource source) : this(source, false)
 {
 }
Пример #38
0
 public SWave_Encoder(DigitalSource Asource, DigitalSource Bsource, bool Reverse)
     : base(Asource, Bsource, Reverse)
 {
 }