Update pause handling stream layer number detection
- Add test for layer number detection - GetLayerNumber(line) - Issue MatterHackers/MCCentral#5024 Read thread exited with S3D gcode
This commit is contained in:
parent
e4bff0feb1
commit
2f44b8e5c0
3 changed files with 62 additions and 23 deletions
|
|
@ -28,6 +28,8 @@ either expressed or implied, of the FreeBSD Project.
|
|||
*/
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using MatterHackers.Agg;
|
||||
using MatterHackers.VectorMath;
|
||||
|
|
@ -36,7 +38,7 @@ namespace MatterControl.Printing
|
|||
{
|
||||
public abstract class GCodeFile
|
||||
{
|
||||
public static string PostProcessedExtension = ".postprocessed.gcode";
|
||||
public const string PostProcessedExtension = ".postprocessed.gcode";
|
||||
|
||||
#if __ANDROID__
|
||||
protected const int Max32BitFileSize = 10000000; // 10 megs
|
||||
|
|
@ -104,11 +106,39 @@ namespace MatterControl.Printing
|
|||
return checksum;
|
||||
}
|
||||
|
||||
public static bool IsLayerChange(string lineString)
|
||||
private static Regex firstDigitsAfterToken = new Regex("\\d+", RegexOptions.CultureInvariant | RegexOptions.Compiled);
|
||||
|
||||
private static string[] layerLineStartTokens = new[]
|
||||
{
|
||||
return lineString.StartsWith("; LAYER:")
|
||||
|| lineString.StartsWith(";LAYER:")
|
||||
|| lineString.StartsWith("; layer ");
|
||||
"; LAYER:",
|
||||
";LAYER:",
|
||||
"; layer ",
|
||||
};
|
||||
|
||||
public static bool IsLayerChange(string line)
|
||||
{
|
||||
return layerLineStartTokens.Any(l => line.StartsWith(l));
|
||||
}
|
||||
|
||||
public static int GetLayerNumber(string line)
|
||||
{
|
||||
var layerToken = layerLineStartTokens.FirstOrDefault(t => line.StartsWith(t));
|
||||
|
||||
if (layerToken != null)
|
||||
{
|
||||
line = line.Substring(layerToken.Length);
|
||||
|
||||
// Find the first digits after the layer start token
|
||||
var match = firstDigitsAfterToken.Match(line);
|
||||
|
||||
if (match.Success
|
||||
&& int.TryParse(match.Value, out int layerNumber))
|
||||
{
|
||||
return layerNumber;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static bool FileTooBigToLoad(Stream fileStream)
|
||||
|
|
|
|||
|
|
@ -228,13 +228,14 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
|
|||
|
||||
if (GCodeFile.IsLayerChange(lineToSend))
|
||||
{
|
||||
string layerNumber = lineToSend.Split(':')[1];
|
||||
int layerNumber = GCodeFile.GetLayerNumber(lineToSend);
|
||||
|
||||
if (PauseOnLayer(layerNumber))
|
||||
{
|
||||
// make the string 1 based (the internal code is 0 based)
|
||||
int layerIndex;
|
||||
int.TryParse(layerNumber, out layerIndex);
|
||||
DoPause(PauseReason.PauseLayerReached, layerIndex + 1);
|
||||
this.DoPause(
|
||||
PauseReason.PauseLayerReached,
|
||||
// make the layer 1 based (the internal code is 0 based)
|
||||
layerNumber + 1);
|
||||
}
|
||||
}
|
||||
else if (lineToSend.StartsWith("M226")
|
||||
|
|
@ -318,18 +319,17 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
|
|||
}
|
||||
}
|
||||
|
||||
private bool PauseOnLayer(string layer)
|
||||
private bool PauseOnLayer(int layerNumber)
|
||||
{
|
||||
int layerNumber;
|
||||
var printerRecoveryStream = internalStream as PrintRecoveryStream;
|
||||
|
||||
if (int.TryParse(layer, out layerNumber)
|
||||
&& printer.Settings.Helpers.LayerToPauseOn().Contains(layerNumber)
|
||||
if (printer.Settings.Helpers.LayerToPauseOn().Contains(layerNumber)
|
||||
&& (printerRecoveryStream == null
|
||||
|| printerRecoveryStream.RecoveryState == RecoveryState.PrintingToEnd))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -126,7 +126,7 @@ namespace MatterControl.Tests.MatterControl
|
|||
"G1 Z10 F1800",
|
||||
"M114",
|
||||
"M109 S[temperature]",
|
||||
null,
|
||||
null,
|
||||
};
|
||||
|
||||
AggContext.StaticData = new FileSystemStaticData(TestContext.CurrentContext.ResolveProjectPath(4, "StaticData"));
|
||||
|
|
@ -160,7 +160,7 @@ namespace MatterControl.Tests.MatterControl
|
|||
"M117 Ready ",
|
||||
"M119",
|
||||
"switch filament; WRITE_RAW",
|
||||
null,
|
||||
null,
|
||||
};
|
||||
|
||||
AggContext.StaticData = new FileSystemStaticData(TestContext.CurrentContext.ResolveProjectPath(4, "StaticData"));
|
||||
|
|
@ -192,7 +192,7 @@ namespace MatterControl.Tests.MatterControl
|
|||
{
|
||||
"G1 X0 Y0 Z0 E0 F1000",
|
||||
"G1 X10",
|
||||
null,
|
||||
null,
|
||||
};
|
||||
|
||||
AggContext.StaticData = new FileSystemStaticData(TestContext.CurrentContext.ResolveProjectPath(4, "StaticData"));
|
||||
|
|
@ -234,7 +234,7 @@ namespace MatterControl.Tests.MatterControl
|
|||
"G1 X8 Y0 Z-0.1",
|
||||
"G1 X9 Y0 Z-0.1",
|
||||
"G1 X10 Y0 Z-0.1",
|
||||
null,
|
||||
null,
|
||||
};
|
||||
|
||||
AggContext.StaticData = new FileSystemStaticData(TestContext.CurrentContext.ResolveProjectPath(4, "StaticData"));
|
||||
|
|
@ -320,7 +320,7 @@ namespace MatterControl.Tests.MatterControl
|
|||
"G1 E-1 F301",
|
||||
"G1 E-2",
|
||||
"G90",
|
||||
null,
|
||||
null,
|
||||
};
|
||||
|
||||
AggContext.StaticData = new FileSystemStaticData(TestContext.CurrentContext.ResolveProjectPath(4, "StaticData"));
|
||||
|
|
@ -822,7 +822,7 @@ namespace MatterControl.Tests.MatterControl
|
|||
}
|
||||
|
||||
string expectedLine = expected[expectedIndex++];
|
||||
if(expectedLine != actualLineWithoutChecksum)
|
||||
if (expectedLine != actualLineWithoutChecksum)
|
||||
{
|
||||
int a = 0;
|
||||
}
|
||||
|
|
@ -849,7 +849,7 @@ namespace MatterControl.Tests.MatterControl
|
|||
|
||||
// wait for the print to finish (or 3 minutes to pass)
|
||||
time = Stopwatch.StartNew();
|
||||
while(printer.Connection.Printing
|
||||
while (printer.Connection.Printing
|
||||
&& time.ElapsedMilliseconds < (1000 * 60 * 3))
|
||||
{
|
||||
Thread.Sleep(1000);
|
||||
|
|
@ -863,6 +863,14 @@ namespace MatterControl.Tests.MatterControl
|
|||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void KnownLayerLinesTest()
|
||||
{
|
||||
Assert.AreEqual(8, GCodeFile.GetLayerNumber("; layer 8, Z = 0.800"), "Simplify3D ~ 2019");
|
||||
Assert.AreEqual(1, GCodeFile.GetLayerNumber("; LAYER:1"), "Cura/MatterSlice");
|
||||
Assert.AreEqual(7, GCodeFile.GetLayerNumber(";LAYER:7"), "Slic3r Prusa Edition 1.38.7-prusa3d on 2018-04-25");
|
||||
}
|
||||
|
||||
[Test, Category("GCodeStream")]
|
||||
public void WriteReplaceStreamTests()
|
||||
{
|
||||
|
|
@ -903,7 +911,8 @@ namespace MatterControl.Tests.MatterControl
|
|||
|
||||
var inputLinesStream = new TestGCodeStream(printer, inputLines);
|
||||
var queueStream = new QueuedCommandsStream(printer, inputLinesStream);
|
||||
ProcessWriteRegexStream writeStream = new ProcessWriteRegexStream(printer, queueStream, queueStream);
|
||||
|
||||
var writeStream = new ProcessWriteRegexStream(printer, queueStream, queueStream);
|
||||
ValidateStreamResponse(expected, writeStream);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue