/// <summary>
        /// Get the fault log/snapshot log data stream corresponding to the specified record.
        /// </summary>
        /// <param name="eventRecord">The event record associated with the data stream that is to be downloaded.</param>
        /// <returns>The data stream corresponding to the specified event record.</returns>
        /// <exception cref="CommunicationException">Thrown if the error code returned from the calls to the PTUDLL32.GetStreamInformation() or PTUDLL32Event.GetStream()
        /// methods is not CommunicationError.Success.</exception>
        public DataStream_t GetStream(EventRecord eventRecord)
        {
            short watchVariableCount, sampleCount, sampleMultiple;
            short[] watchIdentifiers, dataTypes;
            GetStreamInformation(0, out watchVariableCount, out sampleCount, out sampleMultiple, out watchIdentifiers, out dataTypes);

            int[] buffer = new int[sampleCount * watchVariableCount];   // Default values are all zeroes.

            // Not used by the calling class.
            // short timeOrigin = 0;

            Workset_t workset = ConvertToWorkset(eventRecord.Description, watchIdentifiers, sampleMultiple);
            DataStream_t dataStream = new DataStream_t(eventRecord, watchVariableCount, sampleCount, sampleMultiple, workset);

            DateTime startTime = eventRecord.DateTime.Subtract(new TimeSpan(0, 0, 0, 0, dataStream.DurationPreTripMs));

            // Convert the retrieved data stream into a list of individual, time-stamped watch variable data frames.
            List<WatchFrame_t> watchFrameList = ConvertToWatchFrameList(startTime, sampleCount, dataStream.FrameIntervalMs, buffer, dataTypes, workset);

            dataStream.WatchFrameList = watchFrameList;

            // Configure the upper and lower display limits.
            dataStream.ConfigureAutoScale();
#if NODELAY
#else
            // Include a delay to provide verisimilitude.
            System.Threading.Thread.Sleep(SleepMsVerisimilitudeGetStream);
#endif
            return dataStream;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Get the fault log/snapshot log data stream corresponding to the specified record.
        /// </summary>
        /// <param name="eventRecord">The event record associated with the data stream that is to be downloaded.</param>
        /// <returns>The data stream corresponding to the specified event record.</returns>
        /// <exception cref="CommunicationException">Thrown if the error code returned from the calls to the PTUDLL32.GetStreamInformation() or PTUDLL32Event.GetStream() 
        /// methods is not CommunicationError.Success.</exception>
        public DataStream_t GetStream(EventRecord eventRecord)
        {
            // Check that the function delegate has been initialized.
            Debug.Assert(m_GetStream != null, "CommunicationEvent.GetStream() - [m_GetStream != null]");
            Debug.Assert(m_MutexCommuncationInterface != null, "CommunicationEvent.GetStream() - [m_MutexCommuncationInterface != null]");

            Debug.Assert(eventRecord.StreamSaved == true, "CommuncationEvent.GetStream() - [eventRecord.StreamSaved == true]");
            Debug.Assert(eventRecord.StreamNumber != CommonConstants.NotUsed,
                         "CommuncationEvent.GetStream() - [eventRecord.StreamNumber != CommonConstants.NotUsed]");

            short watchCount, sampleCount, sampleMultiple;
            short[] watchIdentifiers, dataTypes;

            GetStreamInformation(eventRecord.StreamNumber, out watchCount, out sampleCount, out sampleMultiple, out watchIdentifiers, out dataTypes);

            int[] buffer = new int[sampleCount * watchCount];
            short timeOrigin;

            CommunicationError errorCode = CommunicationError.UnknownError;
            try
            {
                m_MutexCommuncationInterface.WaitOne(DefaultMutexWaitDurationMs, false);

                // TODO - CommunicationEvent.GetStream(). Check on the significance of the timeOrigin parameter in the GetStream() method.
                errorCode = (CommunicationError)m_GetStream(eventRecord.StreamNumber, buffer, out timeOrigin, watchCount, sampleCount, dataTypes);
            }
            catch (Exception)
            {
                errorCode = CommunicationError.SystemException;
                throw new CommunicationException("CommunicationEvent.GetStream()", errorCode);
            }
            finally
            {
                m_MutexCommuncationInterface.ReleaseMutex();
            }

            if (DebugMode.Enabled == true)
            {
                DebugMode.GetStream_t getStream = new DebugMode.GetStream_t(eventRecord.StreamNumber, buffer, timeOrigin, watchCount,
                                                                            sampleCount, dataTypes, errorCode);
                DebugMode.Write(getStream.ToXML());
            }

            if (errorCode != CommunicationError.Success)
            {
                throw new CommunicationException("CommunicationEvent.GetStream()", errorCode);
            }

            Workset_t workset = ConvertToWorkset(eventRecord.Description, watchIdentifiers, sampleMultiple);
            DataStream_t dataStream = new DataStream_t(eventRecord, watchCount, sampleCount, sampleMultiple, workset);

            DateTime startTime = eventRecord.DateTime.Subtract(new TimeSpan(0, 0, 0, 0, dataStream.DurationPreTripMs));

            // Convert the retrieved data stream into a list of individual, time-stamped watch variable data frames.
            List<WatchFrame_t> watchFrameList = ConvertToWatchFrameList(startTime, sampleCount, dataStream.FrameIntervalMs, buffer, dataTypes,
                                                                        workset);

            dataStream.WatchFrameList = watchFrameList;

            // Configure the upper and lower display limits.
            dataStream.ConfigureAutoScale();

            return dataStream;
        }