Пример #1
0
 public override bool Initialize(Settings settings)
 {
     try {
         if (m_CommELM.Online)
         {
             return(true);
         }
         if (CommBase.GetPortAvailable(settings.ComPort) == CommBase.PortStatus.Available && Initialize(settings.ComPort, settings.BaudRate))
         {
             return(true);
         }
         for (int iPort = 0; iPort < 100; ++iPort)
         {
             if (iPort != settings.ComPort)
             {
                 if (CommBase.GetPortAvailable(iPort) == CommBase.PortStatus.Available &&
                     (Initialize(iPort, 38400) || Initialize(iPort, 115200) || Initialize(iPort, 9600)))
                 {
                     return(true);
                 }
             }
         }
     } catch { }
     return(false);
 }
Пример #2
0
        private void SettingsForm_Load(object sender, EventArgs e)
        {
            try {
                string[] serialPorts = SerialPort.GetPortNames();
                foreach (string serialPort in serialPorts)
                {
                    comboPorts.Items.Add(serialPort);
                    cmbBoxScannerPort.Items.Add(serialPort);
                }

                if (CommBase.IsPortAvailable(m_settings.ComPort))
                {
                    comboPorts.SelectedItem = m_settings.ComPortName;
                }
                else if (comboPorts.Items.Count > 0)
                {
                    comboPorts.SelectedIndex = 0;
                }

                if (CommBase.IsPortAvailable(m_settings.ScannerPort))
                {
                    cmbBoxScannerPort.SelectedItem = m_settings.ScannerPortName;
                }
                else
                {
                    for (int i = 0; i < cmbBoxScannerPort.Items.Count; i++)
                    {
                        if (i != comboPorts.SelectedIndex)
                        {
                            cmbBoxScannerPort.SelectedIndex = i;
                            break;
                            // 自动设置可用串口
                            //if (CommBase.IsPortAvailable(Convert.ToInt32(cmbBoxScannerPort.Items[i].ToString().Remove(0, 3)))) {
                            //    cmbBoxScannerPort.SelectedIndex = i;
                            //    break;
                            //}
                        }
                    }
                }

                comboHardware.SelectedIndex     = m_settings.HardwareIndexInt;
                comboBaud.SelectedIndex         = m_settings.BaudRateIndex;
                cmbBoxScannerBaud.SelectedIndex = m_settings.ScannerBaudRateIndex;

                this.chkBoxUseSerialScanner.Checked = m_settings.UseSerialScanner;
                this.cmbBoxScannerPort.Enabled      = this.chkBoxUseSerialScanner.Checked;
                this.cmbBoxScannerBaud.Enabled      = this.chkBoxUseSerialScanner.Checked;

                foreach (string item in Settings.ProtocolNames)
                {
                    comboProtocol.Items.Add(item);
                }

                comboProtocol.SelectedIndex   = m_settings.ProtocolIndexInt;
                comboInitialize.SelectedIndex = !m_settings.DoInitialization ? 1 : 0;
                if (m_settings.AutoDetect)
                {
                    checkBoxAutoDetect.Checked = true;
                }
                else
                {
                    checkBoxAutoDetect.Checked = false;
                }

                this.txtBoxUser.Text          = m_dbandMES.UserName;
                this.txtBoxPwd.Text           = m_dbandMES.PassWord;
                this.txtBoxDBName.Text        = m_dbandMES.DBName;
                this.txtBoxIP.Text            = m_dbandMES.IP;
                this.txtBoxPort.Text          = m_dbandMES.Port;
                this.txtBoxWebSvcAddress.Text = m_dbandMES.WebServiceAddress;
                this.txtBoxWebSvcName.Text    = m_dbandMES.WebServiceName;
                this.txtBoxWebSvcMethods.Text = m_dbandMES.WebServiceMethods;
                this.txtBoxWebSvcWSDL.Text    = m_dbandMES.WebServiceWSDL;
                if (m_dbandMES.UseURL)
                {
                    this.radioBtnURL.Checked         = true;
                    m_lastURLStatus                  = this.radioBtnURL.Checked;
                    this.txtBoxWebSvcAddress.Enabled = true;
                    this.txtBoxWebSvcWSDL.Enabled    = false;
                }
                else
                {
                    this.radioBtnWSDL.Checked        = true;
                    this.txtBoxWebSvcAddress.Enabled = false;
                    this.txtBoxWebSvcWSDL.Enabled    = true;
                }
                m_lastURLStatus                   = this.radioBtnURL.Checked;
                this.radioBtnURL.Enabled          = m_dbandMES.ChangeWebService;
                this.radioBtnWSDL.Enabled         = m_dbandMES.ChangeWebService;
                this.chkBoxUploadWhenever.Checked = m_dbandMES.UploadWhenever;
                this.chkBoxUseECUName.Checked     = m_dbandMES.UseECUName;
            } catch (Exception ex) {
                MessageBox.Show(ex.ToString());
            }
        }