Exemple #1
0
        /// <summary>
        /// Gets a slice of the current data of all tags.
        /// </summary>
        public DeviceSlice GetCurrentData()
        {
            lock (curDataLock)
            {
                DeviceSlice deviceSlice = new DeviceSlice(DateTime.UtcNow, deviceTags.Count, rawData.Length)
                {
                    DeviceNum = deviceNum
                };

                int tagIndex  = 0;
                int dataIndex = 0;

                foreach (DeviceTag deviceTag in deviceTags)
                {
                    deviceSlice.DeviceTags[tagIndex] = deviceTag;

                    for (int i = 0, len = deviceTag.DataLength; i < len; i++)
                    {
                        deviceSlice.CnlData[dataIndex] = rawData[dataIndex];
                        dataIndex++;
                    }

                    tagIndex++;
                }

                Array.Clear(modifiedFlags, 0, modifiedFlags.Length);
                return(deviceSlice);
            }
        }
Exemple #2
0
        /// <summary>
        /// Gets a slice of the current data for modified tags.
        /// </summary>
        public DeviceSlice GetModifiedData()
        {
            if (deviceTags.Count == 0)
            {
                return(DeviceSlice.Empty);
            }

            lock (curDataLock)
            {
                int tagCount   = 0; // number of modified tags
                int dataLength = 0; // data length of modified tags

                foreach (DeviceTag deviceTag in deviceTags)
                {
                    if (modifiedFlags[deviceTag.Index])
                    {
                        tagCount++;
                        dataLength += deviceTag.DataLength;
                    }
                }

                if (tagCount == 0)
                {
                    return(DeviceSlice.Empty);
                }

                DeviceSlice deviceSlice = new DeviceSlice(DateTime.UtcNow, tagCount, dataLength)
                {
                    DeviceNum = deviceNum
                };

                int tagIndex  = 0;
                int dataIndex = 0;

                foreach (DeviceTag deviceTag in deviceTags)
                {
                    if (modifiedFlags[deviceTag.Index])
                    {
                        modifiedFlags[deviceTag.Index]   = false;
                        deviceSlice.DeviceTags[tagIndex] = deviceTag;

                        for (int i = 0, len = deviceTag.DataLength; i < len; i++)
                        {
                            deviceSlice.CnlData[dataIndex] = rawData[deviceTag.DataIndex + i];
                            dataIndex++;
                        }

                        tagIndex++;
                    }
                }

                return(deviceSlice);
            }
        }
Exemple #3
0
        /// <summary>
        /// Adds the slice of historical data to the queue.
        /// </summary>
        public void EnqueueSlice(DeviceSlice deviceSlice)
        {
            if (deviceSlice == null)
            {
                throw new ArgumentNullException(nameof(deviceSlice));
            }

            deviceSlice.DeviceNum = deviceNum;
            dataView.AddSlice(deviceSlice);

            lock (slices)
            {
                slices.Enqueue(deviceSlice);
            }
        }
Exemple #4
0
 /// <summary>
 /// Removes and returns the slice of historical data at the beginning of the queue.
 /// </summary>
 public bool DequeueSlice(out DeviceSlice deviceSlice)
 {
     lock (slices)
     {
         if (slices.Count > 0)
         {
             deviceSlice = slices.Dequeue();
             return(true);
         }
         else
         {
             deviceSlice = null;
             return(false);
         }
     }
 }
Exemple #5
0
        /// <summary>
        /// Adds the archive slice.
        /// </summary>
        public void AddSlice(DeviceSlice deviceSlice)
        {
            if (deviceSlice == null)
            {
                throw new ArgumentNullException(nameof(deviceSlice));
            }

            lock (slices)
            {
                while (slices.Count >= ItemCount)
                {
                    slices.Dequeue();
                }

                slices.Enqueue(deviceSlice);
                sliceTable.ResetColumnWidths();
            }
        }
Exemple #6
0
 /// <summary>
 /// Adds the device archive slice.
 /// </summary>
 public void AddSlice(DeviceSlice deviceSlice)
 {
 }