Exemplo n.º 1
0
        void ScanningChanges(object sender, ScanningChangesEventArgs e)
        {
            if (SwitchToMainThread(sender, e))
            {
                return;
            }

            _scanning = e.Scanning;

            //set status detail message
            if (!e.Scanning)
            {
                if (_bestScannedPort != null)
                {
                    if (_bestScannedPort.ErrorMessage != null)
                    {
                        _currentStatusDetail = _bestScannedPort.ErrorMessage;
                    }
                    else if (!_bestScannedPort.PossibleArm)
                    {
                        _currentStatusDetail = "no robot found";
                    }
                    else if (!_bestScannedPort.HasArm)
                    {
                        _currentStatusDetail = "possible robot needing firmware on " + _bestScannedPort.Port;
                    }
                }
            }
            else
            {
                _currentStatusDetail = null;
                _bestScannedPort     = null;
            }

            RefreshStatus();
        }
Exemplo n.º 2
0
        void PortScanned(object sender, PortScannedEventArgs e)
        {
            if (SwitchToMainThread(sender, e))
            {
                return;
            }

            //update the Ports collection
            var port = Ports.FirstOrDefault(i => i.Port == e.Port);

            if (port != null)
            {
                Ports.Remove(port);
            }
            if (!e.IsRemoved)
            {
                if (port == null)
                {
                    port = new PortVM()
                    {
                        Port = e.Port, PossibleArm = e.PossibleArm
                    }
                }
                ;
                if (e.ErrorMessage != null)
                {
                    port.Message = e.ErrorMessage;
                }
                else if (e.HasArm)
                {
                    port.Message = $"{e.Model}" + (!string.IsNullOrWhiteSpace(e.NickName) ? $"  ({e.NickName})" : string.Empty);
                }
                else if (port.PossibleArm)
                {
                    port.Message = "possible robot needing firmware";
                }

                _bestScannedPort = PickBetterPort(_bestScannedPort, e);

                Ports.Add(port);
            }

            //reset settings
            if (e.NeedsSettingsReset)
            {
                ResetRequired(e);
            }
        }

        PortScannedEventArgs PickBetterPort(PortScannedEventArgs a, PortScannedEventArgs b)
        {
            if (a == null && b == null)
            {
                return(a);
            }
            if (a == null)
            {
                return(b);
            }
            if (b == null)
            {
                return(a);
            }
            if (b.PossibleArm && !a.PossibleArm)
            {
                return(b);
            }
            if (b.HasArm && !a.HasArm)
            {
                return(b);
            }
            return(a);
        }

        async void ResetRequired(PortScannedEventArgs e)
        {
            //confirm
            var result = await App.Instance.ShowMessageAsync("Robot may require a reset to factory defaults", "If you continue to receive this message and if a new firmware was flashed that is incompatible with the robots previous setting, then the connected robot may require its settings to be reset to factory defaults.  Would you like to do this now?", MahApps.Metro.Controls.Dialogs.MessageDialogStyle.AffirmativeAndNegative);

            if (result != MahApps.Metro.Controls.Dialogs.MessageDialogResult.Affirmative)
            {
                return;
            }

            e.Arm.Communication.Connect(e.Port);
            await e.Arm.ResetSettingsAsync();

            e.Arm.Communication.Disconnect();
            Rescan();
        }