Ejemplo n.º 1
0
        private void ParseGLine(string lineString, PrinterMachineInstruction processingMachineState)
        {
            // take off any comments before we check its length
            int commentIndex = lineString.IndexOf(';');

            if (commentIndex != -1)
            {
                lineString = lineString.Substring(0, commentIndex);
            }

            string[] splitOnSpace = lineString.Split(' ');
            string   onlyNumber   = splitOnSpace[0].Substring(1).Trim();

            switch (onlyNumber)
            {
            case "0":
                goto case "1";

            case "4":
            case "04":
                // wait a given number of miliseconds
                break;

            case "1":
                // get the x y z to move to
            {
                double valueX = 0;
                if (GCodeFile.GetFirstNumberAfter("X", lineString, ref valueX))
                {
                    processingMachineState.X = valueX;
                }
                double valueY = 0;
                if (GCodeFile.GetFirstNumberAfter("Y", lineString, ref valueY))
                {
                    processingMachineState.Y = valueY;
                }
                double valueZ = 0;
                if (GCodeFile.GetFirstNumberAfter("Z", lineString, ref valueZ))
                {
                    processingMachineState.Z = valueZ;
                }
                double valueE = 0;
                if (GCodeFile.GetFirstNumberAfter("E", lineString, ref valueE))
                {
                    if (processingMachineState.movementType == PrinterMachineInstruction.MovementTypes.Absolute)
                    {
                        processingMachineState.EPosition = valueE + amountOfAccumulatedEWhileParsing;
                    }
                    else
                    {
                        processingMachineState.EPosition += valueE;
                    }
                }
                double valueF = 0;
                if (GCodeFile.GetFirstNumberAfter("F", lineString, ref valueF))
                {
                    processingMachineState.FeedRate = valueF;
                }
            }

                if (!gcodeHasExplicitLayerChangeInfo)
                {
                    if (processingMachineState.Z != parsingLastZ || indexOfChangeInZ.Count == 0)
                    {
                        // if we changed z or there is a movement and we have never started a layer index
                        indexOfChangeInZ.Add(GCodeCommandQueue.Count);
                    }
                }
                parsingLastZ = processingMachineState.Position.z;
                break;

            case "10":                     // firmware retract
                break;

            case "11":                     // firmware unretract
                break;

            case "21":
                // set to metric
                break;

            case "28":
                // G28  Return to home position (machine zero, aka machine reference point)
                break;

            case "29":
                // G29 Probe the z-bed in 3 places
                break;

            case "30":
                // G30 Probe z in current position
                break;

            case "90":                     // G90 is Absolute Distance Mode
                processingMachineState.movementType = PrinterMachineInstruction.MovementTypes.Absolute;
                break;

            case "91":                     // G91 is Incremental Distance Mode
                processingMachineState.movementType = PrinterMachineInstruction.MovementTypes.Relative;
                break;

            case "92":
                // set current head position values (used to reset origin)
                double ePosition = 0;
                if (GetFirstNumberAfter("E", lineString, ref ePosition))
                {
                    // remember how much e position we just gave up
                    amountOfAccumulatedEWhileParsing = (processingMachineState.EPosition - ePosition);
                }
                break;

            case "130":
                //Set Digital Potentiometer value
                break;

            case "161":
                // home x,y axis minimum
                break;

            case "162":
                // home z axis maximum
                break;

            default:
                break;
            }
        }