Beispiel #1
0
 internal DataToVisualize(TelegramHead telHead, MeasuredHead measuredHead, MeasuredData measuredData,
                          double convTime, double saveTime)
 {
     m_telHead      = telHead;
     m_measuredHead = measuredHead;
     m_measuredData = measuredData;
     m_convTimeSpan = convTime;
     m_saveTimeSpan = saveTime;
 }
Beispiel #2
0
        /// <summary>  sets the value delivered from ondatachange </summary>
        /// <param name="theValue"> the value (must be byte array) </param>
        /// <exception cref="InvalidCastException"> if the value cannot be converted into a byte array </exception>
        /// <remarks> NOTES:
        /// - this methods measures the time for converting and saving to DB
        /// - it is recommended to call this method asynchronously, because saving to DB may take several seconds </remarks>
        public void setOPCParam(object theValue)
        {
            TelegramHead telHead      = null;
            MeasuredHead measHeadVisu = null;
            MeasuredData measDataVisu = null;

            // Take time for converting
            StopWatch convStopWatch = new StopWatch(TimerType.PerformanceCounter);

            convStopWatch.Scale = 1000.0;
            convStopWatch.Start();

            // Take time for saving
            StopWatch saveStopWatch = new StopWatch(TimerType.PerformanceCounter);

            saveStopWatch.Scale = 1000.0;

            // Convert data
            S7DataConverter theData;

            byte[] data = null;
            try
            {
                data    = (byte[])theValue;
                theData = new S7DataConverter(data, true, true);
            }
            catch (InvalidCastException ex)
            {
                // forward the exception
                throw ex;
            }

            int offset = 0;

            // read telegram-header
            telHead = readOutTelegramHead(theData, data.Length, ref offset);

            // read out data
            readOutData(theData, telHead.telNumberRecords, ref offset, out measHeadVisu, out measDataVisu);
            convStopWatch.Stop();

            // Now save update the database
            try
            {
                saveStopWatch.Start();
                int idx = (int)m_ActiveDB;
                if (idx != 0)
                {
                    ((DBInterface)(m_dataBases[idx])).Insert();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                saveStopWatch.Stop();

                // Fill the data for visualization
                DataToVisualize dataToVisu = new DataToVisualize(telHead, measHeadVisu, measDataVisu,
                                                                 convStopWatch.Time, saveStopWatch.Time);

                // fire the event, that saving is completed
                OnBRCVOccured(this, dataToVisu);
            }
        }