Esempio n. 1
0
        public override void OnLoad(EventArgs args)
        {
            base.OnLoad(args);

            // Replace with calibration template code
            //await templatePrinter.PrintTemplate(verticalLayout: true);
            //await templatePrinter.PrintTemplate(verticalLayout: false);

            Task.Run(async() =>
            {
                var sketch1 = new GCodeSketch(printer)
                {
                    Speed         = (int)(printer.Settings.GetValue <double>(SettingsKey.first_layer_speed) * 60),
                    RetractLength = printer.Settings.GetValue <double>(SettingsKey.retract_length),
                    RetractSpeed  = printer.Settings.GetValue <double>(SettingsKey.retract_speed) * 60,
                    RetractLift   = printer.Settings.GetValue <double>(SettingsKey.retract_lift),
                    TravelSpeed   = printer.Settings.GetValue <double>(SettingsKey.travel_speed) * 60,
                };

                var sketch2 = new GCodeSketch(printer)
                {
                    Speed         = sketch1.Speed,
                    RetractLength = sketch1.RetractLength,
                    RetractSpeed  = sketch1.RetractSpeed,
                    RetractLift   = sketch1.RetractLift,
                    TravelSpeed   = sketch1.TravelSpeed
                };

                //gcodeSketch.WriteRaw("G92 E0");
                sketch1.WriteRaw("; LAYER: 0");
                sketch1.WriteRaw("; LAYER_HEIGHT: 0.2");


                sketch1.SetTool("T0");
                sketch2.SetTool("T1");
                sketch1.PenUp();

                templatePrinter.BuildTemplate(sketch1, sketch2, verticalLayout: true);
                templatePrinter.BuildTemplate(sketch1, sketch2, verticalLayout: false);


                string outputPath = Path.Combine(
                    ApplicationDataStorage.Instance.GCodeOutputPath,
                    $"nozzle-offset-template-combined.gcode");

                File.WriteAllText(outputPath, sketch1.ToGCode() + "\r\n" + sketch2.ToGCode());

                // HACK: update state needed to be set before calling StartPrint
                printer.Connection.CommunicationState = CommunicationStates.PreparingToPrint;

                await printer.Connection.StartPrint(outputPath, allowRecovery: false);

                // Wait for print start
                while (!printer.Connection.PrintIsActive)
                {
                    Thread.Sleep(500);
                }

                // Wait for print finished
                while (printer.Connection.PrintIsActive)
                {
                    Thread.Sleep(500);
                }

                if (printer.Settings.GetValue <bool>(SettingsKey.z_homes_to_max))
                {
                    printer.Connection.HomeAxis(PrinterConnection.Axis.Z);
                }
                else
                {
                    printer.Connection.MoveRelative(PrinterConnection.Axis.Z, 20, printer.Settings.Helpers.ManualMovementSpeeds().Z);

                    printer.Connection.MoveAbsolute(PrinterConnection.Axis.Y,
                                                    printer.Bed.Bounds.Top,
                                                    printer.Settings.Helpers.ManualMovementSpeeds().Y);
                }
            });
        }
        public override void OnLoad(EventArgs args)
        {
            if (!this.HasBeenClosed)
            {
                this.NextButton.Enabled = true;
            }

            base.OnLoad(args);

            // Replace with calibration template code
            //await templatePrinter.PrintTemplate(verticalLayout: true);
            //await templatePrinter.PrintTemplate(verticalLayout: false);

            Task.Run(async() =>
            {
                var gcodeSketch = new GCodeSketch()
                {
                    Speed = (int)(printer.Settings.GetValue <double>(SettingsKey.first_layer_speed) * 60)
                };

                //gcodeSketch.WriteRaw("G92 E0");
                gcodeSketch.WriteRaw("; LAYER: 0");
                gcodeSketch.WriteRaw("; LAYER_HEIGHT: 0.2");

                templatePrinter.BuildTemplate(gcodeSketch, verticalLayout: true);
                templatePrinter.BuildTemplate(gcodeSketch, verticalLayout: false);

                string outputPath = Path.Combine(
                    ApplicationDataStorage.Instance.GCodeOutputPath,
                    $"nozzle-offset-template-combined.gcode");

                File.WriteAllText(outputPath, gcodeSketch.ToGCode());

                // HACK: update state needed to be set before calling StartPrint
                printer.Connection.CommunicationState = CommunicationStates.PreparingToPrint;

                await printer.Connection.StartPrint(outputPath);

                // Wait for print start
                while (!printer.Connection.PrintIsActive)
                {
                    Thread.Sleep(500);
                }

                // Wait for print finished
                while (printer.Connection.PrintIsActive)
                {
                    Thread.Sleep(500);
                }

                if (printer.Settings.GetValue <bool>(SettingsKey.z_homes_to_max))
                {
                    printer.Connection.HomeAxis(PrinterConnection.Axis.Z);
                }
                else
                {
                    printer.Connection.MoveRelative(PrinterConnection.Axis.Z, 20, printer.Settings.Helpers.ManualMovementSpeeds().Z);

                    printer.Connection.MoveAbsolute(PrinterConnection.Axis.Y,
                                                    printer.Bed.Bounds.Top,
                                                    printer.Settings.Helpers.ManualMovementSpeeds().Y);
                }
            });
        }