Beispiel #1
0
        protected virtual void OnRaiseStreamEvent(StreamEventArgs e)
        {
            EventHandler <StreamEventArgs> handler = RaiseStreamEvent;

            if (handler != null)
            {
                handler(this, e);
            }
        }
        private void OnRaiseStreamEvent(object sender, StreamEventArgs e)
        {
            // only notify if estimated process-time > notifier intervall
            bool notifierEnable = ((double)Properties.Settings.Default.notifierMessageProgressInterval < VisuGCode.gcodeMinutes);

            if (isStreaming)
            {
                updateProgressBar(e.CodeProgress, e.BuffProgress);
                if (notifierEnable && Properties.Settings.Default.notifierMessageProgressEnable)
                {
                    if ((elapsed.Seconds % (int)(60 * Properties.Settings.Default.notifierMessageProgressInterval)) == 5) // offset 5 sec. to get message at start
                    {
                        if (notifierUpdateMarker)
                        {
                            notifierUpdateMarker = false;
                            string etime = string.Format("{0:00}:{1:00} hrs", elapsed.Hours, elapsed.Minutes);
                            string msg   = string.Format("{0}Duration   : {1} \r\nCode line  : {2,6}\r\nProcessed: {3,4:0.0} %\r\nGrbl Buffer: {4,3:0} %\r\nTime stamp: {5}", "", etime, e.CodeLineSent, e.CodeProgress, e.BuffProgress, getTimeStampString());//Properties.Settings.Default.notifierMessageProgress
                            if (Properties.Settings.Default.notifierMessageProgressTitle)
                            {
                                Notifier.sendMessage(msg, string.Format("{0,4:0.0} %", e.CodeProgress));
                            }
                            else
                            {
                                Notifier.sendMessage(msg);
                            }
                        }
                    }
                    else
                    {
                        notifierUpdateMarker = true;
                    }
                }
            }

            int actualCodeLine = e.CodeLineSent;

            if (actualCodeLine < 0)
            {
                actualCodeLine = 0;
            }
            if (e.CodeLineSent > fCTBCode.LinesCount)
            {
                actualCodeLine = fCTBCode.LinesCount - 1;
            }
            fCTBCode.Selection = fCTBCode.GetLine(actualCodeLine);

            fCTBCodeClickedLineNow = e.CodeLineSent - 1; // - 1;
            fCTBCodeMarkLine();                          // set Bookmark and marker in 2D-View
//            fCTBCode.DoCaretVisible();

            try {
                if (this.fCTBCode.InvokeRequired)
                {
                    this.fCTBCode.BeginInvoke((MethodInvoker) delegate() { this.fCTBCode.DoCaretVisible(); });
                }
                else
                {
                    this.fCTBCode.DoCaretVisible();
                }
            } catch (Exception er)  {
                Logger.Error(er, "OnRaiseStreamEvent fCTBCode.InvokeRequired ");
            }


            if (_diyControlPad != null)
            {
                _diyControlPad.sendFeedback("[" + e.Status.ToString() + "]");
            }

            if (Properties.Settings.Default.guiProgressShow)
            {
                VisuGCode.ProcessedPath.processedPathLine(e.CodeLineConfirmed);
            }

            if (logStreaming)
            {
                Logger.Trace("OnRaiseStreamEvent  {0}  line {1} ", e.Status.ToString(), e.CodeLineSent);
            }

            switch (e.Status)
            {
            case grblStreaming.lasermode:
                showLaserMode();
                break;

            case grblStreaming.reset:
                flagResetOffset = true;
                stopStreaming(false);
                if (e.CodeProgress < 0)
                {
                    setInfoLabel(_serial_form.lastError, Color.Fuchsia);
                }
                else
                {
                    setInfoLabel("Vers. " + _serial_form.grblVers, Color.Lime);
                }
                statusStripClear(1, 2, "grblStreaming.reset");
                toolTip1.SetToolTip(lbInfo, lbInfo.Text);
                timerUpdateControls = true; timerUpdateControlSource = "grblStreaming.reset";    //updateControls();
                if (_coordSystem_form != null)
                {
                    _coordSystem_form.showValues();
                }

                ControlPowerSaving.EnableStandby();
                VisuGCode.ProcessedPath.processedPathClear();
                break;

            case grblStreaming.error:
                Logger.Info("streaming error at line {0}", e.CodeLineConfirmed);
                statusStripSet(0, grbl.lastMessage, Color.Fuchsia);
                pbFile.ForeColor = Color.Red;

                int errorLine = e.CodeLineConfirmed - 1;
                if (isStreamingCheck)
                {
                    errorLine = e.CodeLineConfirmed - 2;
                }
                ErrorLines.Add(errorLine);
                markErrorLine(errorLine);

                setInfoLabel(Localization.getString("mainInfoErrorLine") + errorLine.ToString(), Color.Fuchsia);

                fCTBCode.BookmarkLine(actualCodeLine - 1);
                fCTBCode.DoSelectionVisible();

                if (notifierEnable)
                {
                    Notifier.sendMessage(string.Format("Streaming error at line {0}\r\nTime stamp: {1}", e.CodeLineConfirmed, getTimeStampString()), "Error");
                }
                break;

            case grblStreaming.ok:
                if (!isStreamingCheck)
                {
                    if (grbl.lastErrorNr <= 0)
                    {
                        setInfoLabel(lblInfoOkString + "(" + (e.CodeLineSent + 1).ToString() + ")", Color.Lime);

                        signalPlay = 0;
                        btnStreamStart.BackColor = SystemColors.Control;
                    }
                }
                break;

            case grblStreaming.finish:
                Logger.Info("streaming finished ok {0}", isStreamingOk);
                if (isStreamingOk)
                {
                    if (isStreamingCheck)
                    {
                        setInfoLabel(Localization.getString("mainInfoFinishCheck"), Color.Lime);
                    }                                                                                    // "Finish checking G-Code"; }
                    else
                    {
                        setInfoLabel(Localization.getString("mainInfoFinishSend"), Color.Lime);
                    }                                                                                   // "Finish sending G-Code"; }
                }
                MainTimer.Stop();
                MainTimer.Start();
                timerUpdateControls = true; timerUpdateControlSource = "grblStreaming.finish"; //updateControls();
                saveStreamingStatus(0);
                showPicBoxBgImage           = false;                                           // don't show background image anymore
                pictureBox1.BackgroundImage = null;
                resetStreaming();

                if (notifierEnable && !notifierUpdateMarkerFinish)        // just notify once
                {
                    notifierUpdateMarkerFinish = true;
                    string msg = string.Format("{0}\r\nDuration  : {1} (hh:mm:ss)\r\nCode line : {2}\r\nTime stamp: {3}", Properties.Settings.Default.notifierMessageFinish, elapsed.ToString(@"hh\:mm\:ss"), fCTBCode.LinesCount, getTimeStampString());
                    if (Properties.Settings.Default.notifierMessageProgressTitle)
                    {
                        Notifier.sendMessage(msg, "100 %");
                    }
                    else
                    {
                        Notifier.sendMessage(msg);
                    }
                }
                break;

            case grblStreaming.waitidle:
                //          timerUpdateControls = true; timerUpdateControlSource = "grblStreaming.waitidle";//updateControls();// true);
                btnStreamStart.Image = Properties.Resources.btn_play;
                setInfoLabel(Localization.getString("mainInfoWaitIdle") + e.CodeLineSent.ToString() + ")", Color.Yellow);
                break;

            case grblStreaming.pause:
                //          lock (this)       2020-12-15 removed
            {
                signalPlay = 1;
                setInfoLabel(Localization.getString("mainInfoPause") + e.CodeLineSent.ToString() + ")", Color.Yellow);
                btnStreamStart.Image = Properties.Resources.btn_play;
                isStreamingPause     = true;
                MainTimer.Stop();
                MainTimer.Start();
                timerUpdateControls = true; timerUpdateControlSource = "grblStreaming.pause";        //updateControls(true);

                saveStreamingStatus(e.CodeLineSent);

                if (Properties.Settings.Default.flowControlEnable)         // send extra Pause-Code in MainTimer_Tick from Properties.Settings.Default.flowControlText
                {
                    delayedSend = 2;
                }

                if (logStreaming)
                {
                    Logger.Trace("OnRaiseStreamEvent - pause: {0}  in line:{1}", fCTBCode.Lines[fCTBCodeClickedLineNow], fCTBCodeClickedLineNow);
                }

                if (fCTBCode.Lines[fCTBCodeClickedLineNow].Contains("M0") && fCTBCode.Lines[fCTBCodeClickedLineNow].Contains("Tool"))          // keyword set in gcodeRelated 1132
                {
                    signalShowToolExchangeMessage = true; if (logStreaming)
                    {
                        Logger.Trace("OnRaiseStreamEvent trigger ToolExchangeMessage");
                    }
                }
                else
                {
                    if (notifierEnable)
                    {
                        Notifier.sendMessage("grbl Pause", "Pause");
                    }
                }
                //  if (Properties.Settings.Default.importGCToolChangeCode.Length > 1)
                //  {   processCommands(Properties.Settings.Default.importGCToolChangeCode); }
            }
            break;

            case grblStreaming.toolchange:
                timerUpdateControls  = true; timerUpdateControlSource = "grblStreaming.toolchange";   // updateControls();
                btnStreamStart.Image = Properties.Resources.btn_play;
                setInfoLabel(Localization.getString("mainInfoToolChange"), Color.Yellow);
                cBTool.Checked = _serial_form.toolInSpindle;
                break;

            case grblStreaming.stop:
                timerUpdateControls = true; timerUpdateControlSource = "grblStreaming.stop";    // updateControls();
                setInfoLabel(Localization.getString("mainInfoStopStream") + e.CodeLineSent.ToString() + ")", Color.Fuchsia);

                if (Properties.Settings.Default.flowControlEnable)     // send extra Pause-Code in MainTimer_Tick from Properties.Settings.Default.flowControlText
                {
                    delayedSend = 2;
                }
                break;

            default:
                break;
            }

            lastLabelInfoText = lbInfo.Text;
            //          lbInfo.Text += overrideMessage;
            if (this.lbInfo.InvokeRequired)
            {
                this.lbInfo.BeginInvoke((MethodInvoker) delegate() { this.lbInfo.Text += overrideMessage; });
            }
            else
            {
                this.lbInfo.Text += overrideMessage;
            }
        }
Beispiel #3
0
 protected virtual void OnRaiseStreamEvent(StreamEventArgs e)
 {
     RaiseStreamEvent?.Invoke(this, e);
 }
Beispiel #4
0
/***** Receive streaming status from serial COM *****/
        private void OnRaiseStreamEvent(object sender, StreamEventArgs e)
        {
            if (isStreaming)
            {
                updateProgressBar((int)e.CodeProgress, (int)e.BuffProgress);
            }

            int actualCodeLine = e.CodeLineSent;

            if (actualCodeLine < 0)
            {
                actualCodeLine = 0;
            }
            if (e.CodeLineSent > fCTBCode.LinesCount)
            {
                actualCodeLine = fCTBCode.LinesCount - 1;
            }
            fCTBCode.Selection = fCTBCode.GetLine(actualCodeLine);

            fCTBCodeClickedLineNow = e.CodeLineSent - 1; // - 1;
            fCTBCodeMarkLine();                          // set Bookmark and marker in 2D-View
            fCTBCode.DoCaretVisible();

            if (_diyControlPad != null)
            {
                _diyControlPad.sendFeedback("[" + e.Status.ToString() + "]");
            }

            if (Properties.Settings.Default.guiProgressShow)
            {
                VisuGCode.ProcessedPath.processedPathLine(e.CodeLineConfirmed);
            }

            if (logStreaming)
            {
                Logger.Trace("OnRaiseStreamEvent  {0}  line {1} ", e.Status.ToString(), e.CodeLineSent);
            }

            switch (e.Status)
            {
            case grblStreaming.lasermode:
                showLaserMode();
                break;

            case grblStreaming.reset:
                flagResetOffset = true;
                stopStreaming(false);
                if (e.CodeProgress < 0)
                {
                    lbInfo.Text      = _serial_form.lastError;
                    lbInfo.BackColor = Color.Fuchsia;
                }
                else
                {
                    lbInfo.Text      = "Vers. " + _serial_form.grblVers;
                    lbInfo.BackColor = Color.Lime;
                }
                statusStripClear(1, 2);
                toolTip1.SetToolTip(lbInfo, lbInfo.Text);
                timerUpdateControls = true; timerUpdateControlSource = "grblStreaming.reset";    //updateControls();
                if (_coordSystem_form != null)
                {
                    _coordSystem_form.showValues();
                }

                ControlPowerSaving.EnableStandby();
                VisuGCode.ProcessedPath.processedPathClear();
                break;

            case grblStreaming.error:
                Logger.Info("streaming error at line {0}", e.CodeLineConfirmed);
                statusStripSet(1, grbl.lastMessage, Color.Fuchsia);
                //              isStreaming = false;
                //              isStreamingCheck = false;
                pbFile.ForeColor = Color.Red;
                lbInfo.Text      = Localization.getString("mainInfoErrorLine") + e.CodeLineSent.ToString();
                lbInfo.BackColor = Color.Fuchsia;
                fCTBCode.BookmarkLine(actualCodeLine - 1);
                fCTBCode.DoSelectionVisible();
                fCTBCode.CurrentLineColor = Color.Red;
                //               isStreamingOk = false;
                break;

            case grblStreaming.ok:
                if (!isStreamingCheck)
                {
//                        updateControls();
                    lbInfo.Text              = lblInfoOkString + "(" + (e.CodeLineSent + 1).ToString() + ")";
                    lbInfo.BackColor         = Color.Lime;
                    signalPlay               = 0;
                    btnStreamStart.BackColor = SystemColors.Control;
                }
                break;

            case grblStreaming.finish:
                Logger.Info("streaming finished ok {0}", isStreamingOk);
                if (isStreamingOk)
                {
                    if (isStreamingCheck)
                    {
                        lbInfo.Text = Localization.getString("mainInfoFinishCheck");
                    }                                                                      // "Finish checking G-Code"; }
                    else
                    {
                        lbInfo.Text = Localization.getString("mainInfoFinishSend");
                    }                                                                     // "Finish sending G-Code"; }
                    lbInfo.BackColor = Color.Lime;
                }
                MainTimer.Stop();
                MainTimer.Start();
                timerUpdateControls = true; timerUpdateControlSource = "grblStreaming.finish"; //updateControls();
                saveStreamingStatus(0);
                showPicBoxBgImage           = false;                                           // don't show background image anymore
                pictureBox1.BackgroundImage = null;
                resetStreaming();
                break;

            case grblStreaming.waitidle:
                timerUpdateControls  = true; timerUpdateControlSource = "grblStreaming.waitidle";   //updateControls();// true);
                btnStreamStart.Image = Properties.Resources.btn_play;
                //                  isStreamingPause = true;
                lbInfo.Text      = Localization.getString("mainInfoWaitIdle") + e.CodeLineSent.ToString() + ")";
                lbInfo.BackColor = Color.Yellow;
                break;

            case grblStreaming.pause:
                lock (this)
                {
                    signalPlay           = 1;
                    lbInfo.BackColor     = Color.Yellow;
                    lbInfo.Text          = Localization.getString("mainInfoPause") + e.CodeLineSent.ToString() + ")";
                    btnStreamStart.Image = Properties.Resources.btn_play;
                    isStreamingPause     = true;
                    MainTimer.Stop();
                    MainTimer.Start();
                    timerUpdateControls = true; timerUpdateControlSource = "grblStreaming.pause";    //updateControls(true);

                    saveStreamingStatus(e.CodeLineSent);

                    if (Properties.Settings.Default.flowControlEnable)     // send extra Pause-Code in MainTimer_Tick from Properties.Settings.Default.flowControlText
                    {
                        delayedSend = 2;
                    }

                    if (logStreaming)
                    {
                        Logger.Trace("OnRaiseStreamEvent - pause: {0}  in line:{1}", fCTBCode.Lines[fCTBCodeClickedLineNow], fCTBCodeClickedLineNow);
                    }

                    if (fCTBCode.Lines[fCTBCodeClickedLineNow].Contains("M0") && fCTBCode.Lines[fCTBCodeClickedLineNow].Contains("Tool"))      // keyword set in gcodeRelated 1132
                    {
                        signalShowToolExchangeMessage = true;   if (logStreaming)
                        {
                            Logger.Trace("OnRaiseStreamEvent trigger ToolExchangeMessage");
                        }
                    }

                    //  if (Properties.Settings.Default.importGCToolChangeCode.Length > 1)
                    //  {   processCommands(Properties.Settings.Default.importGCToolChangeCode); }
                }
                break;

            case grblStreaming.toolchange:
                timerUpdateControls  = true; timerUpdateControlSource = "grblStreaming.toolchange";   // updateControls();
                btnStreamStart.Image = Properties.Resources.btn_play;
                lbInfo.Text          = Localization.getString("mainInfoToolChange");
                lbInfo.BackColor     = Color.Yellow;
                cBTool.Checked       = _serial_form.toolInSpindle;
                break;

            case grblStreaming.stop:
                timerUpdateControls = true; timerUpdateControlSource = "grblStreaming.stop";    // updateControls();
                lbInfo.Text         = Localization.getString("mainInfoStopStream") + e.CodeLineSent.ToString() + ")";
                lbInfo.BackColor    = Color.Fuchsia;

                if (Properties.Settings.Default.flowControlEnable)     // send extra Pause-Code in MainTimer_Tick from Properties.Settings.Default.flowControlText
                {
                    delayedSend = 2;
                }
                //                  VisuGCode.ProcessedPath.processedPathClear();
                break;

            default:
                break;
            }

            lastLabelInfoText = lbInfo.Text;
            lbInfo.Text      += overrideMessage;
        }