From b5f8c9fc37468fc7dc48155f3ee6534afdf4ec8e Mon Sep 17 00:00:00 2001 From: Lars Brubaker Date: Mon, 19 Jan 2015 17:33:17 -0800 Subject: [PATCH] Made ComTester understand commands while printing. Made it possible to creat HUGE test gcode files. Made a massage when trying to load huge gcode. --- ComTester.py | 21 ++++++++--- MatterControlApplication.cs | 54 ++++++++++++++--------------- PartPreviewWindow/ViewGcodeBasic.cs | 26 +++++++++++++- PrintQueue/QueueData.cs | 2 +- StaticData/Translations/Master.txt | 3 ++ 5 files changed, 72 insertions(+), 34 deletions(-) diff --git a/ComTester.py b/ComTester.py index e8a75417b..8c758ad0a 100644 --- a/ComTester.py +++ b/ComTester.py @@ -39,14 +39,25 @@ def randomTemp(command): # temp commands look like this: ok T:19.4 /0.0 B:0.0 /0.0 @:0 B@:0 return "ok T:%s\n" % random.randrange(202,215) -def echo(command): +def getPosition(command): + # temp commands look like this: X:0.00 Y:0.00 Z0.00 E:0.00 Count X: 0.00 Y:0.00 Z:0.00 then an ok on the next line + return "X:0.00 Y:0.00 Z0.00 E:0.00 Count X: 0.00 Y:0.00 Z:0.00\nok\n" + +def echo(command): return command + +def parseChecksumLine(command): + if command[0] == 'N': + spaceIndex = command.find(' ') + 1 + endIndex = command.find('*') + return command[spaceIndex:endIndex] def getCorrectResponse(command): try: #Remove line returns - command = ''.join(command.splitlines()) - if command in responses: + command = ''.join(command.splitlines()) # strip of the trailing cr (\n) + command = parseChecksumLine(command) + if command in responses: return responses[command](command) except Exception, e: print e @@ -54,7 +65,7 @@ def getCorrectResponse(command): return 'ok\n' """Dictionary of command and response callback""" -responses = { "M105" : randomTemp, "A": echo} +responses = { "M105" : randomTemp, "A" : echo, "M114" : getPosition , "N" : parseChecksumLine} def main(argv): parser = argparse.ArgumentParser(description='Set up a printer emulation.') @@ -66,7 +77,7 @@ def main(argv): if len(line) > 0: print(line) response = getCorrectResponse(line) - sleep(0.02) + # sleep(0.02) print response ser.write(response) ser.close() diff --git a/MatterControlApplication.cs b/MatterControlApplication.cs index 1e52ef973..7185ed053 100644 --- a/MatterControlApplication.cs +++ b/MatterControlApplication.cs @@ -284,41 +284,41 @@ namespace MatterHackers.MatterControl ShowAsSystemWindow(); } - private static void WriteMove(StringBuilder gcodeStringBuilder, Vector2 center) + private static void WriteMove(StreamWriter file, Vector2 center) { - gcodeStringBuilder.AppendLine("G1 X" + center.x.ToString() + " Y" + center.y.ToString()); + file.WriteLine("G1 X" + center.x.ToString() + " Y" + center.y.ToString()); } public static void WriteTestGCodeFile() { - StringBuilder gcodeStringBuilder = new StringBuilder(); + using (StreamWriter file = new StreamWriter("PerformanceTest.gcode")) + { + //int loops = 150000; + int loops = 150; + int steps = 200; + double radius = 50; + Vector2 center = new Vector2(150, 100); - int loops = 15; - int steps = 200; - double radius = 50; - Vector2 center = new Vector2(150, 100); + file.WriteLine("G28 ; home all axes"); + file.WriteLine("G90 ; use absolute coordinates"); + file.WriteLine("G21 ; set units to millimeters"); + file.WriteLine("G92 E0"); + file.WriteLine("G1 F7800"); + file.WriteLine("G1 Z" + (5).ToString()); + WriteMove(file, center); - gcodeStringBuilder.AppendLine("G28 ; home all axes"); - gcodeStringBuilder.AppendLine("G90 ; use absolute coordinates"); - gcodeStringBuilder.AppendLine("G21 ; set units to millimeters"); - gcodeStringBuilder.AppendLine("G92 E0"); - gcodeStringBuilder.AppendLine("G1 F7800"); - gcodeStringBuilder.AppendLine("G1 Z" + (5).ToString()); - WriteMove(gcodeStringBuilder, center); + for (int loop = 0; loop < loops; loop++) + { + for (int step = 0; step < steps; step++) + { + Vector2 nextPosition = new Vector2(radius, 0); + nextPosition.Rotate(MathHelper.Tau / steps * step); + WriteMove(file, center + nextPosition); + } + } - for (int loop = 0; loop < loops; loop++) - { - for (int step = 0; step < steps; step++) - { - Vector2 nextPosition = new Vector2(radius, 0); - nextPosition.Rotate(MathHelper.Tau / steps * step); - WriteMove(gcodeStringBuilder, center + nextPosition); - } - } - - gcodeStringBuilder.AppendLine("M84 ; disable motors"); - - System.IO.File.WriteAllText("PerformanceTest.gcode", gcodeStringBuilder.ToString()); + file.WriteLine("M84 ; disable motors"); + } } void CheckOnPrinter(object state) diff --git a/PartPreviewWindow/ViewGcodeBasic.cs b/PartPreviewWindow/ViewGcodeBasic.cs index b1e83057d..d9a138405 100644 --- a/PartPreviewWindow/ViewGcodeBasic.cs +++ b/PartPreviewWindow/ViewGcodeBasic.cs @@ -78,6 +78,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow static string slicingErrorMessage = "Slicing Error.\nPlease review your slice settings.".Localize(); static string pressGenerateMessage = "Press 'generate' to view layers".Localize(); static string fileNotFoundMessage = "File not found on disk.".Localize(); + static string fileTooBigToLoad = "File too big to load.".Localize(); Vector2 bedCenter; Vector3 viewerVolume; @@ -837,9 +838,32 @@ namespace MatterHackers.MatterControl.PartPreviewWindow } } - void DoneLoadingGCode(object sender, EventArgs e) + static bool RunningIn32Bit() + { + if (IntPtr.Size == 4) + { + return true; + } + + return false; + } + + void DoneLoadingGCode(object sender, EventArgs e) { SetProcessingMessage(""); + if (gcodeViewWidget != null + && gcodeViewWidget.LoadedGCode == null) + { + if (GCodeFile.FileTooBigToLoad(printItem.FileLocation)) + { + SetProcessingMessage(string.Format("{0}\n'{1}'", fileTooBigToLoad, Path.GetFileName(printItem.FileLocation))); + } + else + { + SetProcessingMessage(string.Format("{0}\n'{1}'", fileNotFoundMessage, Path.GetFileName(printItem.FileLocation))); + } + } + if (gcodeViewWidget != null && gcodeViewWidget.LoadedGCode != null && gcodeViewWidget.LoadedGCode.Count > 0) diff --git a/PrintQueue/QueueData.cs b/PrintQueue/QueueData.cs index 47516e9d3..fd5174797 100644 --- a/PrintQueue/QueueData.cs +++ b/PrintQueue/QueueData.cs @@ -284,7 +284,7 @@ namespace MatterHackers.MatterControl.PrintQueue return listToReturn; } - bool Is32Bit() + static bool Is32Bit() { if (IntPtr.Size == 4) { diff --git a/StaticData/Translations/Master.txt b/StaticData/Translations/Master.txt index 596dc796c..58f5e1d26 100644 --- a/StaticData/Translations/Master.txt +++ b/StaticData/Translations/Master.txt @@ -3083,3 +3083,6 @@ Translated:Token received... English:Please wait. Sending files... Translated:Please wait. Sending files... +English:File too big to load. +Translated:File too big to load. +