Ejemplo n.º 1
0
/**********************************************************************************
*  preProcessStreaming copy line by line (requestSend(line)) to sendBuffer until
*  grbl-buffer (grblBufferFree) is filled, M0 or M30 or buffer-end reached.
*  Insert script-code on tool change.
*  requestSend -> processSend -> sendLine  -  dec. grblBufferFree
*  called in startStreaming, pauseStreaming (to restart) and timer
**********************************************************************************/
        private void preProcessStreaming()
        {
            int lengthToSend = streamingBuffer.LengthSent() + 1;

            if (waitForIdle || isStreamingRequestPause || (countPreventIdle > 0))
            {
                return;
            }

            while ((streamingBuffer.IndexSent < streamingBuffer.Count) && (grblBufferFree >= lengthToSend) && !waitForIdle && (streamingStateNow != grblStreaming.pause) && externalCOMReady())
            {
                lock (sendDataLock)
                {
                    string line = streamingBuffer.GetSentLine();
                    if ((line == "OV") || (line == "UR"))
                    {
                        Logger.Error("preProcessStreaming read:{0} from  streamingBuffer index:{1} count:{2}", line, streamingBuffer.IndexSent, streamingBuffer.Count);
                        break;
                    }
                    streamingStateNow = grblStreaming.ok;       // default status

                    int cmdMNr = gcode.getIntGCode('M', line);

                    if ((replaceFeedRate) && (gcode.getStringValue('F', line) != ""))
                    {
                        string old_value = gcode.getStringValue('F', line);
                        replaceFeedRateCmdOld = old_value;
                        line = line.Replace(old_value, replaceFeedRateCmd);
                        streamingBuffer.SetSentLine(line);
                    }

                    if ((replaceSpindleSpeed) && (gcode.getStringValue('S', line) != ""))
                    {
                        string old_value = gcode.getStringValue('S', line);
                        line = line.Replace(old_value, replaceSpindleSpeedCmd);
                        replaceSpindleSpeedCmdOld = old_value;
                        streamingBuffer.SetSentLine(line);
                    }

                    #region M0                              // Program pause
                    if ((cmdMNr == 0) && !isStreamingCheck) // M0 request pause
                    {
                        if (!Properties.Settings.Default.guiDisableProgramPause)
                        {
                            if (logStartStop || logReceive)
                            {
                                Logger.Trace("[Pause streaming - skip M0 - wait for IDLE]  indx-sent:{0}  line:{1} lineNr:{2} grblBufferFree:{3}", streamingBuffer.IndexSent, streamingBuffer.GetSentLine(), streamingBuffer.GetSentLineNr(), grblBufferFree);
                            }
                            addToLog("[Pause streaming - skip M0 line:" + streamingBuffer.GetSentLineNr() + "]");
                            lineStreamingPause = streamingBuffer.GetSentLineNr();

                            if (grblStateNow == grblState.idle)
                            {
                                requestSend("G4 P1");   // changed from 2 to 1 2021-01-26
                                grblStateNow          = grblStateLast = grblState.unknown;
                                countPreventInterlock = 10;
                            }

                            isStreamingRequestPause = true;
                            streamingStateNow       = grblStreaming.waitidle;
                            waitForIdle             = true;             // block further sending
                            waitForOk      = false;
                            getParserState = true;                      // ask for parser state
                            line           = "(M0)";
                        }
                    }
                    #endregion

                    if (isMarlin)
                    {
                        if (updateMarlinPosition || (--insertMarlinCounter <= 0))
                        {   //requestSend("M114", streamingBuffer.GetSentLineNr(), false);    // insert getPosition commands
                            sendBuffer.Add("M114", streamingBuffer.GetSentLineNr());
                            getMarlinPositionWasSent = true;
                            streamingBuffer.LineWasSent();
                            streamingStateOld   = streamingStateNow;
                            lengthToSend        = streamingBuffer.LengthSent() + 1; // update while-variable
                            insertMarlinCounter = insertMarlinCounterReload;
                        }
                        updateMarlinPosition = false;
                    }
                    //           requestSend(line, streamingBuffer.GetSentLineNr(), false);   // fill sendBuffer,
                    sendBuffer.Add(line, streamingBuffer.GetSentLineNr());
                    if (logEnable)
                    {
                        System.IO.File.AppendAllText(Application.StartupPath + "\\logSendBuffer.nc", line + "\r\n");            // clear file
                    }
                    streamingBuffer.LineWasSent();
                    streamingStateOld = streamingStateNow;
                    lengthToSend      = streamingBuffer.LengthSent() + 1; // update while-variable
                }                                                         // lock
                processSend();
                //                Logger.Trace("preProcessStreaming sent {0}  lengthToSend {1}  grblBufferFree {2} 3busy {3} countPreventIdle {4} line {5}", streamingBuffer.IndexSent, lengthToSend, grblBufferFree, serial3Busy, countPreventIdle, line);
            }   // while

            if (streamingStateNow != grblStreaming.pause)
            {
                if (trgEvent)
                {
                    sendStreamEvent(streamingStateNow);
                }
                trgEvent = false;
            }                                                                            // streaming in preProcessStreaming
        }
Ejemplo n.º 2
0
/**********************************************************************************
*  preProcessStreaming copy line by line (requestSend(line)) to sendBuffer until
*  grbl-buffer (grblBufferFree) is filled, M0 or M30 or buffer-end reached.
*  Insert script-code on tool change.
*  requestSend -> processSend -> sendLine  -  dec. grblBufferFree
*  called in startStreaming, pauseStreaming (to restart) and timer
**********************************************************************************/
        private void preProcessStreaming()
        {
            int lengthToSend = streamingBuffer.LengthSent() + 1;

            if (waitForIdle || isStreamingRequestPause)
            {
                return;
            }

            while ((streamingBuffer.IndexSent <= streamingBuffer.Count) && (grblBufferFree >= lengthToSend) && !waitForIdle && (streamingStateNow != grblStreaming.pause))
            {
                string line = streamingBuffer.GetSentLine();
                streamingStateNow = grblStreaming.ok;       // default status

                int cmdMNr = gcode.getIntGCode('M', line);

                if ((replaceFeedRate) && (gcode.getStringValue('F', line) != ""))
                {
                    string old_value = gcode.getStringValue('F', line);
                    replaceFeedRateCmdOld = old_value;
                    line = line.Replace(old_value, replaceFeedRateCmd);
                    streamingBuffer.SetSentLine(line);
                }

                if ((replaceSpindleSpeed) && (gcode.getStringValue('S', line) != ""))
                {
                    string old_value = gcode.getStringValue('S', line);
                    line = line.Replace(old_value, replaceSpindleSpeedCmd);
                    replaceSpindleSpeedCmdOld = old_value;
                    streamingBuffer.SetSentLine(line);
                }

                #region M0                              // Program pause
                if ((cmdMNr == 0) && !isStreamingCheck) // M0 request pause
                {
                    if (!Properties.Settings.Default.guiDisableProgramPause)
                    {
                        if (logStartStop || logReceive)
                        {
                            Logger.Trace("[Pause streaming - skip M0 - wait for IDLE]  indx-sent:{0}  line:{1} lineNr:{2} grblBufferFree:{3}", streamingBuffer.IndexSent, streamingBuffer.GetSentLine(), streamingBuffer.GetSentLineNr(), grblBufferFree);
                        }
                        addToLog("[Pause streaming - skip M0 line:" + streamingBuffer.GetSentLineNr() + "]");
                        lineStreamingPause = streamingBuffer.GetSentLineNr();

                        if (grblStateNow == grblState.idle)
                        {
                            requestSend("G4 P2");
                            grblStateNow          = grblStateLast = grblState.unknown;
                            countPreventInterlock = 10;
                        }

                        isStreamingRequestPause = true;
                        streamingStateNow       = grblStreaming.waitidle;
                        waitForIdle             = true;             // block further sending
                        waitForOk      = false;
                        getParserState = true;                      // ask for parser state
                        line           = "(M0)";
                    }
                }
                #endregion

                requestSend(line, streamingBuffer.GetSentLineNr(), false);                                  // fill sendBuffer,
                streamingBuffer.LineWasSent();
                streamingStateOld = streamingStateNow;
                lengthToSend      = streamingBuffer.LengthSent() + 1; // update while-variable
            }                                                         // while

            if (streamingStateNow != grblStreaming.pause)
            {
                sendStreamEvent(streamingStateNow);                 // streaming in preProcessStreaming
            }
        }