Esempio n. 1
0
        /// <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;
        }
Esempio n. 2
0
        /// <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();
        }
Esempio n. 3
0
        /// <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);
        }
Esempio n. 4
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();
        }
        /// <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);
        }
Esempio n. 6
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 and is used by the InitCommunication() method in PTUDLL32 to specify the serial communication port.
                        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);
                                listBoxTargetsFound.Update();
                                statusInformation.Text = Resources.TextTargetFoundOn + CommonConstants.Space + communicationSetting.Port.FullSpecification;
                                communicationSettingList.Add(communicationSetting);
                                targetFound = true;
                            }
                        }
                        catch (Exception)
                        {
                            statusInformation.Text = Resources.TextNoTargetFoundOn + CommonConstants.Space + communicationSetting.Port.FullSpecification;
                            statusInformation.Update();
                            continue;
                        }
                    }
                }
            }

            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;
                // Scan each port in the Registry.
                foreach (string URI in Parameter.URIList)
                {
                    communicationSetting.PortIdentifier = URI;
                    // 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.Space + "(" + URI + ")");
                            listBoxTargetsFound.Update();
                            statusInformation.Text = Resources.TextTargetFoundOn + CommonConstants.Space + URI;
                            communicationSettingList.Add(communicationSetting);
                            targetFound = true;
                        }
                    }
                    catch (Exception)
                    {
                        statusInformation.Text = Resources.TextNoTargetFoundOn + CommonConstants.Space + communicationSetting.Port.Name;
                        statusInformation.Update();
                        continue;
                    }
                }
            }

            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);
        }
Esempio n. 7
0
 /// <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)
 {
 }
Esempio n. 8
0
 /// <summary>
 /// Initialize a new instance of the class and set the <c>CommunicationSetting</c> property to the specified communication setting.
 /// </summary>
 /// <param name="communicationSetting">The communication setting that is to be used to initialize the <c>CommunicationSetting</c> property.
 /// </param>
 public CommunicationParentOffline(CommunicationSetting_t communicationSetting) : this()
 {
     m_CommunicationSetting = communicationSetting;
 }
        /// <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))
                {
                    // If no serial ports have ever been connected to the PC since reset, "serialCommunication == null"
                    // will be true.
                    if (serialCommunication == null)
                    {
                        if (Parameter.CommunicationType == Parameter.CommunicationTypeEnum.RS232)
                        {
                            // Since only RS-232 has been selected as the only method to communicate with
                            // the VCU, throw an exception which is handled in the calling function
                            throw new Exception();
                        }
                    }

                    // If a USB/Serial port has been connected and removed, serialCommunication
                    // will be a non-null value, but no serial ports will be discovered (i.e.
                    // serialCommunication.GetValueNames() will return an empty array
                    else
                    {
                        // 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);
        }