private void OnTimedEvent(object source, ElapsedEventArgs args) { // we use the timer to update our data. // The timer event occurs each second. // We send data at a rate of 100 Hz, this means // we have to create 100 data points for each timer event. Random rand = new Random(m_Time); DataPointEx[] data = new DataPointEx[100]; for (int i = 0; i < 100; i++) { data[i] = new DataPointEx(m_Time * 10.0, Convert.ToDouble(rand.Next(0, 1000))); m_Time++; } // Send the new data to Chromeleon m_Channel.UpdateDataEx(data); // If acquisition was stopped disable the timer. if (m_Channel.AcquisitionStateProperty.Value == (int)AcquisitionState.Idle) { m_Timer.Enabled = false; // Notify Chromeleon that there will be no more data available. // We could also send this if our hardware has finished data acquisition. m_Channel.NoMoreData(); } }
private void ChannelUpdateData() { DateTime timeNow = DateTime.UtcNow; DateTime acquisitionOnTime = AcquisitionTimeOn; TimeSpan elapsedTime = timeNow - acquisitionOnTime; double nextDataPointTimeMilliseconds = m_TimeIntervalBetweenTwoDataPointsMilliSeconds * (m_DataPacketIndex + 1); double elapsedTimeTotalMilliseconds = elapsedTime.TotalMilliseconds; if (elapsedTimeTotalMilliseconds < nextDataPointTimeMilliseconds) { return; } m_DataPacketIndex++; //int dataPointsAllCount = (int)Math.Round(elapsedTimeTotalMilliseconds / m_TimeIntervalBetweenTwoDataPointsMilliSeconds, MidpointRounding.AwayFromZero); int dataPointsAllCount = (int)(elapsedTimeTotalMilliseconds / m_TimeIntervalBetweenTwoDataPointsMilliSeconds); int dataPointsGeneratedCount = m_DataPointIndex + 1; int dataPointsToGenerateCount = dataPointsAllCount - dataPointsGeneratedCount; if (dataPointsToGenerateCount <= 0) { DebuggerBreak("dataPointsToGenerateCount = " + dataPointsToGenerateCount.ToString()); return; } bool useDataPointDouble = true; //bool useDataPointDouble = false; if (useDataPointDouble) { DataPointEx[] dataPoints = new DataPointEx[dataPointsToGenerateCount]; for (int i = 0; i < dataPoints.Length; i++) { double dataPointTimeMilliSeconds = m_AcquisitionOnRetentionTimeMilliSeconds + m_DataPointIndex * m_TimeIntervalBetweenTwoDataPointsMilliSeconds; double dataPoint = Util.GetDataPoint(m_AcquisitionOnRetentionTimeMinutes + m_DataPointIndex * m_TimeIntervalBetweenTwoDataPointsMinutes, m_Number); dataPoints[i] = new DataPointEx(dataPointTimeMilliSeconds, dataPoint); m_DataPointIndex++; } m_Channel.UpdateDataEx(dataPoints); // Send the new data to Chromeleon } else // long dataPoint { DataPointInt64[] dataPoints = new DataPointInt64[dataPointsToGenerateCount]; for (int i = 0; i < dataPoints.Length; i++) { long dataPointTimeNanoSeconds = Convert.ToInt64(m_AcquisitionOnRetentionTimeNanoSeconds + m_DataPointIndex * m_TimeIntervalBetweenTwoDataPointsNanoSeconds); long dataPoint = Convert.ToInt64(Util.GetDataPoint(m_AcquisitionOnRetentionTimeMinutes + m_DataPointIndex * m_TimeIntervalBetweenTwoDataPointsMinutes, m_Number)); dataPoints[i] = new DataPointInt64(dataPointTimeNanoSeconds, dataPoint); m_DataPointIndex++; } m_Channel.UpdateDataEx(dataPoints); // Send the new data to Chromeleon } }
private void CreateChart(bool anomalies) { Chart = null; Chart = new LineChart() { LineMode = LineMode.Spline, LabelTextSize = 0 }; Chart.Entries = DataRequest.Series.Select( (v, index) => new Microcharts.Entry(v.Value) { Label = v.Timestamp.ToString("MM/dd_HH:mm"), Color = anomalies ? DataPointEx.Any(x => x.Timestamp.ToString("MM/dd_HH:mm") == v.Timestamp.ToString("MM/dd_HH:mm")) ? SKColors.Red : SKColors.Green : SKColors.Green, }); }
private void OnTimedEvent(object source, ElapsedEventArgs args) { if (m_GotDataFinished) { HandleTimer(); return; } // we use the timer to update our data. TimeSpan elapsedTime = DateTime.UtcNow - m_AcquisitionOnTime; if (elapsedTime.TotalMilliseconds > m_DataPointInterval.TotalMilliseconds * (m_PacketIndex + 1)) { // create as many data points as necessary Int32 numberOfDataPointsToGenerate = Convert.ToInt32((elapsedTime.TotalMilliseconds - m_DataPointInterval.TotalMilliseconds * (m_DataIndex + 1)) / m_DataPointInterval.TotalMilliseconds); m_DataPacket = new DataPointEx[numberOfDataPointsToGenerate]; for (int i = 0; i < numberOfDataPointsToGenerate; i++) { // in minutes double dCurrentTime = m_AcquisitionOnRetention + (double)m_DataIndex / m_RateProperty.Value.Value / 60.0; m_ChannelTimeProperty.Update(dCurrentTime); // timestamp is sent in ms double timestamp = m_AcquisitionOnRetention * 60.0 * 1000.0 + (double)m_DataIndex * 1000.0 / (m_RateProperty.Value.Value); m_DataPacket[i] = new DataPointEx(timestamp, ChannelTestDriver.CurrentDataValue(dCurrentTime)); m_DataIndex++; } // update the total number of data points already acquired m_DataIndexProperty.Update(m_DataIndex); m_PacketIndex++; m_MyCmDevice.UpdateDataEx(m_DataPacket); } HandleTimer(); }