Exemplo n.º 1
0
        private void ExecuteExtendedFunction(string line)
        {
            var    lineParts    = line.Split(':');
            string functionName = lineParts[0].ToUpper();
            string parameters   = lineParts.Length > 1 ? lineParts[1] : "";

            switch (functionName)
            {
            case "!Z-TOP":
                _machine.MoveZServo(_machine.Settings.ZServoTopPosition);
                _machine.SendDwell(500);
                break;

            case "!Z-BOTTOM":
                _machine.MoveZServo(_machine.Settings.ZServoBottomPosition, true);
                break;

            case "!Z-LOAD":
                _machine.MoveZServo(_machine.Settings.ZServoLoadPosition);
                _machine.SendDwell(500);
                break;

            case "!END":
                ProgramFinished = true;
                break;

            case "!EXEC":
                ExecuteCode(GCodeFunctions.ExecuteGCodeFile(parameters), true);
                break;

            default:
                throw new Exception("Invalid extended function");
            }
        }
Exemplo n.º 2
0
        public void ExecuteCode(List <string> gCode, bool nestedCall = false)
        {
            int  linesParsed  = 0;
            int  linesToParse = gCode.Count;
            bool cancel       = false;

            SetMachineWorkingOffset();

            // Header File
            if (!nestedCall && _machine.Settings.ExecHeaderFile.Length > 0)
            {
                ExecuteCode(GCodeFunctions.ExecuteGCodeFile(_machine.Settings.ExecHeaderFile), true);
            }

            foreach (string line in gCode)
            {
                if (ProgramFinished)
                {
                    break;
                }

                string normalizedLine = line.Split('/')[0];             // The '/' signifies a remark to the end of the line
                normalizedLine = normalizedLine.Split('(')[0];          // The '(' signifies an inline/multiline remark in standard Gcode, but we're only treating it as a line comment or end of line comment
                normalizedLine = normalizedLine.Trim();

                // Raise event to notify caller of progress
                linesParsed++;
                if (!nestedCall && OnProgressNotify != null)
                {
                    OnProgressNotify(string.Format("Parsing G-Code: {0} of {1}", linesParsed, linesToParse), out cancel);
                }

                if (cancel)
                {
                    break;
                }
                if (normalizedLine.Length == 0)
                {
                    continue;
                }

                // --- Extended (non-gcode) functions begin with a '!'
                if (normalizedLine.StartsWith("!"))
                {
                    ExecuteExtendedFunction(normalizedLine);
                }

                // --- Everything else is gcode
                else
                {
                    var blocks = GCodeBlock.Parse(normalizedLine);

                    foreach (var block in blocks)
                    {
                        if (block.G.HasValue || block.T.HasValue)
                        {
                            ExecuteGBlock(block);
                        }
                        if (block.M.HasValue)
                        {
                            ExecuteMBlock(block);
                        }
                    }
                }
            }

            // Footer File
            if (!nestedCall && _machine.Settings.ExecFooterFile.Length > 0)
            {
                ExecuteCode(GCodeFunctions.ExecuteGCodeFile(_machine.Settings.ExecFooterFile), true);
            }
        }