Exemplo n.º 1
0
 void JobView_Load(object sender, EventArgs e)
 {
     GCodeSender.CallHandler(StreamingState.Idle, true);
 }
Exemplo n.º 2
0
        public void Activate(bool activate, ViewType chgMode)
        {
            if (activate)
            {
                GCodeSender.RewindFile();
                GCodeSender.CallHandler(GCode.File.IsLoaded ? StreamingState.Idle : (model.IsSDCardJob ? StreamingState.Start : StreamingState.NoFile), false);

                model.ResponseLogFilterOk = AppConfig.Settings.Base.FilterOkResponse;

                if (Controller == null)
                {
                    Controller = new Controller(model);
                }

                if (initOK != true)
                {
                    focusedControl = this;
                    initOK         = false;

                    switch (Controller.Restart())
                    {
                    case Controller.RestartResult.Ok:
                        initOK = InitSystem();
                        break;

                    case Controller.RestartResult.Close:
                        MainWindow.ui.Close();
                        break;

                    case Controller.RestartResult.Exit:
                        Environment.Exit(-1);
                        break;
                    }

                    model.Message = Controller.Message;
                }

                #if ADD_CAMERA
                if (MainWindow.UIViewModel.Camera != null)
                {
                    MainWindow.UIViewModel.Camera.MoveOffset          += Camera_MoveOffset;
                    MainWindow.UIViewModel.Camera.IsVisibilityChanged += Camera_Opened;
                }
                #endif
                //if (viewer == null)
                //    viewer = new Viewer();

                if (GCode.File.IsLoaded)
                {
                    MainWindow.ui.WindowTitle = ((GrblViewModel)DataContext).FileName;
                }

                model.Keyboard.JogStepDistance = AppConfig.Settings.Jog.LinkStepJogToUI ? AppConfig.Settings.JogUiMetric.Distance0 : AppConfig.Settings.Jog.StepDistance;
                model.Keyboard.JogDistances[(int)KeypressHandler.JogMode.Slow] = AppConfig.Settings.Jog.SlowDistance;
                model.Keyboard.JogDistances[(int)KeypressHandler.JogMode.Fast] = AppConfig.Settings.Jog.FastDistance;
                model.Keyboard.JogFeedrates[(int)KeypressHandler.JogMode.Step] = AppConfig.Settings.Jog.StepFeedrate;
                model.Keyboard.JogFeedrates[(int)KeypressHandler.JogMode.Slow] = AppConfig.Settings.Jog.SlowFeedrate;
                model.Keyboard.JogFeedrates[(int)KeypressHandler.JogMode.Fast] = AppConfig.Settings.Jog.FastFeedrate;

                model.Keyboard.IsJoggingEnabled = AppConfig.Settings.Jog.Mode != JogConfig.JogMode.UI;

                if (!GrblInfo.IsGrblHAL)
                {
                    model.Keyboard.IsContinuousJoggingEnabled = AppConfig.Settings.Jog.KeyboardEnable;
                }
            }
            else if (ViewType != ViewType.Shutdown)
            {
                DRO.IsFocusable = false;
                #if ADD_CAMERA
                if (MainWindow.UIViewModel.Camera != null)
                {
                    MainWindow.UIViewModel.Camera.MoveOffset -= Camera_MoveOffset;
                }
                #endif
                focusedControl = AppConfig.Settings.Base.KeepMdiFocus &&
                                 Keyboard.FocusedElement is TextBox &&
                                 (Keyboard.FocusedElement as TextBox).Tag is string &&
                                 (string)(Keyboard.FocusedElement as TextBox).Tag == "MDI"
                                  ? Keyboard.FocusedElement
                                  : this;
            }

            if (GCodeSender.Activate(activate))
            {
                showProgramLimits();
                Task.Delay(500).ContinueWith(t => DRO.EnableFocus());
                Application.Current.Dispatcher.BeginInvoke(new System.Action(() =>
                {
                    focusedControl.Focus();
                }), DispatcherPriority.Render);
            }
        }
Exemplo n.º 3
0
        public void Activate(bool activate, ViewType chgMode)
        {
            if (activate)
            {
                GCodeSender.RewindFile();
                GCodeSender.CallHandler(GCode.File.IsLoaded ? StreamingState.Idle : (sdStream ? StreamingState.Start : StreamingState.NoFile), false);
                sdStream = false;

                model.ResponseLogFilterOk = AppConfig.Settings.Base.FilterOkResponse;

                if (initOK != true)
                {
                    focusedControl = this;

                    var message = model.Message;
                    model.Message = string.Format("Waiting for controller ({0})...", AppConfig.Settings.Base.PortParams);

                    string response = GrblInfo.Startup(model);

                    if (response.StartsWith("<"))
                    {
                        if (model.GrblState.State != GrblStates.Unknown)
                        {
                            switch (model.GrblState.State)
                            {
                            case GrblStates.Alarm:

                                model.Poller.SetState(AppConfig.Settings.Base.PollInterval);

                                switch (model.GrblState.Substate)
                                {
                                case 1:         // Hard limits
                                    if (!GrblInfo.IsLoaded)
                                    {
                                        if (model.LimitTriggered)
                                        {
                                            MessageBox.Show(string.Format("Controller is not able to communicate due to alarm {0}, attempting a soft reset.", model.GrblState.Substate.ToString()), "ioSender");
                                            if (AttemptReset())
                                            {
                                                model.ExecuteCommand(GrblConstants.CMD_UNLOCK);
                                            }
                                            else
                                            {
                                                MessageBox.Show("Controller soft reset failed, exiting.", "ioSender");
                                                MainWindow.ui.Close();
                                            }
                                        }
                                        else if (AttemptReset())
                                        {
                                            model.ExecuteCommand(GrblConstants.CMD_UNLOCK);
                                        }
                                    }
                                    else
                                    {
                                        response = string.Empty;
                                    }
                                    break;

                                case 2:         // Soft limits
                                    if (!GrblInfo.IsLoaded)
                                    {
                                        MessageBox.Show(string.Format("Controller is not able to communicate due to alarm {0}, attempting a soft reset.", model.GrblState.Substate.ToString()), "ioSender");
                                        if (AttemptReset())
                                        {
                                            model.ExecuteCommand(GrblConstants.CMD_UNLOCK);
                                        }
                                        else
                                        {
                                            MessageBox.Show("Controller soft reset failed, exiting.", "ioSender");
                                            MainWindow.ui.Close();
                                        }
                                    }
                                    else
                                    {
                                        response = string.Empty;
                                    }
                                    break;

                                case 10:         // EStop
                                    if (GrblInfo.IsGrblHAL && model.Signals.Value.HasFlag(Signals.EStop))
                                    {
                                        MessageBox.Show("E-Stop active! - clear before continuing.", "ioSender", MessageBoxButton.OK, MessageBoxImage.Warning);
                                        while (!AttemptReset() && model.GrblState.State == GrblStates.Alarm)
                                        {
                                            if (MessageBox.Show("E-Stop still active, exit?", "ioSender", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                                            {
                                                MainWindow.ui.Close();
                                            }
                                        }
                                        ;
                                    }
                                    else
                                    {
                                        AttemptReset();
                                    }
                                    if (!GrblInfo.IsLoaded)
                                    {
                                        model.ExecuteCommand(GrblConstants.CMD_UNLOCK);
                                    }
                                    break;

                                case 11:         // Homing required
                                    if (GrblInfo.IsLoaded)
                                    {
                                        response = string.Empty;
                                    }
                                    else
                                    {
                                        message = "Homing cycle required, <Home> to continue";
                                    }
                                    break;
                                }
                                break;

                            case GrblStates.Tool:
                                Comms.com.WriteByte(GrblConstants.CMD_STOP);
                                break;

                            case GrblStates.Door:
                                if (!GrblInfo.IsLoaded)
                                {
                                    if (MessageBox.Show("Door is open, close door and continue?", "ioSender", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
                                    {
                                        MainWindow.ui.Close();
                                    }
                                    else
                                    {
                                        bool exit = false;
                                        do
                                        {
                                            Comms.com.PurgeQueue();

                                            bool?res = null;
                                            CancellationToken cancellationToken = new CancellationToken();

                                            new Thread(() =>
                                            {
                                                res = WaitFor.SingleEvent <string>(
                                                    cancellationToken,
                                                    s => TrapReset(s),
                                                    a => model.OnGrblReset += a,
                                                    a => model.OnGrblReset -= a,
                                                    200, () => Comms.com.WriteByte(GrblConstants.CMD_STATUS_REPORT));
                                            }).Start();

                                            while (res == null)
                                            {
                                                EventUtils.DoEvents();
                                            }

                                            if (!(exit = !model.Signals.Value.HasFlag(Signals.SafetyDoor)))
                                            {
                                                if (MessageBox.Show("Door is still open, exit?", "ioSender", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                                                {
                                                    exit = true;
                                                    MainWindow.ui.Close();
                                                }
                                            }
                                        } while (!exit);
                                    }
                                }
                                else
                                {
                                    MessageBox.Show("Door state cannot be cleared with <Reset>", "ioSender", MessageBoxButton.YesNo, MessageBoxImage.Exclamation);
                                    response = string.Empty;
                                }
                                break;

                            case GrblStates.Hold:
                            case GrblStates.Sleep:
                                if (MessageBox.Show(string.Format("Controller is in {0} state and cannot respond, try a soft reset?", model.GrblState.State.ToString()),
                                                    "ioSender", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
                                {
                                    MainWindow.ui.Close();
                                }
                                else if (!AttemptReset())
                                {
                                    MessageBox.Show("Controller soft reset failed, exiting.", "ioSender");
                                    MainWindow.ui.Close();
                                }
                                break;
                            }
                        }
                    }

                    if (response != string.Empty)
                    {
                        InitSystem();
                    }

                    model.Message = message;
                }

                if (initOK == null)
                {
                    initOK = false;
                }

                #if ADD_CAMERA
                if (MainWindow.UIViewModel.Camera != null)
                {
                    MainWindow.UIViewModel.Camera.MoveOffset += Camera_MoveOffset;
                    MainWindow.UIViewModel.Camera.Opened     += Camera_Opened;
                }
                #endif
                //if (viewer == null)
                //    viewer = new Viewer();

                if (GCode.File.IsLoaded)
                {
                    MainWindow.ui.WindowTitle = ((GrblViewModel)DataContext).FileName;
                }
            }
            else if (ViewType != ViewType.Shutdown)
            {
                DRO.IsFocusable = false;
                #if ADD_CAMERA
                if (MainWindow.UIViewModel.Camera != null)
                {
                    MainWindow.UIViewModel.Camera.MoveOffset -= Camera_MoveOffset;
                }
                #endif
                focusedControl = AppConfig.Settings.Base.KeepMdiFocus && Keyboard.FocusedElement is TextBox && (string)(Keyboard.FocusedElement as TextBox).Tag == "MDI"
                                  ? Keyboard.FocusedElement
                                  : this;
            }

            if (GCodeSender.Activate(activate))
            {
                Task.Delay(500).ContinueWith(t => DRO.EnableFocus());
                Application.Current.Dispatcher.BeginInvoke(new System.Action(() =>
                {
                    focusedControl.Focus();
                }), DispatcherPriority.Render);
            }
        }
Exemplo n.º 4
0
        public void Activate(bool activate, ViewType chgMode)
        {
            if (activate)
            {
                GCodeSender.RewindFile();
                GCodeSender.CallHandler(GCode.File.IsLoaded ? StreamingState.Idle : (sdStream ? StreamingState.Start : StreamingState.NoFile), false);
                sdStream = false;

                if (initOK != true)
                {
                    model.Message = "Waiting for controller...";

                    Comms.com.PurgeQueue();
                    Comms.com.WriteByte(GrblLegacy.ConvertRTCommand(GrblConstants.CMD_STATUS_REPORT));

                    int timeout = 30; // 1.5s
                    do
                    {
                        System.Threading.Thread.Sleep(50);
                    } while (Comms.com.Reply == "" && --timeout != 0);

                    if (Comms.com.Reply.StartsWith("<Alarm"))
                    {
                        GrblViewModel data = (GrblViewModel)DataContext;
                        data.ParseStatus(Comms.com.Reply);

                        // Alarm 1, 2 and 10 are critical events
                        if (!(data.GrblState.Substate == 1 || data.GrblState.Substate == 2 || data.GrblState.Substate == 10))
                        {
                            InitSystem();
                        }
                    }
                    else if (Comms.com.Reply != "")
                    {
                        InitSystem();
                    }
                }

                if (initOK == null)
                {
                    initOK = false;
                }

                #if ADD_CAMERA
                if (MainWindow.UIViewModel.Camera != null)
                {
                    MainWindow.UIViewModel.Camera.MoveOffset += Camera_MoveOffset;
                    MainWindow.UIViewModel.Camera.Opened     += Camera_Opened;
                }
                #endif
                //if (viewer == null)
                //    viewer = new Viewer();

                if (GCode.File.IsLoaded)
                {
                    MainWindow.ui.WindowTitle = ((GrblViewModel)DataContext).FileName;
                }
            }
            else if (ViewType != ViewType.Shutdown)
            {
                DRO.IsFocusable = false;
                #if ADD_CAMERA
                if (MainWindow.UIViewModel.Camera != null)
                {
                    MainWindow.UIViewModel.Camera.MoveOffset -= Camera_MoveOffset;
                }
                #endif
            }

            if (GCodeSender.Activate(activate))
            {
                Task.Delay(500).ContinueWith(t => DRO.EnableFocus());
                Application.Current.Dispatcher.BeginInvoke(new System.Action(() =>
                {
                    Focus();
                }), DispatcherPriority.Render);
            }
        }
Exemplo n.º 5
0
        public void Activate(bool activate, ViewType chgMode)
        {
            if (activate)
            {
                GCodeSender.RewindFile();
                GCodeSender.CallHandler(GCode.File.IsLoaded ? StreamingState.Idle : (sdStream ? StreamingState.Start : StreamingState.NoFile), false);
                sdStream = false;

                if (initOK != true)
                {
                    focusedControl = this;
                    model.Message  = string.Format("Waiting for controller ({0})...", AppConfig.Settings.Base.PortParams);

                    string response = GrblInfo.Startup();

                    if (response.StartsWith("<Alarm"))
                    {
                        GrblViewModel data = DataContext as GrblViewModel;
                        data.ParseStatus(response);

                        // Alarm 1, 2 and 10 are critical events
                        if (!(data.GrblState.Substate == 1 || data.GrblState.Substate == 2 || data.GrblState.Substate == 10))
                        {
                            InitSystem();
                        }
                    }
                    else if (response.StartsWith("<Tool"))
                    {
                        Comms.com.WriteByte(GrblConstants.CMD_STOP);
                        GrblViewModel data = DataContext as GrblViewModel;
                        data.ParseStatus(Comms.com.Reply);
                    }
                    else if (response != string.Empty)
                    {
                        InitSystem();
                    }
                }

                if (initOK == null)
                {
                    initOK = false;
                }

                #if ADD_CAMERA
                if (MainWindow.UIViewModel.Camera != null)
                {
                    MainWindow.UIViewModel.Camera.MoveOffset += Camera_MoveOffset;
                    MainWindow.UIViewModel.Camera.Opened     += Camera_Opened;
                }
                #endif
                //if (viewer == null)
                //    viewer = new Viewer();

                if (GCode.File.IsLoaded)
                {
                    MainWindow.ui.WindowTitle = ((GrblViewModel)DataContext).FileName;
                }
            }
            else if (ViewType != ViewType.Shutdown)
            {
                DRO.IsFocusable = false;
                #if ADD_CAMERA
                if (MainWindow.UIViewModel.Camera != null)
                {
                    MainWindow.UIViewModel.Camera.MoveOffset -= Camera_MoveOffset;
                }
                #endif
                focusedControl = AppConfig.Settings.Base.KeepMdiFocus && Keyboard.FocusedElement is TextBox && (string)(Keyboard.FocusedElement as TextBox).Tag == "MDI"
                                  ? Keyboard.FocusedElement
                                  : this;
            }

            if (GCodeSender.Activate(activate))
            {
                Task.Delay(500).ContinueWith(t => DRO.EnableFocus());
                Application.Current.Dispatcher.BeginInvoke(new System.Action(() =>
                {
                    focusedControl.Focus();
                }), DispatcherPriority.Render);
            }
        }