Пример #1
0
        /// <summary>
        /// Event handler for the OK button <c>Click</c> event. Updates the properties with the selected target logic and communication settings.
        /// </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_BtnOK_Click(object sender, EventArgs e)
        {

            if (m_ListBoxAvailableLogicControllers.SelectedItems.Count == 0)
            {
                // No target was selected.
                MessageBox.Show(Resources.MBTSelectTarget, Resources.MBCaptionInformation, MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            int selectedLogic = m_ListBoxAvailableLogicControllers.SelectedIndex;
            m_TargetSelected = true;

            m_TargetConfiguration = m_TargetConfigurationList[selectedLogic];
            m_CommunicationSetting = m_CommunicationSettingList[selectedLogic];
            Close();
        }
Пример #2
0
        /// <summary>
        /// Scans each of the communication ports listed in the registry to determine if it is connected to target hardware and generates a list
        /// of the target configuration information and the communication settings for each target that is located. 
        /// </summary>
        /// <param name="targetConfigurationList">The list containing the target configuration information for any targets connected to the PTU.</param>
        /// <param name="communicationSettingList">The communication settings associated with each target that was found.</param>
        /// <param name="listBoxTargetsFound">The <c>ListBox</c> control on which the target names are to be displayed.</param>
        /// <param name="statusInformation">The control on which the status information is to be displayed.</param>
        /// <returns>A flag to indicate whether one or more targets were found; true, if  targets were found, otherwise, false.</returns>
        public bool GetTargets(ListBox listBoxTargetsFound, Control statusInformation,  out List<TargetConfiguration_t> targetConfigurationList,
                               out List<CommunicationSetting_t> communicationSettingList)
        {
            // Instantiate to output parameters.
            communicationSettingList = new List<CommunicationSetting_t>();
            targetConfigurationList = new List<TargetConfiguration_t>();

            CommunicationApplication communicationInterface;

            // Flag to indicate whether target hardware was found; true, if one or more targets were found, otherwise, false.
            bool targetFound = false;

			if (Parameter.CommunicationType == Parameter.CommunicationTypeEnum.Both || Parameter.CommunicationType == Parameter.CommunicationTypeEnum.RS232)
			{

				// -----------------------------------------------------------------
				// Scan each serial communication (COM) port listed in the Registry.
				// -----------------------------------------------------------------

				// Get the list of available serial COM ports from the registry.
				RegistryKey root = Registry.LocalMachine;
				CommunicationSetting_t communicationSetting = new CommunicationSetting_t();

				// Set the protocol to serial communication.
				communicationSetting.Protocol = Protocol.RS232;

				// Initialize the serial communication parameters.
				communicationSetting.SerialCommunicationParameters.SetToDefault();

				TargetConfiguration_t targetConfiguration;
				using (RegistryKey serialCommunication = root.OpenSubKey(RegistryKeySerialCommunication))
				{
					// Scan each port in the Registry.
					foreach (string valueName in serialCommunication.GetValueNames())
					{
						// Filter out those '\HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM' keys that are not to be included in the search.
						switch (valueName)
						{
							// Skip those registry keys defined here.
							case SerialCommRegistryKeyWinachsf0:
								continue;
							default:
								// Process the key.
								break;
						}

						string value = serialCommunication.GetValue(valueName).ToString();

						communicationSetting.Port.Name = value;
						communicationSetting.Port.FullSpecification = value.PadRight(ComDeviceTotalCharacters) + " - " + valueName;
						communicationSetting.Port.Type = (communicationSetting.Port.FullSpecification.Contains(VirtualComPort)) ? PortType.VCP : PortType.COM;

						// Determine the port identifier, this is a 16 bit Unicode string representation of the serial port number e.g. for physical and virtual
                        // COM ports this takes the form: 1, 2, 3 ... etc.
						switch (communicationSetting.Port.Type)
						{
							case PortType.COM:
							case PortType.VCP:
								communicationSetting.PortIdentifier = communicationSetting.Port.Name.Remove(0, communicationSetting.Port.Type.ToString().Length);
								break;
							default:
								throw new ArgumentException("FormSelectTargetLogic.LocateTargetHardware()", "communicationSetting.Port.Type");
						}

						statusInformation.Text = Resources.TextSearchingForTargetOn + CommonConstants.Space + communicationSetting.Port.FullSpecification;
						statusInformation.Update();

						// Instantiate the appropriate type of communication interface.
						communicationInterface = new CommunicationApplication();
						try
						{
							if (communicationInterface.ScanPort(communicationSetting, out targetConfiguration) == true)
							{
								targetConfigurationList.Add(targetConfiguration);
                                listBoxTargetsFound.Items.Add(targetConfiguration.SubSystemName + " - (COM" + communicationSetting.PortIdentifier + ")" );
								listBoxTargetsFound.Update();
								statusInformation.Text = Resources.TextTargetFoundOn + CommonConstants.Space + communicationSetting.Port.FullSpecification;
                                statusInformation.Update();
								communicationSettingList.Add(communicationSetting);
								targetFound = true;
							}
						}
						catch (Exception)
						{
							statusInformation.Text = Resources.TextNoTargetFoundOn + CommonConstants.Space + communicationSetting.Port.FullSpecification;
							statusInformation.Update();
							continue;
						}
					}
				}
			}

            statusInformation.Text = string.Empty;
            statusInformation.Update();

			if (Parameter.CommunicationType == Parameter.CommunicationTypeEnum.Both || Parameter.CommunicationType == Parameter.CommunicationTypeEnum.TCPIP)
			{

				// -----------------------------------------------------------------
				// Scan each URI listed in the Data Dictionary.
				// -----------------------------------------------------------------

				CommunicationSetting_t communicationSetting = new CommunicationSetting_t();

				// Set the protocol to IP communication.
				communicationSetting.Protocol = Protocol.TCPIP;

				TargetConfiguration_t targetConfiguration;

                // Initialize the ProgressBar control.
                m_ProgressBarScan.Enabled = true;
                m_ProgressBarScan.Visible = true;
                m_LegendScanProgress.Visible = true;
                m_ProgressBarScan.Maximum = Parameter.URIList.Count;
                m_ProgressBarScan.Value = 0;
                m_BtnOK.Enabled = false;
                m_CancelSelected = false;

				// Scan each port in the Registry.
				foreach (string uRI in Parameter.URIList)
				{
                    // Ensure that the form remains responsive during the asynchronous operation.
                    Application.DoEvents();

                    // Check whether the Cancel button has been selected.
                    if (m_CancelSelected == true)
				{
                        // Yes - Terminate the scan.
                        break;
                    }

                    // Update the progress bar.
                    m_ProgressBarScan.Value++;

					communicationSetting.PortIdentifier = uRI;

                    statusInformation.Text = Resources.TextSearchingForTargetOn + CommonConstants.Space + Resources.TextURI + CommonConstants.Colon +
                                             communicationSetting.PortIdentifier;
                    statusInformation.Update();

					// Instantiate the appropriate type of communication interface.
					communicationInterface = new CommunicationApplication();
					try
					{
						if (communicationInterface.ScanPort(communicationSetting, out targetConfiguration) == true)
						{
							targetConfigurationList.Add(targetConfiguration);
							listBoxTargetsFound.Items.Add(targetConfiguration.SubSystemName + CommonConstants.BindingMessage +
                                                          Resources.TextURI + CommonConstants.Colon + communicationSetting.PortIdentifier);
							listBoxTargetsFound.Update();
                            statusInformation.Text = Resources.TextTargetFoundOn + CommonConstants.Space + Resources.TextURI + CommonConstants.Colon +
                                                     communicationSetting.PortIdentifier;
                            statusInformation.Update();
							communicationSettingList.Add(communicationSetting);
							targetFound = true;
						}
					}
					catch (Exception)
					{
						continue;
					}
				}

                m_BtnOK.Enabled = true;
                m_ProgressBarScan.Enabled = false;
                m_ProgressBarScan.Visible = false;
                m_LegendScanProgress.Visible = false;
			}

            if (targetFound == true)
            {
                statusInformation.Text = targetConfigurationList.Count.ToString() + CommonConstants.Space + Resources.TextTargetsFound;
                statusInformation.Update();

                // Highlight the first logic controller that was found.
                listBoxTargetsFound.SetSelected(0, true);
            }
            else
            {
                statusInformation.Text = Resources.TextNoTargetsFound;
                statusInformation.Update();
            }

            return targetFound;
        }
Пример #3
0
 /// <summary>
 /// Initialize a new instance of the class and set the function delegates, properties and member variables.
 /// </summary>
 /// <param name="communicationInterface">Reference to the communication interface containing the properties and member variables that are to
 /// be used to initialize the class.</param>
 public CommunicationParent(ICommunicationParent communicationInterface)
     : this()
 {
     m_CommunicationSetting = communicationInterface.CommunicationSetting;
     m_CommDevice = communicationInterface.CommDevice;
     m_WatchClockMarshal = communicationInterface.WatchClockMarshall;
 }
Пример #4
0
        /// <summary>
        /// Initialize the communication port.
        /// </summary>
        /// <param name="communicationsSetting">The communication settings.</param>
        /// <exception cref="CommunicationException">Thrown if the error code returned from the call to the PTUDLL32.InitCommunication() method is
        /// not CommunicationError.Success.</exception>
        public virtual void InitCommunication(CommunicationSetting_t communicationsSetting)
        {
            Int32 error = -1;

            CommunicationError errorCode = CommunicationError.UnknownError;
            try
            {
                String args = "";

                if (communicationsSetting.Protocol == Protocol.RS232)
                {
                    m_CommDevice = new Serial();

                    args = "COM" + communicationsSetting.PortIdentifier + "," +
                            ((Int32)communicationsSetting.SerialCommunicationParameters.BaudRate).ToString() + "," + 
                            communicationsSetting.SerialCommunicationParameters.Parity.ToString() + "," + 
                            ((Int32)communicationsSetting.SerialCommunicationParameters.BitsPerCharacter).ToString() + "," +
                            ((Int32)communicationsSetting.SerialCommunicationParameters.StopBits).ToString();


                }
                else if (communicationsSetting.Protocol == Protocol.TCPIP)
                {
                    m_CommDevice = new TCP();
                    args = communicationsSetting.PortIdentifier;
                }

                if (m_CommDevice != null)
                {
                    error = m_CommDevice.Open(args);
                }
            }
            catch (Exception)
            {
                errorCode = CommunicationError.SystemException;
                throw new CommunicationException(Resources.EMPortInitializationFailed, errorCode);
            }

            if (DebugMode.Enabled == true)
            {
                DebugMode.InitCommunication_t initCommunication =
                    new DebugMode.InitCommunication_t(communicationsSetting.Protocol,
                                                      communicationsSetting.PortIdentifier,
                                                      communicationsSetting.SerialCommunicationParameters.BaudRate,
                                                      communicationsSetting.SerialCommunicationParameters.BitsPerCharacter,
                                                      communicationsSetting.SerialCommunicationParameters.Parity,
                                                      communicationsSetting.SerialCommunicationParameters.StopBits,
                                                      errorCode);
                DebugMode.Write(initCommunication.ToXML());
            }

            if (error >= 0)
            {
                errorCode = CommunicationError.Success;
                m_WatchClockMarshal = new WatchClockMarshal(m_CommDevice);
            }

            if (errorCode != CommunicationError.Success)
            {
                throw new CommunicationException(Resources.EMPortInitializationFailed, errorCode);
            }
        }
Пример #5
0
        /// <summary>
        /// Initialize a new instance of the class and set the function delegates, properties and member variables.
        /// </summary>
        public CommunicationParent()
        {
            // Random number generator, used to simulate communication values.
            m_Random = new Random();

            // Initialize the watch element array.
            m_WatchElements = new WatchElement_t[Parameter.WatchSize];

            m_CommunicationSetting = new CommunicationSetting_t();
            m_MutexCommuncationInterface = new Mutex();
        }
Пример #6
0
 /// <summary>
 /// Initialize a new instance of the class and set the function delegates, properties and member variables.
 /// </summary>
 /// <param name="communicationSetting">The communication setting that is to be used to initialize the <c>CommunicationSetting</c>
 /// property.</param>
 public CommunicationParent(CommunicationSetting_t communicationSetting)
     : this()
 {
     m_CommunicationSetting = communicationSetting;
 }
 /// <summary>
 /// Initialize the target hardware communication port.
 /// </summary>
 /// <param name="communicationsSetting">The communication settings.</param>
 /// <exception cref="CommunicationException">Thrown if the error code returned from the call to the PTUDLL32.InitCommunication() method is not
 /// CommunicationError.Success.</exception>
 public virtual void InitCommunication(CommunicationSetting_t communicationsSetting)
 {
 }
Пример #8
0
        /// <summary>
        /// Event handler for the off-line button <c>Click</c> event. Enter offline mode.
        /// </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_TSBOffline_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_TSBOffline.Enabled == false)
            {
                return;
            }

            // If offline mode is already selected, toggle to configuration mode.
            if (m_TSBOffline.Checked)
            {
                #region - [Return to Configuration Mode] -
                // -------------------------------------------------------
                // The PTU is already offline, go to configuration mode.
                // -------------------------------------------------------
                try
                {
                    this.Cursor = Cursors.WaitCursor;
                    CommunicationInterface.CloseCommunication(CommunicationInterface.CommunicationSetting.Protocol);
                }
                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;
            }

            this.Cursor = Cursors.WaitCursor;
            #region - [Go Offline] -
            // ---------------------------------------------------------------------------------------------
            // Enter offline mode. Instantiate a the communication interface which returns simulated values.
            // ---------------------------------------------------------------------------------------------
            CommunicationSetting_t communicationSetting = new CommunicationSetting_t();
            communicationSetting.Port = new Port_t();
            communicationSetting.PortIdentifier = string.Empty;
            communicationSetting.Protocol = Protocol.SIMULATOR;
            CommunicationInterface = new CommunicationParentOffline(communicationSetting);
            TargetConfiguration_t targetConfiguration;
            CommunicationInterface.GetEmbeddedInformation(out targetConfiguration);

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

            SetMode(Mode.Offline);

            // 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 Offline] -
            this.Cursor = Cursors.Default;
        }
        /// <summary>
        /// Initialize a new instance of the class.
        /// </summary>
        public CommunicationParentOffline()
        {
            // Initialize the watch element array.
            m_WatchElements = new WatchElement_t[Parameter.WatchSize];

            m_CommunicationSetting = new CommunicationSetting_t();
        }
        /// <summary>
        /// Initialize a new instance of the class and set the properties and member variables to those values associated with the specified
        /// communication interface.
        /// </summary>
        /// <param name="communicationInterface">Reference to the communication interface containing the properties and member variables that are to be
        /// used to initialize the class.</param>
        public CommunicationParentOffline(ICommunicationParent communicationInterface)
        {
            // Initialize the watch element array.
            m_WatchElements = new WatchElement_t[Parameter.WatchSize];

            m_CommunicationSetting = communicationInterface.CommunicationSetting;
        }
Пример #11
0
        /// <summary>
        /// Scan the specified serial communication port to determine if it is connected to a target logic controller. If a target is found
        /// the target configuration information is written to the output parameter <paramref name="targetConfiguration"/>.
        /// </summary>
        /// <param name="communicationSetting">The communication settings that are to be used to communicate with the target.</param>
        /// <param name="targetConfiguration">The target configuration information returned from the target hardware if a target is found.</param>
        /// <returns>A flag to indicate whether a target was found; true, if a target was found, otherwise, false.</returns>
        /// <exception cref="CommunicationException">Thrown if the error code returned from the call to the PTUDLL32.InitCommunication() method is not
        /// CommunicationError.Success.</exception>
        public bool ScanPort(CommunicationSetting_t communicationSetting, out TargetConfiguration_t targetConfiguration)
        {
            // Flag to indicate whether target hardware was found; true, if target was found, otherwise, false.
            bool targetFound = false;

            try
            {
                InitCommunication(communicationSetting);
                GetEmbeddedInformation(out targetConfiguration);
                targetFound = true;
            }
            catch (InvalidOperationException)
            {
                targetConfiguration = new TargetConfiguration_t();
                return targetFound;
            }
            finally
            {
                CloseCommunication(communicationSetting.Protocol);
            }

            return targetFound;
        }
Пример #12
0
 /// <summary>
 /// Initialize a new instance of the class and set the function delegates, properties and member variables.
 /// </summary>
 /// <param name="communicationInterface">Reference to the communication interface containing the properties and member variables that are to
 /// be used to initialize the class.</param>
 public CommunicationParent(ICommunicationParent communicationInterface)
     : this()
 {
     m_CommunicationSetting = communicationInterface.CommunicationSetting;
 }
Пример #13
0
        /// <summary>
        /// Initialize a new instance of the class and set the function delegates, properties and member variables.
        /// </summary>
        public CommunicationParent()
        {
            // Random number generator, used to simulate communication values.
            m_Random = new Random();

            // Initialize the watch element array.
            m_WatchElements = new WatchElement_t[Parameter.WatchSize];

            m_CommunicationSetting = new CommunicationSetting_t();
            m_MutexCommuncationInterface = new Mutex();

            #region - [Initialize VcuCommunication.comm.cpp Function Delegates] -
            // ----------------------------------------------------------------------
            // Initialize the function delegates to either the VcuCommunication32.dll
            // or VcuCommunication64.dll functions depending upon whether the
            // Windows operating system is 64 bit or 32 bit.
            // ----------------------------------------------------------------------
            if (Environment.Is64BitOperatingSystem == true)
            {
                m_Is64BitOperatingSystem = true;

                // CommunicationParent
                m_InitCommunication = VcuCommunication64.InitCommunication;
                m_CloseCommunication = VcuCommunication64.CloseCommunication;
                m_GetEmbeddedInformation = VcuCommunication64.GetEmbeddedInformation;
                m_GetChartMode = VcuCommunication64.GetChartMode;
                m_SetChartMode = VcuCommunication64.SetChartMode;
                m_GetChartIndex = VcuCommunication64.GetChartIndex;
                m_SetChartIndex = VcuCommunication64.SetChartIndex;
                m_SetChartScale = VcuCommunication64.SetChartScale;
                m_SetWatchSize = VcuCommunication64.SetWatchSize;

                // CommunicationWatch
                m_SendVariable = VcuCommunication64.SendVariable;
                m_SetWatchElements = VcuCommunication64.SetWatchElements;
                m_UpdateWatchElements = VcuCommunication64.UpdateWatchElements;

                // CommunicationPTUApplication
                m_GetTimeDate = VcuCommunication64.GetTimeDate;
                m_SetTimeDate = VcuCommunication64.SetTimeDate;
                m_SetCarID = VcuCommunication64.SetCarID;

                // Not Used
                m_StartClock = VcuCommunication64.StartClock;
                m_StopClock = VcuCommunication64.StopClock;
            }
            else
            {
                // CommunicationParent
                m_InitCommunication = VcuCommunication32.InitCommunication;
                m_CloseCommunication = VcuCommunication32.CloseCommunication;
                m_GetEmbeddedInformation = VcuCommunication32.GetEmbeddedInformation;
                m_GetChartMode = VcuCommunication32.GetChartMode;
                m_SetChartMode = VcuCommunication32.SetChartMode;
                m_GetChartIndex = VcuCommunication32.GetChartIndex;
                m_SetChartIndex = VcuCommunication32.SetChartIndex;
                m_SetChartScale = VcuCommunication32.SetChartScale;
                m_SetWatchSize = VcuCommunication32.SetWatchSize;

                // CommunicationWatch
                m_SendVariable = VcuCommunication32.SendVariable;
                m_SetWatchElements = VcuCommunication32.SetWatchElements;
                m_UpdateWatchElements = VcuCommunication32.UpdateWatchElements;

                // CommunicationPTUApplication
                m_GetTimeDate = VcuCommunication32.GetTimeDate;
                m_SetTimeDate = VcuCommunication32.SetTimeDate;
                m_SetCarID = VcuCommunication32.SetCarID;

                // Not Used
                m_StartClock = VcuCommunication32.StartClock;
                m_StopClock = VcuCommunication32.StopClock;
            }
            #endregion - [Initialize VcuCommunication.comm.cpp Function Delegates] -
        }
Пример #14
0
        /// <summary>
        /// Initialize the communication port.
        /// </summary>
        /// <param name="communicationsSetting">The communication settings.</param>
        /// <exception cref="CommunicationException">Thrown if the error code returned from the call to the PTUDLL32.InitCommunication() method is
        /// not CommunicationError.Success.</exception>
        public virtual void InitCommunication(CommunicationSetting_t communicationsSetting)
        {
            // Check that the function delegate has been initialized.
            Debug.Assert(m_InitCommunication != null, "CommunicationParent.InitCommunication() - [m_InitCommunication != null]");

            CommunicationError errorCode = CommunicationError.UnknownError;
            try
            {
                errorCode = (CommunicationError)m_InitCommunication((short)communicationsSetting.Protocol, communicationsSetting.PortIdentifier,
                                                                    (int)communicationsSetting.SerialCommunicationParameters.BaudRate,
                                                                    (short)communicationsSetting.SerialCommunicationParameters.BitsPerCharacter,
                                                                    (short)communicationsSetting.SerialCommunicationParameters.Parity,
                                                                    (short)communicationsSetting.SerialCommunicationParameters.StopBits);
            }
            catch (Exception)
            {
                errorCode = CommunicationError.SystemException;
                throw new CommunicationException(Resources.EMPortInitializationFailed, errorCode);
            }

            if (DebugMode.Enabled == true)
            {
                DebugMode.InitCommunication_t initCommunication =
                    new DebugMode.InitCommunication_t(communicationsSetting.Protocol,
                                                      communicationsSetting.PortIdentifier,
                                                      communicationsSetting.SerialCommunicationParameters.BaudRate,
                                                      communicationsSetting.SerialCommunicationParameters.BitsPerCharacter,
                                                      communicationsSetting.SerialCommunicationParameters.Parity,
                                                      communicationsSetting.SerialCommunicationParameters.StopBits,
                                                      errorCode);
                DebugMode.Write(initCommunication.ToXML());
            }

            if (errorCode != CommunicationError.Success)
            {
                throw new CommunicationException(Resources.EMPortInitializationFailed, errorCode);
            }
        }
        /// <summary>
		/// Provide dummy target configuration information and write it to the output parameter <paramref name="targetConfiguration"/>.
        /// </summary>
        /// <param name="communicationSetting">The communication settings that are to be used to communicate with the target. Ignored.</param>
        /// <param name="targetConfiguration">The target configuration information returned from the target hardware if a target is found.</param>
        /// <returns>A flag to indicate whether a target was found; true, if a target was found, otherwise, false.</returns>
        /// <exception cref="CommunicationException">Thrown if the error code returned from the call to the PTUDLL32.InitCommunication() method is not
        /// CommunicationError.Success.</exception>
        public bool ScanPort(CommunicationSetting_t communicationSetting, out TargetConfiguration_t targetConfiguration)
        {
            targetConfiguration.CarIdentifier = m_CarID;
            targetConfiguration.ConversionMask = ConversionMask;
            targetConfiguration.ProjectIdentifier = ProjectIdentifier;
            targetConfiguration.SubSystemName = SubSystemName;
            targetConfiguration.Version = Version;

            return true;
        }