Пример #1
0
        /// <summary>
        /// Gets the digital output values for the specified <see cref="DOBit"/>s. A read from the controller will only be performed if no previous
        /// read was performed within the specified timeout.
        /// </summary>
        /// <param name="bits">The DO bits.</param>
        /// <param name="minFresh">The minimum amount of time before data is considered stale and a re-read is required.</param>
        /// <returns>
        /// The values.
        /// </returns>
        public static IEnumerable <int> GetValues(this IEnumerable <DOBit> bits, TimeSpan minFresh)
        {
            var devGroups = bits.GroupBy(b => b.Device);

            foreach (var devGroup in devGroups)
            {
                IIODevice    dev         = (IIODevice)devGroup.Key;
                List <DOBit> orderedBits = devGroup.OrderBy(b => b.Channel).ToList();

                bool allFresh = true;
                foreach (DOBit bit in orderedBits)
                {
                    if (DateTime.Now - bit.LastRead > minFresh)
                    {
                        allFresh = false;
                        break;
                    }
                }

                if (!allFresh)
                {
                    int[] values = dev.GetDOBits(orderedBits.Select(b => b.Channel).ToArray());

                    DateTime readTime = DateTime.Now;

                    for (int i = 0; i < values.Length; i++)
                    {
                        orderedBits[i].Update(readTime, values[i]);
                    }
                }
            }

            return(bits.Select(b => b.GetLast()));
        }
Пример #2
0
        /// <summary>
        /// Gets the digital output values for the specified DO bits.
        /// </summary>
        /// <param name="bits">The DO bits.</param>
        /// <returns>The values.</returns>
        public static IEnumerable <int> GetValues(this IEnumerable <DOBit> bits)
        {
            var devGroups = bits.GroupBy(b => b.Device);

            foreach (var devGroup in devGroups)
            {
                IIODevice    dev         = (IIODevice)devGroup.Key;
                List <DOBit> orderedBits = devGroup.OrderBy(b => b.Channel).ToList();

                int[] values = dev.GetDOBits(orderedBits.Select(b => b.Channel).ToArray());

                DateTime readTime = DateTime.Now;

                for (int i = 0; i < values.Length; i++)
                {
                    orderedBits[i].Update(readTime, values[i]);
                }
            }

            return(bits.Select(b => b.GetLast()));
        }