Example #1
0
        /// <summary>
        /// Конструктор
        /// </summary>
        /// <param name="emu"></param>
        public FormSettings(FormMain frmParrent)
        {
            _frmParrent = frmParrent;
            _portsList  = COMPortName.GetPortNames();

            InitializeComponent();

            cbConsultPort.SelectedIndexChanged  += new EventHandler(cbPorts_SelectedIndexChanged);
            cbEmulatorPort.SelectedIndexChanged += new EventHandler(cbPorts_SelectedIndexChanged);

            InitializeMenu();

            InitializeConsult();
            UpdateConsultInterface();

            InitializeEmulator();

            LoadSettings();
            UpdateButtons();
        }
Example #2
0
        private void ConsultConnect(COMPortName comPort = null)
        {
            StatusLabel(StatusCommunications.Search, lblStatusConsult);
            StatusLabel(StatusCommunications.Search, cbConsultPort);

            string port = comPort == null ? "" : comPort.PortName;

            _consultECUInfo = null;
            //Если Класса не существует - внештатная ситуация
            if (_consult == null)
            {
                throw new NullReferenceException("Не создан экземпляр класса Consult!");
            }

            //Порт пуст. будем искать консульт на всех свободных портах
            if (String.IsNullOrEmpty(port))
            {
                if (!_consult.IsOnline)
                {
                    List <COMPortName> lstAccesiblePorts = COMPortName.GetPortNames(true);
                    using (IProgressBar progressCOMSearch = FormProgressBar.GetInstance("Initialize consult on "))
                    {
                        progressCOMSearch.ShowProgressBar(delegate()
                        {
                            foreach (COMPortName i in lstAccesiblePorts)
                            {
                                progressCOMSearch.SetCurrentState(i.PortName);
                                try
                                {
                                    _consult.Initialise(i.PortName, true);
                                    _consultECUInfo = _consult.GetECUInfo();
                                    break;
                                }
                                catch (ConsultException)
                                { continue; }
                            }
                        });
                    }

                    if (_consult.IsOnline)
                    {
                        StatusLabel(StatusCommunications.Found, lblStatusConsult, _consultECUInfo.ToString());
                        StatusLabel(StatusCommunications.Found, cbConsultPort, _consultECUInfo.ToString());

                        port = _consult.COMPort;
                        _consult.Disconnect();
                        ComboBoxSelectedIndexUpdate(new COMPortName(_consult.COMPort), cbConsultPort);
                    }
                    else
                    {
                        StatusLabel(StatusCommunications.NotFound, lblStatusConsult);
                        StatusLabel(StatusCommunications.NotFound, cbConsultPort);
                    }
                }
            }
            //выбран конкретный порт
            else
            {
                try
                {
                    //выбранный порт отличается от того по которому сейчас работает консульт
                    //выбранный порт новый и consult уже подключен, отключимся
                    if (port != _consult.COMPort && _consult.IsOnline)
                    {
                        _consult.Disconnect();
                    }

                    using (IProgressBar progress = FormProgressBar.GetInstance("Consult initialization on " + port))
                    {
                        progress.ShowProgressBar(delegate()
                        {
                            try
                            {
                                _consult.Initialise(port);
                                _consultECUInfo = _consult.GetECUInfo();

                                StatusLabel(StatusCommunications.Found, lblStatusConsult, _consultECUInfo.ToString());
                                StatusLabel(StatusCommunications.Found, cbConsultPort, _consultECUInfo.ToString());
                            }
                            catch (ConsultException ex)
                            {
                                StatusLabel(StatusCommunications.NotFound, lblStatusConsult, ex.Message);
                                StatusLabel(StatusCommunications.NotFound, cbConsultPort, ex.Message);
                            }
                        });
                    }
                }
                catch (ConsultException ex)
                {
                    StatusLabel(ex.Message, Color.Red, lblStatusConsult);
                    StatusLabel(ex.Message, Color.Red, cbConsultPort);
                    return;
                }
            }
        }