コード例 #1
0
ファイル: ConnectionModel.cs プロジェクト: zhanghz/nmqtt
        public void Connect()
        {
            if (!Servers.Contains(Server))
            {
                Servers.Add(Server);
            }
            if (!Ports.Contains(Port))
            {
                Ports.Add(Port);
            }

            MqttHandler.Instance.Connect(Server, Port);
        }
コード例 #2
0
        public InitViewModel(Toolset toolset)
        {
            Toolset = toolset ?? throw new ArgumentNullException(nameof(toolset));

            // We explicitly don't want to "run this command at startup" because it leads to a wonky
            // UX if the user hasn't yet connected the device. It *looks* like we're providing "live
            // updates" but we're not.
            RefreshPorts = Command.Create(() =>
            {
                Ports = SerialPort.GetPortNames();
                if (!Ports.Contains(SelectedPort))
                {
                    SelectedPort = null;
                }
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Ports)));
            });
            StartTools = Command.Create(async() =>
            {
                try
                {
                    NextViewModel = new ProcessSetViewModel(toolset);
                    var(extractedLocation, extractedSet) = await BinarySet.Extract(BinarySetViewModel.BinarySetPath !);
                    await NextViewModel.SetBinaries(extractedSet !, SelectedPort !, extractedLocation);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                    MessageBox.Show(Application.Current.MainWindow, "Failed to extract data.\r\n\r\n" + ex.ToString(), "Flashing failed", MessageBoxButton.OK, MessageBoxImage.Error);
                    Application.Current.Shutdown(1);
                }
            }, () => SelectedPort != null && Toolset.IsInstalled && (BinarySetViewModel.BinarySetTask?.IsCompletedSuccessfully ?? false));
            BinarySetViewModel.PropertyChanged += (_, args) =>
            {
                if (args.IsFor(nameof(BinarySetViewModel.EffectiveViewModel)))
                {
                    StartTools.RaiseCanExecuteChanged();
                }
            };
        }
コード例 #3
0
        private void AtualizaListaCom()
        {
            int  i   = 0;
            bool qtd = false;


            if (Ports.Count == SerialPort.GetPortNames().Length)
            {
                foreach (string s in SerialPort.GetPortNames())
                {
                    if (Ports.Contains(s) == false)
                    {
                        qtd = true;
                    }
                }
            }
            else
            {
                qtd = true;
            }

            //Se não foi detectado diferença
            if (qtd == false)
            {
                return;                     //retorna
            }

            //limpa comboBox
            Ports.Clear();

            //adiciona todas as COM diponíveis na lista
            foreach (string s in SerialPort.GetPortNames())
            {
                Ports.Add(s);
            }
        }