/// <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); } }
/// <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); } }
/// <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); } }
/// <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); } } }
/// <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(); } }
/// <summary> /// Adds the device archive slice. /// </summary> public void AddSlice(DeviceSlice deviceSlice) { }