Beispiel #1
0
 private void JobView_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
 {
     if (IsVisible)
     {
         GCodeSender.Focus();
     }
 }
Beispiel #2
0
        protected bool ProcessKeyPreview(System.Windows.Input.KeyEventArgs e)
        {
            if (mdiControl.IsFocused || DRO.IsFocused || spindleControl.IsFocused || workParametersControl.IsFocused)
            {
                return(false);
            }

            return(GCodeSender.ProcessKeypress(e));
        }
        private void OnDataContextPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (sender is GrblViewModel)
            {
                switch (e.PropertyName)
                {
                case nameof(GrblViewModel.GrblState):
                    if (!initOK && ((GrblViewModel)sender).GrblState.State != GrblStates.Alarm)
                    {
                        InitSystem();
                    }
                    break;

                case nameof(GrblViewModel.IsSleepMode):
                    EnableUI(!((GrblViewModel)sender).IsSleepMode);
                    break;

                case nameof(GrblViewModel.IsJobRunning):
                    MainWindow.ui.JobRunning = ((GrblViewModel)sender).IsJobRunning;
                    break;

                case nameof(GrblViewModel.GrblReset):
                    if (((GrblViewModel)sender).GrblReset)
                    {
                        Comms.com.WriteCommand(GrblConstants.CMD_GETPARSERSTATE);
                    }
                    break;

                case nameof(GrblViewModel.ParserState):
                    if (((GrblViewModel)sender).GrblReset)
                    {
                        EnableUI(true);
                        ((GrblViewModel)sender).GrblReset = false;
                    }
                    break;

                case nameof(GrblViewModel.FileName):
                    string filename = ((GrblViewModel)sender).FileName;
                    MainWindow.ui.WindowTitle = filename;
                    if (filename != string.Empty && MainWindow.IsViewVisible(ViewType.GCodeViewer))
                    {
                        MainWindow.EnableView(true, ViewType.GCodeViewer);
                        GCodeSender.EnablePolling(false);
                        MainWindow.GCodeViewer.Open(filename, GCodeSender.GCode.Tokens);
                        GCodeSender.EnablePolling(true);
                    }
                    break;
                }
            }
        }
Beispiel #4
0
        //NOTE: at the moment temperature checking has only been enable for the #1 extruder, support for more extruders and heatbed(s) should be added later
        /// <summary>
        /// Initialise a Communication Controller which will handle all low level communication
        /// with the connected device
        /// </summary>
        /// <param name="_hostPage">The page that who's dispatcher will be used to display messageboxes with info regarding connection related events</param>
        /// <param name="_file_Listpicker">The listpicker tha will contain the list of GCode files that can be printed</param>
        /// <param name="_device_Listpicker">The listpicker that will contain the list of paired devices that can be connected to</param>
        /// <param name="_log_Stackpanel">The stackpanel that will be used to log communication</param>
        /// <param name="_temperature_Textblock">The textblock that will be used to display the current extruder temperature</param>
        public ComController(PhoneApplicationPage _hostPage, ListPicker _device_Listpicker, StackPanel _log_Stackpanel,
                             TextBlock _temperature_Textblock)
        {
            //Store local references of the recieved instances
            hostPage              = _hostPage;
            device_Listpicker     = _device_Listpicker;
            log_Stackpanel        = _log_Stackpanel;
            temperature_Textblock = _temperature_Textblock;

            //Initialise the needed classes
            bluetoothIO      = new BluetoothIO();
            responseReceiver = new GCodeResponseReciever(bluetoothIO);
            GCodeSender      = new GCodeSender(bluetoothIO, responseReceiver, hostPage.Dispatcher);
            GCodeGenerator   = new GCodeGenerator(GCodeSender);

            //Connect the needed events to our local handlers
            bluetoothIO.ConnectedToDevice     += bluetoothIO_ConnectedToDevice;
            bluetoothIO.ConnectionFailed      += bluetoothIO_ConnectionFailed;
            bluetoothIO.DiconnectedFromDevice += bluetoothIO_DiconnectedFromDevice;

            //Setup the GCodefilereader
            GCodeFileReader = new GCodeFileReader(GCodeSender, GCodeGenerator);
            GCodeFileReader.FileReadingStarted += GCodeFileReader_FileReadingStarted;
            GCodeFileReader.FileReadingStopped += GCodeFileReader_FileReadingStopped;

            //Fill the listpicker that contains the list of connectable bluetooth with a list of all the currently paired bluetooth devices
            Devicefinder.getListOfBluetoothDevices(device_Listpicker);

            //Link the external events to our local handlers
            GCodeSender.CommandSent              += GCodeSender_CommandSent;
            responseReceiver.MessageRecieved     += responseReceiver_MessageRecieved;
            responseReceiver.TemperatureRecieved += responseReceiver_TemperatureRecieved;

            //Start the probing thread with a function that probes the printer for the #1 extruders temperature every 5 second (5000 milliseconds)
            temperatureProbingThread = new Thread(new ThreadStart(() => GCodeTemperatureProber.probeTemperature(5000, GCodeGenerator)));

            //Initialise the logboxbox that will log all communication between the application and the connected device
            logBox = new LogBox(log_Stackpanel, hostPage, 25);
        }
Beispiel #5
0
        private void InitSystem()
        {
            initOK = true;

            // TODO: check if grbl is in a state that allows replies
            using (new UIUtils.WaitCursor())
            {
                GCodeSender.EnablePolling(false);
                GrblInfo.Get();
                GrblSettings.Get();
                GrblParserState.Get();
                GrblWorkParameters.Get();
                GCodeSender.EnablePolling(true);
            }

            model.Message = "";

            GrblCommand.ToolChange = GrblInfo.ManualToolChange ? "M61Q{0}" : "T{0}";

            GCodeSender.Config(MainWindow.UIViewModel.Profile.Config);

            if (GrblInfo.NumAxes > 3)
            {
                limitsControl.Visibility = Visibility.Collapsed;
            }

            if (GrblInfo.LatheModeEnabled)
            {
                MainWindow.EnableView(true, ViewType.Turning);
                MainWindow.EnableView(true, ViewType.Facing);
                MainWindow.EnableView(true, ViewType.G76Threading);
            }
            else
            {
                MainWindow.ShowView(false, ViewType.Turning);
                MainWindow.ShowView(false, ViewType.Facing);
                MainWindow.ShowView(false, ViewType.G76Threading);
            }

            if (GrblInfo.HasSDCard)
            {
                MainWindow.EnableView(true, ViewType.SDCard);
            }
            else
            {
                MainWindow.ShowView(false, ViewType.SDCard);
            }

            if (GrblInfo.HasPIDLog)
            {
                MainWindow.EnableView(true, ViewType.PIDTuner);
            }
            else
            {
                MainWindow.ShowView(false, ViewType.PIDTuner);
            }

            if (GrblInfo.NumTools > 0)
            {
                MainWindow.EnableView(true, ViewType.Tools);
            }
            else
            {
                MainWindow.ShowView(false, ViewType.Tools);
            }

            MainWindow.EnableView(true, ViewType.Offsets);
            MainWindow.EnableView(true, ViewType.GRBLConfig);

            if (!string.IsNullOrEmpty(GrblInfo.TrinamicDrivers))
            {
                MainWindow.EnableView(true, ViewType.TrinamicTuner);
            }
            else
            {
                MainWindow.ShowView(false, ViewType.TrinamicTuner);
            }

            MainWindow.GCodePush += GCode.File.AddBlock;
        }
Beispiel #6
0
 public void CloseFile()
 {
     GCodeSender.CloseFile();
 }
Beispiel #7
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);
            }
        }
Beispiel #8
0
        private void OnDataContextPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (sender is GrblViewModel)
            {
                switch (e.PropertyName)
                {
                case nameof(GrblViewModel.GrblState):
                    if (initOK == false && ((GrblViewModel)sender).GrblState.State != GrblStates.Alarm)
                    {
                        InitSystem();
                    }
                    break;

                case nameof(GrblViewModel.IsSleepMode):
                    EnableUI(!((GrblViewModel)sender).IsSleepMode);
                    break;

                case nameof(GrblViewModel.IsJobRunning):
                    MainWindow.ui.JobRunning = ((GrblViewModel)sender).IsJobRunning;
                    if (GrblInfo.ManualToolChange)
                    {
                        GrblCommand.ToolChange = MainWindow.ui.JobRunning ? "T{0}M6" : "M61Q{0}";
                    }
                    break;

                case nameof(GrblViewModel.Tool):
                    if (GrblInfo.ManualToolChange && ((GrblViewModel)sender).Tool != GrblConstants.NO_TOOL)
                    {
                        GrblWorkParameters.RemoveNoTool();
                    }
                    break;

                case nameof(GrblViewModel.GrblReset):
                    if (((GrblViewModel)sender).GrblReset)
                    {
                        initOK = null;
                        Activate(true, ViewType.GRBL);
                    }
                    //         Comms.com.WriteCommand(GrblConstants.CMD_GETPARSERSTATE);
                    break;

                case nameof(GrblViewModel.ParserState):
                    if (((GrblViewModel)sender).GrblReset)
                    {
                        EnableUI(true);
                        //  ((GrblViewModel)sender).GrblReset = false;
                    }
                    break;

                case nameof(GrblViewModel.FileName):
                    string filename = ((GrblViewModel)sender).FileName;
                    MainWindow.ui.WindowTitle = filename;
                    if (filename.StartsWith("SDCard:"))
                    {
                        sdStream = true;
                        MainWindow.EnableView(false, ViewType.GCodeViewer);
                    }
                    else if (filename.StartsWith("Wizard:"))
                    {
                        if (MainWindow.IsViewVisible(ViewType.GCodeViewer))
                        {
                            MainWindow.EnableView(false, ViewType.GCodeViewer);
// For now - rendering of G76 must be implemented first                                MainWindow.GCodeViewer.Open(filename, GCodeSender.GCode.Tokens);
                        }
                    }
                    else if (!string.IsNullOrEmpty(filename) && MainWindow.IsViewVisible(ViewType.GCodeViewer))
                    {
                        MainWindow.EnableView(true, ViewType.GCodeViewer);
                        GCodeSender.EnablePolling(false);
                        MainWindow.GCodeViewer.Open(filename, GCode.File.Tokens);
                        GCodeSender.EnablePolling(true);
                    }
                    break;
                }
            }
        }
        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);
            }
        }
Beispiel #10
0
        bool InitSystem()
        {
            initOK = true;
            int timeout = 5;

            using (new UIUtils.WaitCursor())
            {
                GCodeSender.EnablePolling(false);
                while (!GrblInfo.Get())
                {
                    if (--timeout == 0)
                    {
                        model.Message = (string)FindResource("MsgNoResponse");
                        return(false);
                    }
                    Thread.Sleep(500);
                }
                GrblAlarms.Get();
                GrblErrors.Get();
                GrblSettings.Load();
                if (GrblInfo.IsGrblHAL)
                {
                    GrblParserState.Get();
                    GrblWorkParameters.Get();
                }
                else
                {
                    GrblParserState.Get(true);
                }
                GCodeSender.EnablePolling(true);
            }

            GrblCommand.ToolChange = GrblInfo.ManualToolChange ? "M61Q{0}" : "T{0}";

            showProgramLimits();

            if (!AppConfig.Settings.GCodeViewer.IsEnabled)
            {
                tabGCode.Items.Remove(tab3D);
            }

            if (GrblInfo.NumAxes > 3)
            {
                limitsControl.Visibility = Visibility.Collapsed;
            }

            if (GrblInfo.LatheModeEnabled)
            {
                MainWindow.EnableView(true, ViewType.Turning);
                //      MainWindow.EnableView(true, ViewType.Parting);
                //      MainWindow.EnableView(true, ViewType.Facing);
                MainWindow.EnableView(true, ViewType.G76Threading);
            }
            else
            {
                MainWindow.ShowView(false, ViewType.Turning);
                MainWindow.ShowView(false, ViewType.Parting);
                MainWindow.ShowView(false, ViewType.Facing);
                MainWindow.ShowView(false, ViewType.G76Threading);
            }

            if (GrblInfo.HasSDCard)
            {
                MainWindow.EnableView(true, ViewType.SDCard);
            }
            else
            {
                MainWindow.ShowView(false, ViewType.SDCard);
            }

            if (GrblInfo.HasPIDLog)
            {
                MainWindow.EnableView(true, ViewType.PIDTuner);
            }
            else
            {
                MainWindow.ShowView(false, ViewType.PIDTuner);
            }

            if (GrblInfo.NumTools > 0)
            {
                MainWindow.EnableView(true, ViewType.Tools);
            }
            else
            {
                MainWindow.ShowView(false, ViewType.Tools);
            }

            if (GrblInfo.HasProbe && GrblSettings.ReportProbeCoordinates)
            {
                MainWindow.EnableView(true, ViewType.Probing);
            }

            MainWindow.EnableView(true, ViewType.Offsets);
            MainWindow.EnableView(true, ViewType.GRBLConfig);

            if (!string.IsNullOrEmpty(GrblInfo.TrinamicDrivers))
            {
                MainWindow.EnableView(true, ViewType.TrinamicTuner);
            }
            else
            {
                MainWindow.ShowView(false, ViewType.TrinamicTuner);
            }

            return(true);
        }
        private void InitSystem()
        {
            initOK = true;
            int timeout = 5;

            using (new UIUtils.WaitCursor())
            {
                GCodeSender.EnablePolling(false);
                while (!GrblInfo.Get())
                {
                    if (--timeout == 0)
                    {
                        model.Message = "Controller is not responding!";
                        initOK        = false;
                    }
                    Thread.Sleep(500);
                }
                GrblAlarms.Get();
                GrblErrors.Get();
                GrblSettings.Get();
                GrblParserState.Get();
                GrblWorkParameters.Get();
                GCodeSender.EnablePolling(true);
            }

            GrblCommand.ToolChange = GrblInfo.ManualToolChange ? "M61Q{0}" : "T{0}";

            if (keyboard == null)
            {
                keyboard = new KeypressHandler(model);
                GCodeSender.Configure(keyboard);
                gcodeRenderer.Configure();
            }

            showProgramLimits();

            if (!AppConfig.Settings.GCodeViewer.IsEnabled)
            {
                tabGCode.Items.Remove(tab3D);
            }

            if (GrblInfo.NumAxes > 3)
            {
                limitsControl.Visibility = Visibility.Collapsed;
            }

            if (GrblInfo.LatheModeEnabled)
            {
                MainWindow.EnableView(true, ViewType.Turning);
                //      MainWindow.EnableView(true, ViewType.Parting);
                //      MainWindow.EnableView(true, ViewType.Facing);
                MainWindow.EnableView(true, ViewType.G76Threading);
            }
            else
            {
                MainWindow.ShowView(false, ViewType.Turning);
                MainWindow.ShowView(false, ViewType.Parting);
                MainWindow.ShowView(false, ViewType.Facing);
                MainWindow.ShowView(false, ViewType.G76Threading);
            }

            if (GrblInfo.HasSDCard)
            {
                MainWindow.EnableView(true, ViewType.SDCard);
            }
            else
            {
                MainWindow.ShowView(false, ViewType.SDCard);
            }

            if (GrblInfo.HasPIDLog)
            {
                MainWindow.EnableView(true, ViewType.PIDTuner);
            }
            else
            {
                MainWindow.ShowView(false, ViewType.PIDTuner);
            }

            if (GrblInfo.NumTools > 0)
            {
                MainWindow.EnableView(true, ViewType.Tools);
            }
            else
            {
                MainWindow.ShowView(false, ViewType.Tools);
            }

            if (GrblInfo.HasProbe && GrblSettings.ReportProbeCoordinates)
            {
                MainWindow.EnableView(true, ViewType.Probing);
            }

            MainWindow.EnableView(true, ViewType.Offsets);
            MainWindow.EnableView(true, ViewType.GRBLConfig);

            if (!string.IsNullOrEmpty(GrblInfo.TrinamicDrivers))
            {
                MainWindow.EnableView(true, ViewType.TrinamicTuner);
            }
            else
            {
                MainWindow.ShowView(false, ViewType.TrinamicTuner);
            }
        }
        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);
            }
        }
 private void MainWindow_FileOpen()
 {
     GCodeSender.OpenFile();
 }
 void JobView_Load(object sender, EventArgs e)
 {
     GCodeSender.SetStreamingState(StreamingState.Idle);
 }
        private void InitSystem()
        {
            initOK = true;

            // TODO: check if grbl is in a state that allows replies
            using (new UIUtils.WaitCursor())
            {
                GCodeSender.EnablePolling(false);
                GrblInfo.Get();
                GrblSettings.Get();
                GrblParserState.Get();
                GrblWorkParameters.Get();
                GCodeSender.EnablePolling(true);
            }

            workParametersControl.ToolChangeCommand = GrblInfo.ManualToolChange ? "T{0}M6" : "T{0}";

            GCodeSender.Config();

            if (GrblInfo.LatheModeEnabled)
            {
                DRO.EnableLatheMode();
                signalsControl.SetLatheMode();
                MainWindow.EnableView(true, ViewType.Turning);
                MainWindow.EnableView(true, ViewType.Facing);
                MainWindow.EnableView(true, ViewType.G76Threading);
            }
            else
            {
                DRO.SetNumAxes(GrblInfo.NumAxes);
                signalsControl.SetNumAxes(GrblInfo.NumAxes);
                MainWindow.ShowView(false, ViewType.Turning);
                MainWindow.ShowView(false, ViewType.Facing);
                MainWindow.ShowView(false, ViewType.G76Threading);
            }

            if (GrblInfo.HasSDCard)
            {
                MainWindow.EnableView(true, ViewType.SDCard);
            }
            else
            {
                MainWindow.ShowView(false, ViewType.SDCard);
            }

            if (GrblInfo.HasPIDLog)
            {
                MainWindow.EnableView(true, ViewType.PIDTuner);
            }
            else
            {
                MainWindow.ShowView(false, ViewType.PIDTuner);
            }

            if (GrblInfo.NumTools > 0)
            {
                MainWindow.EnableView(true, ViewType.Tools);
            }
            else
            {
                MainWindow.ShowView(false, ViewType.Tools);
            }

            MainWindow.EnableView(true, ViewType.Offsets);
            MainWindow.EnableView(true, ViewType.GRBLConfig);

            if (!string.IsNullOrEmpty(GrblInfo.TrinamicDrivers))
            {
                MainWindow.EnableView(true, ViewType.TrinamicTuner);
            }
            else
            {
                MainWindow.ShowView(false, ViewType.TrinamicTuner);
            }

            MainWindow.GCodePush += UserUI_GCodePush;

            txtStatus.Text = "";
        }
Beispiel #16
0
        GCodeGenerator GCodeGenerator; //The generator that will home and cool

        /// <summary>
        /// Intialise a class that can read and send GCode line for line from
        /// a file.
        /// </summary>
        /// <param name="_GCodeSender">The fully intialised GCodeSender that will be used to send the GCode</param>
        public GCodeFileReader(GCodeSender _GCodeSender, GCodeGenerator _GCodeGenerator)
        {
            GCodeSender    = _GCodeSender;
            GCodeGenerator = _GCodeGenerator;
        }
Beispiel #17
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);
            }
        }
Beispiel #18
0
        private void InitSystem()
        {
            initOK = true;

            // TODO: check if grbl is in a state that allows replies
            using (new UIUtils.WaitCursor())
            {
                GCodeSender.EnablePolling(false);
                GrblInfo.Get();
                GrblSettings.Get();
                GrblParserState.Get();
                GrblWorkParameters.Get();
                GCodeSender.EnablePolling(true);
            }

            model.Message = string.Empty;

            GrblCommand.ToolChange = GrblInfo.ManualToolChange ? "M61Q{0}" : "T{0}";

            if (keyboard == null)
            {
                keyboard = new KeypressHandler(model);
                GCodeSender.Configure(keyboard);
                gcodeRenderer.Configure();
            }

            showProgramLimits();

            if (!AppConfig.Settings.GCodeViewer.IsEnabled)
            {
                tabGCode.Items.Remove(tab3D);
            }

            if (GrblInfo.NumAxes > 3)
            {
                limitsControl.Visibility = Visibility.Collapsed;
            }

            if (GrblInfo.LatheModeEnabled)
            {
                MainWindow.EnableView(true, ViewType.Turning);
                MainWindow.EnableView(true, ViewType.Facing);
                MainWindow.EnableView(true, ViewType.G76Threading);
            }
            else
            {
                MainWindow.ShowView(false, ViewType.Turning);
                MainWindow.ShowView(false, ViewType.Facing);
                MainWindow.ShowView(false, ViewType.G76Threading);
            }

            if (GrblInfo.HasSDCard)
            {
                MainWindow.EnableView(true, ViewType.SDCard);
            }
            else
            {
                MainWindow.ShowView(false, ViewType.SDCard);
            }

            if (GrblInfo.HasPIDLog)
            {
                MainWindow.EnableView(true, ViewType.PIDTuner);
            }
            else
            {
                MainWindow.ShowView(false, ViewType.PIDTuner);
            }

            if (GrblInfo.NumTools > 0)
            {
                MainWindow.EnableView(true, ViewType.Tools);
            }
            else
            {
                MainWindow.ShowView(false, ViewType.Tools);
            }

            MainWindow.EnableView(true, ViewType.Probing);
            MainWindow.EnableView(true, ViewType.Offsets);
            MainWindow.EnableView(true, ViewType.GRBLConfig);

            if (!string.IsNullOrEmpty(GrblInfo.TrinamicDrivers))
            {
                MainWindow.EnableView(true, ViewType.TrinamicTuner);
            }
            else
            {
                MainWindow.ShowView(false, ViewType.TrinamicTuner);
            }
        }
Beispiel #19
0
 void JobView_Load(object sender, EventArgs e)
 {
     GCodeSender.CallHandler(StreamingState.Idle, true);
 }
Beispiel #20
0
 public void CloseFile()
 {
     GCodeSender.CloseFile();
     gcodeRenderer.Close();
 }
Beispiel #21
0
        private void OnDataContextPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (sender is GrblViewModel)
            {
                switch (e.PropertyName)
                {
                case nameof(GrblViewModel.GrblState):
                    if (!Controller.ResetPending)
                    {
                        if (initOK == false && (sender as GrblViewModel).GrblState.State != GrblStates.Alarm)
                        {
                            Dispatcher.BeginInvoke(new System.Action(() => InitSystem()), DispatcherPriority.ApplicationIdle);
                        }
                    }
                    break;

                case nameof(GrblViewModel.IsGCLock):
                    MainWindow.ui.JobRunning = (sender as GrblViewModel).IsJobRunning;
                    //             MainWindow.EnableView(!(sender as GrblViewModel).IsGCLock, ViewType.Probing);
                    break;

                case nameof(GrblViewModel.IsSleepMode):
                    EnableUI(!(sender as GrblViewModel).IsSleepMode);
                    break;

                case nameof(GrblViewModel.IsJobRunning):
                    MainWindow.ui.JobRunning = (sender as GrblViewModel).IsJobRunning;
                    if (GrblInfo.ManualToolChange)
                    {
                        GrblCommand.ToolChange = (sender as GrblViewModel).IsJobRunning ? "T{0}M6" : "M61Q{0}";
                    }
                    break;

                case nameof(GrblViewModel.IsToolChanging):
                    MainWindow.ui.JobRunning = (sender as GrblViewModel).IsToolChanging || (sender as GrblViewModel).IsJobRunning;
                    break;

                case nameof(GrblViewModel.Tool):
                    if (GrblInfo.ManualToolChange && (sender as GrblViewModel).Tool != GrblConstants.NO_TOOL)
                    {
                        GrblWorkParameters.RemoveNoTool();
                    }
                    break;

                case nameof(GrblViewModel.GrblReset):
                    if ((sender as GrblViewModel).IsReady)
                    {
                        if (!Controller.ResetPending && (sender as GrblViewModel).GrblReset)
                        {
                            initOK = null;
                            Dispatcher.BeginInvoke(new System.Action(() => Activate(true, ViewType.GRBL)), DispatcherPriority.ApplicationIdle);
                        }
                    }
                    break;

                case nameof(GrblViewModel.ParserState):
                    if (!Controller.ResetPending && (sender as GrblViewModel).GrblReset)
                    {
                        EnableUI(true);
                        (sender as GrblViewModel).GrblReset = false;
                    }
                    break;

                case nameof(GrblViewModel.FileName):
                    string filename = (sender as GrblViewModel).FileName;
                    MainWindow.ui.WindowTitle = filename;

                    if (string.IsNullOrEmpty(filename))
                    {
                        MainWindow.CloseFile();
                    }
                    else if ((sender as GrblViewModel).IsSDCardJob)
                    {
                        MainWindow.EnableView(false, ViewType.GCodeViewer);
                    }
                    else if (filename.StartsWith("Wizard:"))
                    {
                        if (MainWindow.IsViewVisible(ViewType.GCodeViewer))
                        {
                            MainWindow.EnableView(true, ViewType.GCodeViewer);
                            gcodeRenderer.Open(GCode.File.Tokens);
                        }
                    }
                    else if (!string.IsNullOrEmpty(filename) && AppConfig.Settings.GCodeViewer.IsEnabled)
                    {
                        MainWindow.GCodeViewer.Open(GCode.File.Tokens);
                        MainWindow.EnableView(true, ViewType.GCodeViewer);
                        GCodeSender.EnablePolling(false);
                        gcodeRenderer.Open(GCode.File.Tokens);
                        GCodeSender.EnablePolling(true);
                    }
                    break;
                }
            }
        }
        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);
            }
        }