Ejemplo n.º 1
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);
        }
Ejemplo n.º 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;
        }