private void TimedEventArbitrary(Object source, ElapsedEventArgs e) { DateTime now = DateTime.Now; TimeSpan timeSincelatestCall = now - m_lastestEventCall; TimeSpan timeSinceAcqStart = now - m_startDateTime; double timeSincePrevCall = timeSincelatestCall.TotalSeconds; int noOfPointsToSend = Convert.ToInt32(timeSincePrevCall * m_dcr.Value); if (noOfPointsToSend <= 0) { Debug.WriteLine(String.Format("Nothing to send: {0:f1} ns", timeSincePrevCall)); return; } m_lastestEventCall = now; DataPointInt64[] data = new DataPointInt64[noOfPointsToSend]; double startTimeThisPackage = m_startTime + (timeSinceAcqStart.TotalMilliseconds - timeSincelatestCall.TotalMilliseconds) * 1.0E6; for (int i = 0; i < noOfPointsToSend; i++) { double currentTime = startTimeThisPackage + (timeSincelatestCall.TotalMilliseconds * i * 1.0E6) / noOfPointsToSend; data[i] = new DataPointInt64(Convert.ToInt64(currentTime), Convert.ToInt64(DemoSignal(currentTime))); m_totalDataIdx++; } Trace.WriteLine(String.Format("First Point: {0:f3}, Value {1:f3}, Total: {2:d}", data[0].Retention, data[0].Data, m_totalDataIdx)); Trace.WriteLine(String.Format("Last Point : {0:f3}, Value {1:f3}, Total: {2:d}", data[noOfPointsToSend - 1].Retention, data[noOfPointsToSend - 1].Data, m_totalDataIdx)); // Send the new data to Chromeleon m_MyCmDevice.UpdateDataEx(data); }
private void TimedEventRegular(Object source, ElapsedEventArgs e) { // we use the timer to update our data // the timer occurs each second. TimeSpan timeSinceAcqStart = DateTime.Now - m_startDateTime; int actNoOfPoints = Convert.ToInt32(timeSinceAcqStart.TotalSeconds * m_dcr.Value); int dataToBeSent = actNoOfPoints - m_totalDataIdx; if (dataToBeSent <= 0) { return; } DataPointInt64[] data = new DataPointInt64[dataToBeSent]; for (int i = 0; i < dataToBeSent; i++) { double currentTime = m_startTime + m_totalDataIdx * 1.0E9 / m_dcr.Value.Value; // current retention time in ns data[i] = new DataPointInt64(Convert.ToInt64(currentTime), Convert.ToInt64(DemoSignal(currentTime))); m_totalDataIdx++; } Trace.WriteLine(String.Format("First Point: {0:f3}, Value {1:f3}, Total: {2:d}", data[0].Retention, data[0].Data, m_totalDataIdx)); Trace.WriteLine(String.Format("Last Point : {0:f3}, Value {1:f3}, Total: {2:d}", data[dataToBeSent - 1].Retention, data[dataToBeSent - 1].Data, m_totalDataIdx)); // Send the new data to Chromeleon m_MyCmDevice.UpdateDataEx(data); }
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 OnTimedEvent(object source, ElapsedEventArgs args) { // we use the timer to update our data. if (m_GotDataFinished) { HandleTimer(); return; } 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 DataPointInt64[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 ns double timestamp = m_AcquisitionOnRetention * 60.0 * 1.0E9 + (double)m_DataIndex * 1.0E9 / (m_RateProperty.Value.Value); m_DataPacket[i] = new DataPointInt64(Convert.ToInt64(timestamp), Convert.ToInt64(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(); }