/// <summary>
        /// Convert the data stream values retrieved from the VCU to a format that can be plotted by the <c>FormViewDataStream</c> class.
        /// </summary>
        /// <remarks>
        /// The value array retrieved by from the VCU is initially mapped to the WatchIdentifierList property of Column[0] of the workset, however, the WatchElement
        /// array associated with each frame must be mapped to the WatchElementList property of the workset.
        /// </remarks>
        /// <param name="startTime">The start time of the fault log.</param>
        /// <param name="sampleCount">The number of samples in the data stream.</param>
        /// <param name="frameIntervalMs">The interval, in ms, between consecutive data frames.</param>
        /// <param name="values">The point values corresponding to each variable.</param>
        /// <param name="dataTypes">The data types associated with each value.</param>
        /// <param name="workset">The workset that is to be used to define the output format.</param>
        /// <returns>The watch variable values in the format that can be plotted by the <c>FormViewDataStream</c> class.</returns>
        /// <exception cref="ArgumentException">Thrown if one or more of the the watch identifiers defined in the WatchElementList property of the workset does nor exist.</exception>
        private List<WatchFrame_t> ConvertToWatchFrameList(DateTime startTime, short sampleCount, short frameIntervalMs, int[] values, short[] dataTypes, Workset_t workset)
        {
            Debug.Assert(sampleCount > 1, "CommunicationEvent.ConvertToWatchFrameList() - [pointCount > 1]");
            Debug.Assert(frameIntervalMs > 0, "CommunicationEvent.ConvertToWatchFrameList() - [frameIntervalMs > 0");
            Debug.Assert(values != null, "CommunicationEvent.ConvertToWatchFrameList() - [values != null]");
            Debug.Assert(dataTypes != null, "CommunicationEvent.ConvertToWatchFrameList() - [dataTypes != null]");

            short watchCount = (short)workset.WatchElementList.Count;

            // Create a look-up array to translate the watch variable data retrieved from the VCU to the order defined by the WatchElementList property of the workset.
            short[] translate = new short[watchCount];
            short watchIdentifier, rowIndex, columnIndex;
            WatchVariable watchVariable;
            for (short watchElementIndex = 0; watchElementIndex < watchCount; watchElementIndex++)
            {
                watchIdentifier = workset.WatchElementList[watchElementIndex];
                try
                {
                    watchVariable = Lookup.WatchVariableTable.Items[watchIdentifier];
                    if (watchVariable == null)
                    {
                        throw new ArgumentException(Resources.MBTWatchVariableNotDefined);
                    }
                }
                catch (Exception)
                {
                    throw new ArgumentException(Resources.MBTWatchVariableNotDefined);
                }

                workset.GetWatchVariableLocation(watchVariable.OldIdentifier, out columnIndex, out rowIndex);
                Debug.Assert(((columnIndex != CommonConstants.NotFound) && (rowIndex != CommonConstants.NotFound)), "CommunicationEvent.ConvertToWatchFrameList() - [((columnIndex != 0) || (rowIndex != CommonConstants.NotFound))]");

                translate[watchElementIndex] = rowIndex;
            }

            // Translate the values of the watch variables retrieved from the VCU to a list of watch frames.
            List<WatchFrame_t> watchFrameList = new List<WatchFrame_t>();
            WatchFrame_t watchFrame;
            WatchElement_t watchElement;
            for (int frameIndex = 0; frameIndex < sampleCount; frameIndex++)
            {
                watchFrame = new WatchFrame_t();
                watchFrame.CurrentDateTime = startTime.AddMilliseconds(frameIndex * frameIntervalMs);
                watchFrame.WatchElements = new WatchElement_t[watchCount];
                for (short watchElementIndex = 0; watchElementIndex < watchCount; watchElementIndex++)
                {
                    watchElement = new WatchElement_t();
                    watchElement.ElementIndex = watchElementIndex;
                    watchElement.WatchIdentifier = workset.WatchElementList[watchElementIndex];
                    watchElement.DataType = dataTypes[translate[watchElementIndex]];
                    watchElement.Value = (double)values[(frameIndex * watchCount) + translate[watchElementIndex]];
                    watchFrame.WatchElements[watchElementIndex] = watchElement;
                }
                watchFrameList.Add(watchFrame);
            }
            return watchFrameList;
        }
Пример #2
0
        /// <summary>
        /// Retrieve the watch elements from the target hardware.
        /// </summary>
        /// <remarks>The watch elements are the watch values that are being monitored by the target hardware as defined by the 
        /// <c>SetWatchElements()> method.</c></remarks>
        /// <returns>The retrieved watch element table, if successful; otherwise, null.</returns>
        /// <exception cref="CommunicationException">Thrown if the error code returned from the call to the VcuCommunication32/VcuCommunication64
        /// UpdateElements() method is not CommunicationError.Success.</exception>
        public WatchElement_t[] UpdateWatchElements(bool forceUpdate)
        {
            Debug.Assert(m_UpdateWatchElements != null, "CommunicationWatch.UpdateWatchElements() - [m_UpdateWatchElementsDelegate != null]");
            Debug.Assert(m_MutexCommuncationInterface != null, "CommunicationWatch.UpdateWatchElements() - [m_MutexCommuncationInterface != null]");

            WatchElement_t[] watchElements = new WatchElement_t[Parameter.WatchSize];
            double[] watchValues = new double[Parameter.WatchSize];
            short[] watchDataTypes = new short[Parameter.WatchSize];

            short forceUpdateAsShort = (forceUpdate == true) ? ForceUpdateTrue : ForceUpdateFalse;
            CommunicationError errorCode = CommunicationError.UnknownError;
            try
            {
                m_MutexCommuncationInterface.WaitOne(DefaultMutexWaitDurationMs, false);
                errorCode = (CommunicationError)m_UpdateWatchElements(forceUpdateAsShort, watchValues, watchDataTypes);
            }
            catch (Exception)
            {
                errorCode = CommunicationError.SystemException;
                throw new CommunicationException(Resources.EMUpdateWatchElementsFailed, errorCode);
            }
            finally
            {
                m_MutexCommuncationInterface.ReleaseMutex();
            }

            if (DebugMode.Enabled == true)
            {
                DebugMode.UpdateWatchElements_t updateWatchElements = new DebugMode.UpdateWatchElements_t(forceUpdateAsShort, watchValues,
                                                                                                          watchDataTypes, errorCode);
                DebugMode.Write(updateWatchElements.ToXML());
            }

            if (errorCode != CommunicationError.Success)
            {
                throw new CommunicationException(Resources.EMUpdateWatchElementsFailed, errorCode);
            }

            // Map the values retrieved from the target hardware into the watch element table.
            for (short elementIndex = 0; elementIndex < Parameter.WatchSize; elementIndex++)
            {
                watchElements[elementIndex] = new WatchElement_t();
                watchElements[elementIndex].Value = watchValues[elementIndex];
                watchElements[elementIndex].DataType = watchDataTypes[elementIndex];
                watchElements[elementIndex].WatchIdentifier = m_WatchElements[elementIndex].WatchIdentifier;
                watchElements[elementIndex].ElementIndex = elementIndex;
            }
            return watchElements;
        }
Пример #3
0
        /// <summary>
        /// Update the watch variable lookup table with the latest watch element data retrieved from the targer hardware.
        /// </summary>
        /// <param name="watchElements">The watch element table retrieved from the target hardware.</param>
        public void UpdateWatchVariableTable(WatchElement_t[] watchElements)
        {
            short watchIdentifier;
            for (int elementIndex = 0; elementIndex < watchElements.Length; elementIndex++)
            {
                watchIdentifier = watchElements[elementIndex].WatchIdentifier;

                try
                {
                    Lookup.WatchVariableTable.Items[watchIdentifier].ValueFromTarget = watchElements[elementIndex].Value;
                    Lookup.WatchVariableTable.Items[watchIdentifier].DataTypeFromTarget = watchElements[elementIndex].DataType;
                }
                catch (Exception)
                {
                    continue;
                }
            }
        }
        /// <summary>
        /// Retrieve the watch elements from the target hardware.
        /// </summary>
        /// <remarks>The watch elements are the watch values that are being monitored by the target hardware as defined by the <c>SetWatchElements()
        /// </c> method.</remarks>
        /// <returns>The retrieved watch element table, if successful; otherwise, null.</returns>
        /// <exception cref="CommunicationException">Thrown if the error code returned from the call to the PTUDLL32.UpdateElements() method is not
        /// CommunicationError.Success.</exception>
        public WatchElement_t[] UpdateWatchElements(bool forceUpdate)
        {
            WatchElement_t[] watchElements = new WatchElement_t[Parameter.WatchSize];

            double[] watchValues = new double[Parameter.WatchSize];
            short[] watchDataTypes = new short[Parameter.WatchSize];

            // Initialize the data values and data types.
            WatchVariable watchVariable;
            for (int elementIndex = 0; elementIndex < Parameter.WatchSize; elementIndex++)
            {
                try
                {
                    watchVariable = Lookup.WatchVariableTable.Items[m_WatchElements[elementIndex].WatchIdentifier];
                    if (watchVariable == null)
                    {
                        throw new Exception();
                    }
                    watchValues[elementIndex] = watchVariable.ValueFromTarget;
                    watchDataTypes[elementIndex] = watchVariable.DataTypeFromTarget;
                }
                catch (Exception)
                {
                    watchValues[elementIndex] = 0;
                    watchDataTypes[elementIndex] = 0;
                }
            }

            // Map the values retrieved from the target hardware into the watch element table.
            for (short elementIndex = 0; elementIndex < Parameter.WatchSize; elementIndex++)
            {
                watchElements[elementIndex] = new WatchElement_t();
                watchElements[elementIndex].Value = watchValues[elementIndex];
                watchElements[elementIndex].DataType = watchDataTypes[elementIndex];
                watchElements[elementIndex].WatchIdentifier = m_WatchElements[elementIndex].WatchIdentifier;
                watchElements[elementIndex].ElementIndex = elementIndex;
            }

            return watchElements;
        }