void JobView_Load(object sender, EventArgs e)
 {
     GCodeSender.SetStreamingState(StreamingState.Idle);
 }
        public void Activate(bool activate, ViewType chgMode)
        {
            if (activate)
            {
                GCodeSender.RewindFile();
                GCodeSender.SetStreamingState(GCodeSender.GCode.Loaded ? StreamingState.Idle : StreamingState.NoFile);

                if (!initOK)
                {
                    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"))
                    {
                        if (Comms.com.Reply.StartsWith("<Alarm:"))
                        {
                            int    i = Comms.com.Reply.IndexOf('|');
                            string s = Comms.com.Reply.Substring(7, i - 7);
                            if (!"1,2,10".Contains(s)) // Alarm 1, 2 and 10 are critical events
                            {
                                InitSystem();
                            }
                            if (s == "11")
                            {
                                txtStatus.Text = "<Home> to continue.";
                            }
                            else
                            {
                                txtStatus.Text = "<Reset> then <Unlock> to continue.";
                            }
                        }
                        else
                        {
                            txtStatus.Text = "<Reset> then <Unlock> to continue.";
                        }
                    }
                    else
                    {
                        InitSystem();
                    }
                }
                #if ADD_CAMERA
                if (MainWindow.Camera != null)
                {
                    MainWindow.Camera.CameraControl.MoveOffset += Camera_MoveOffset;
                    MainWindow.Camera.Opened += Camera_Opened;
                }
                #endif
                //if (viewer == null)
                //    viewer = new Viewer();

                if (GCodeSender.GCode.Loaded)
                {
                    MainWindow.ui.WindowTitle = ((GrblViewModel)DataContext).FileName;
                }
            }
            else if (mode != ViewType.Shutdown)
            {
                DRO.IsFocusable = false;
                #if ADD_CAMERA
                if (MainWindow.Camera != null)
                {
                    MainWindow.Camera.CameraControl.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);
            }
        }