Beispiel #1
0
        /// <summary>
        /// Event handler for the on-line button <c>Click</c> event. Initializes the communication port specified in the <c>Communication</c> project user settings 
        /// and, if successful: (a) updates the mode setting and then (b) displays the form to show the live watch variable data.
        /// </summary>
        /// <param name="sender">Reference to the object that raised the event.</param>
        /// <param name="e">Parameter passed from the object that raised the event.</param>
        private void m_TSBOnline_Click(object sender, EventArgs e)
        {
            // Skip, if the Dispose() method has been called.
            if (IsDisposed)
            {
                return;
            }

            // Skip, if the button isn't enabled.
            if (m_TSBOnline.Enabled == false)
            {
                return;
            }

            // If online mode is already selected, toggle to configuration mode.
            if (m_TSBOnline.Checked)
            {
                #region - [Return to Configuration Mode] -
                // -------------------------------------------------------
                // The PTU is already online, go to configuration mode.
                // -------------------------------------------------------
				try
				{
					this.Cursor = Cursors.WaitCursor;
					CommunicationInterface.CloseCommunication(CommunicationInterface.CommunicationSetting.Protocol);
				}
				catch (CommunicationException ex)
				{
					// Check to see if it's a failure to close, which we can potentially ignore.
					if (ex.CommunicationError != CommunicationError.SystemException)
					{
						// This is a recoverable error, so we allow the port to stay open, but display the error.
						MessageBox.Show(Resources.MBTPortCloseFailed, Resources.MBCaptionError, MessageBoxButtons.OK, MessageBoxIcon.Error);
					}
					else
					{
						MessageBox.Show(Resources.MBTPortCloseFailed, Resources.MBCaptionError, MessageBoxButtons.OK, MessageBoxIcon.Error);
						return;
					}
				}
				catch (Exception)
				{
					MessageBox.Show(Resources.MBTPortCloseFailed, Resources.MBCaptionError, MessageBoxButtons.OK, MessageBoxIcon.Error);
					return;
				}
                finally
                {
                    this.Cursor = Cursors.Default;
                }

                SetMode(Mode.Configuration);

                // Update the LogStatus StatusStrip.
                LogStatus = EventLogSavedStatus.NotApplicable;
                #endregion -[Return to Configuration Mode] -
                return;
            }

            // ---------------------------------------------------------
            // Show the form to allow the user to select a valid target.
            // ---------------------------------------------------------
            this.Cursor = Cursors.WaitCursor;
            FormSelectTarget formSelectTarget = new FormSelectTarget();
            ShowDialog(formSelectTarget);
            this.Cursor = Cursors.WaitCursor;

            // Skip, if no target logic was selected.
            if (formSelectTarget.TargetSelected != true)
            {
                this.Cursor = Cursors.Default;
                return;
            }

            // -------------------------------------------------------------------------------------------------
            // A valid target was selected, check that the PTU configuration and the target configuration match.
            // -------------------------------------------------------------------------------------------------
            bool configurationMatch = CheckConfiguration(formSelectTarget.TargetConfiguration.ProjectIdentifier, formSelectTarget.TargetConfiguration.Version);
            if (configurationMatch == true)
            {
                #region - [Go Online] -
                // -------------------------------------------------------------------
                // PTU configuration and target configuration match, enter online mode.
                // -------------------------------------------------------------------
                CommunicationInterface = new CommunicationParent(formSelectTarget.CommunicationSetting);
                Debug.Assert(CommunicationInterface != null);

                try
                {
                    // Initialize the serial communications port associated with the selected target.
                    CommunicationInterface.InitCommunication(CommunicationInterface.CommunicationSetting);
                }
                catch (InvalidOperationException)
                {
                    // An error occurred trying to initialize the communication port, do not enter online mode.
                    CommunicationInterface = null;
                    this.Cursor = Cursors.Default;
                    MessageBox.Show(Resources.MBTPortInitializationFailed, Resources.MBCaptionError, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                // Update the header information with the target configuration.
                Header_t header = new Header_t();
                header = FileHeader.HeaderCurrent;
                header.TargetConfiguration = formSelectTarget.TargetConfiguration;
                FileHeader.HeaderCurrent = header;

                SetMode(Mode.Online);

                // Check whether the most recently downloaded event log was saved to disk and update the LogStatus StatusStrip.
                LogStatus = EventLogSavedStatus.Unknown;

                UpdateChartMode();

                // Display the Watch Window only if the project doesn't use a Control Panel.
                if (this.Controls[CommonConstants.KeyControlPanel] == null)
                {
                    m_MenuInterfaceWatch.ViewWatchWindow();
                }
                #endregion - [Go Online] -
            }
            this.Cursor = Cursors.Default;
        }
Beispiel #2
0
        /// <summary>
        /// Initializes the class properties to the parameter values contained within the specified configuration file. If any configuration file
        /// parameters are invalid all properties associated with the table to which the parameter belongs will be left at their default values.
        /// </summary>
        /// <param name="dataDictionary">The <c>DataSet</c> corresponding to the current data dictionary.</param>
        public static void Initialize(DataDictionary dataDictionary)
        {
            // Set the data dictionary defined properties to their default values.
            SetToDefault();

            // Now overlay the values defined in the data dictionary. If an exception is thrown the properties will be left in their default state.

            // --------------------
            // Function Flags
            // --------------------
            try
            {
                m_FunctionFlags = dataDictionary.CONFIGUREPTU[0].FunctionFlags;
                m_Use4DigitYearCode = ((m_FunctionFlags & CommonConstants.MaskBit0) == CommonConstants.MaskBit0) ? true : false;
                m_ShowLogName = ((m_FunctionFlags & CommonConstants.MaskBit1) == CommonConstants.MaskBit1) ? true : false;
            }
            catch (Exception)
            {
                // Use the default values set up by the static constructor instead.
            }

            // --------------------
            // Recorded Watch Data
            // --------------------
            try
            {
                m_WatchSize = dataDictionary.CONFIGUREPTU[0].WatchSize;
                short watchReturn = (short)CommunicationError.UnknownError;

                // Inform the VcuCommunication32/VcuCommunication64 dynamic link library of the number of watch variables that are associated with the
                // project.
                CommunicationParent communicationInterface = new CommunicationParent();
                watchReturn = communicationInterface.SetWatchSize(m_WatchSize);
                communicationInterface = null;

                if (watchReturn != m_WatchSize)
                {
                    // Use the returned value.
                    m_WatchSize = watchReturn;

                    MessageBox.Show(Resources.MBTWatchSizeInvalid, Resources.MBCaptionWarning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            catch (System.EntryPointNotFoundException)
            {
                MessageBox.Show(Resources.MBTSetWatchSizeNotSupported, Resources.MBCaptionWarning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            catch (Exception)
            {
                // Use the default values set up by the static constructor instead.
            }

            // --------------------
            // Fault Log WatchSize
            // --------------------
            try
            {
                // Scan the number of watch variables that are recorded by each event log and determine the maximum.
                short watchVariablesMax = 0;
                short watchVariablesPrev = 0;
                short watchVariableCurrent;
                bool firstPass = true;
                m_SupportsMultipleDataStreamTypes = false;
                for (short recordIndex = 0; recordIndex < dataDictionary.LOGS.Count; recordIndex++)
                {
                    watchVariableCurrent = dataDictionary.DataStreamTypes[dataDictionary.LOGS[recordIndex].DataStreamTypeIdentifier].WatchVariablesMax;

                    if (firstPass == true)
                    {
                        watchVariablesMax = watchVariableCurrent;
                        watchVariablesPrev = watchVariableCurrent;
                        firstPass = false;
                    }
                    else
                    {
                        if (watchVariableCurrent > watchVariablesMax)
                        {
                            watchVariablesMax = watchVariableCurrent;
                        }

                        if (watchVariableCurrent != watchVariablesPrev)
                        {
                            m_SupportsMultipleDataStreamTypes = true;
                        }
                    }
                }

                m_WatchSizeFaultLog = watchVariablesMax;
            }
            catch (Exception)
            {
                // Use the default values set up by the static constructor instead.
            }

            // --------------------
            // Project Information
            // --------------------
            try
            {
                m_ProjectInformation.DataDictionaryName = dataDictionary.FILEINFO[0].DDNAME;
                m_ProjectInformation.ProjectIdentifier = dataDictionary.FILEINFO[0].PROJECTSTRING;
                m_ProjectInformation.Version = dataDictionary.FILEINFO[0].VERSION;
                m_ProjectInformation.DataDictionaryBuilderVersion = dataDictionary.FILEINFO[0].DDBVersion;
                m_ProjectInformation.WatchIdentifierCount = dataDictionary.FILEINFO[0].NUMOFVARS;
            }
            catch (Exception)
            {
                // Use the default values set up by the static constructor instead.
            }

            // ----------------------
            // WibuBox Parameters
            // ----------------------
            try
            {
                m_WibuBox.FirmCode = dataDictionary.CONFIGUREPTU[0].FIRMCODE;
                m_WibuBox.UserCode = dataDictionary.CONFIGUREPTU[0].USERCODE;
                m_WibuBox.SlotId = dataDictionary.CONFIGUREPTU[0].SLOTID;
                m_WibuBox.PortId = dataDictionary.CONFIGUREPTU[0].PORTID;
            }
            catch(Exception)
            {
                // Use the default values set up by the static constructor instead.
            }

            // ----------------------
            // Application Data Path
            // ----------------------
            try
            {
                m_PathPTUApplicationData = dataDictionary.CONFIGUREPTU[0].ApplicationDataPath;
            }
            catch (Exception)
            {
                // Use the default values set up by the static constructor instead.
            }

            // --------
            // Security
            // --------
            try
            {
                m_SecurityConfiguration.DescriptionLevel0 = dataDictionary.Security[0].DescriptionLevel0;
                m_SecurityConfiguration.DescriptionLevel1 = dataDictionary.Security[0].DescriptionLevel1;
                m_SecurityConfiguration.DescriptionLevel2 = dataDictionary.Security[0].DescriptionLevel2;
                m_SecurityConfiguration.DescriptionLevel3 = dataDictionary.Security[0].DescriptionLevel3;
                m_SecurityConfiguration.SecurityLevelBase = (SecurityLevel)dataDictionary.Security[0].SecurityLevelBase;
                m_SecurityConfiguration.SecurityLevelHighest = (SecurityLevel)dataDictionary.Security[0].SecurityLevelHighest;
            }
            catch (Exception)
            {
                // Use the default values set up by the static constructor instead.
            }

            // ----------------------
            // Communication Variables
            // ----------------------
            try
            {
                //DAS m_CommunicationType = (CommunicationTypeEnum)dataDictionary.CONFIGUREPTU[0].CommunicationType;
            }
            catch (Exception)
            {
                // Use the default values set up by the static constructor instead.
            }

            try
            {
                m_URIList = new List<string>(dataDictionary.URI.Count);
                foreach (System.Data.DataRow dataRow in dataDictionary.URI.Rows)
                {
                    string URI = (string)dataRow.ItemArray[1];
                    if (URI.Length > 0)
                    {
                        m_URIList.Add(URI);
                    }
                }
            }
            catch (Exception)
            {
                // Use the default values set up by the static constructor instead.
            }
        }