Пример #1
0
    /// <summary>
    ///     Loads all gcode from a file into memory and links all variables in the gcode into a structured class.
    /// </summary>
    /// <param name="filename">The name of the file where to load the gcode from.</param>
    /// <param name="newCommands">The list where all gcode commands will be stored in.</param>
    private void Load(string filename, List <GcodeCommand> newCommands)
    {
        long beginTime = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;

        newCommands.Clear();
        ModelLoaded = false;

        var    filestream = new System.IO.FileStream(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read);
        var    fileReader = new System.IO.StreamReader(filestream, System.Text.Encoding.UTF8, true, 128);
        string line;

        while ((line = fileReader.ReadLine()) != null)
        {
            var command = new GcodeCommand(line);
            if (command.IsValid())
            {
                newCommands.Add(command);
            }
            else
            {
                command = null;
            }
        }
        ModelLoaded = true;

        long endTime = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;

        Debug.Log("GCODE_LOADER (LOAD_TIME:" + (endTime - beginTime) + "ms, LINES:" + Commands.Count + ")");
    }
Пример #2
0
    /// <summary>
    ///     Determines the command to execute and then calls the matching function with parameters to the Printer object.
    /// </summary>
    /// <param name="command">The command object that will contain all information of the command.</param>
    /// <param name="printer">The printer object that requested a new command.</param>
    private void ExecuteCommand(GcodeCommand command, Printer printer)
    {
        //string startCommand = commando[0].Key.ToString() + (int)commando[0].Value;
        switch (command.GetCommandType())
        {
        case GMcodes.Move0:
        case GMcodes.Move1:
            printer.Move(command.X, command.Y, command.Z, command.E, command.F);
            break;

        case GMcodes.HomeAxis:
            printer.HomeAllAxis();
            break;

        case GMcodes.SetExtruderTemperature1:     // Which value is different for different type of printers.
        case GMcodes.SetExtruderTemperature2:
            printer.SetExtruderTemperature(command.S);
            break;

        case GMcodes.SetBedTemperature1:     // Which value is different for different type of printers.
        case GMcodes.SetBedTemperature2:
            printer.SetBedTemperature(command.S);
            break;

        default:
            break;
        }
    }