Made the emulator parse commands better (temps)
Made LaunchAndConnectToPrinterEmulator Working on pause on layer test Updated version to 1.6
This commit is contained in:
parent
5e46a182cf
commit
cb3d518d35
4 changed files with 116 additions and 9 deletions
|
|
@ -300,7 +300,7 @@ public static bool CameraPreviewActive = false;
|
|||
{
|
||||
UseOpenGL = true;
|
||||
}
|
||||
string version = "1.5";
|
||||
string version = "1.6";
|
||||
|
||||
Title = "MatterHackers: MatterControl {0}".FormatWith(version);
|
||||
if (OemSettings.Instance.WindowTitleExtra != null && OemSettings.Instance.WindowTitleExtra.Trim().Length > 0)
|
||||
|
|
|
|||
|
|
@ -35,11 +35,15 @@ import time
|
|||
import random
|
||||
|
||||
extruderGoalTemperature = 210
|
||||
bedGoalTemperature = 0
|
||||
|
||||
"""Add response callbacks here"""
|
||||
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" % (extruderGoalTemperature + random.randrange(-2,2))
|
||||
if bedGoalTemperature == 0:
|
||||
return "ok T:%s\n" % (extruderGoalTemperature + random.randrange(-2,2))
|
||||
else:
|
||||
return "ok T:%s B:%s\n" % (extruderGoalTemperature + random.randrange(-2,2), bedGoalTemperature + random.randrange(-2,2))
|
||||
|
||||
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
|
||||
|
|
@ -59,13 +63,22 @@ def parseChecksumLine(command):
|
|||
else:
|
||||
return command
|
||||
|
||||
def getCommandKey(command):
|
||||
if command.find(' ') != -1:
|
||||
return command[:command.find(' ')]
|
||||
else:
|
||||
return command
|
||||
|
||||
def getCorrectResponse(command):
|
||||
try:
|
||||
#Remove line returns
|
||||
command = ''.join(command.splitlines()) # strip of the trailing cr (\n)
|
||||
command = parseChecksumLine(command)
|
||||
if command in responses:
|
||||
return responses[command](command)
|
||||
commandKey = getCommandKey(command)
|
||||
if commandKey in responses:
|
||||
return responses[commandKey](command)
|
||||
else:
|
||||
print "Command '%s' not found" % command
|
||||
except Exception, e:
|
||||
print e
|
||||
|
||||
|
|
@ -73,16 +86,28 @@ def getCorrectResponse(command):
|
|||
|
||||
def setExtruderTemperature(command):
|
||||
try:
|
||||
#M104 S210
|
||||
#M104 S210 or M109 S[temp]
|
||||
sIndex = command.find('S') + 1
|
||||
global extruderGoalTemperature
|
||||
extruderGoalTemperature = int(command[sIndex:])
|
||||
except Exception, e:
|
||||
print e
|
||||
|
||||
return 'ok\n'
|
||||
|
||||
def setBedTemperature(command):
|
||||
try:
|
||||
#M140 S210 or M190 S[temp]
|
||||
sIndex = command.find('S') + 1
|
||||
global bedGoalTemperature
|
||||
bedGoalTemperature = int(command[sIndex:])
|
||||
except Exception, e:
|
||||
print e
|
||||
|
||||
return 'ok\n'
|
||||
|
||||
"""Dictionary of command and response callback"""
|
||||
responses = { "M105" : randomTemp, "A" : echo, "M114" : getPosition , "N" : parseChecksumLine, "M115" : reportMarlinFirmware, "M104" : setExtruderTemperature }
|
||||
responses = { "M105" : randomTemp, "A" : echo, "M114" : getPosition , "N" : parseChecksumLine, "M115" : reportMarlinFirmware, "M104" : setExtruderTemperature, "M109" : setExtruderTemperature, "M140" : setBedTemperature,"M190" : setBedTemperature }
|
||||
|
||||
def main(argv):
|
||||
parser = argparse.ArgumentParser(description='Set up a printer emulation.')
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
using MatterHackers.Agg.UI.Tests;
|
||||
using MatterHackers.Agg.PlatformAbstract;
|
||||
using MatterHackers.Agg.UI.Tests;
|
||||
using MatterHackers.GuiAutomation;
|
||||
using MatterHackers.MatterControl.SlicerConfiguration;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace MatterHackers.MatterControl.Tests.Automation
|
||||
|
|
@ -57,6 +59,32 @@ namespace MatterHackers.MatterControl.Tests.Automation
|
|||
Assert.IsTrue(testHarness.TestCount == 1); // make sure we ran all our tests
|
||||
}
|
||||
|
||||
[Test, RequiresSTA, RunInApplicationDomain]
|
||||
public void PauseOnLayerDoesPauseOnPrint()
|
||||
{
|
||||
Action<AutomationTesterHarness> testToRun = (AutomationTesterHarness resultsHarness) =>
|
||||
{
|
||||
AutomationRunner testRunner = new AutomationRunner();
|
||||
{
|
||||
MatterControlUtilities.PrepForTestRun(testRunner, MatterControlUtilities.PrepAction.CloseSignInAndPrinterSelect);
|
||||
|
||||
var emualtorProccess = MatterControlUtilities.LaunchAndConnectToPrinterEmulator(testRunner);
|
||||
|
||||
resultsHarness.AddTestResult(ProfileManager.Instance.ActiveProfile != null);
|
||||
|
||||
testRunner.Wait(200);
|
||||
|
||||
emualtorProccess.Kill();
|
||||
MatterControlUtilities.CloseMatterControl(testRunner);
|
||||
}
|
||||
};
|
||||
|
||||
string staticDataPathOverride = Path.Combine("..", "..", "..", "..", "..", "MatterControl", "StaticData");
|
||||
StaticData.Instance = new MatterHackers.Agg.FileSystemStaticData(staticDataPathOverride);
|
||||
AutomationTesterHarness testHarness = MatterControlUtilities.RunTest(testToRun, staticDataPathOverride: staticDataPathOverride, maxTimeToRun: 200);
|
||||
Assert.IsTrue(testHarness.AllTestsPassed);
|
||||
}
|
||||
|
||||
[Test, RequiresSTA, RunInApplicationDomain]
|
||||
public void ClearingCheckBoxClearsUserOverride()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ using MatterHackers.MatterControl.PrintLibrary.Provider;
|
|||
using Newtonsoft.Json;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
|
@ -134,18 +135,71 @@ namespace MatterHackers.MatterControl.Tests.Automation
|
|||
}
|
||||
}
|
||||
|
||||
public static Process StartPrinterEmulator(string emulatorCom)
|
||||
public static Process LaunchAndConnectToPrinterEmulator(AutomationRunner testRunner)
|
||||
{
|
||||
// check for the settings file
|
||||
string testConfigDataPath = Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "MCTestConfig");
|
||||
var emulatorPath = Path.Combine(testConfigDataPath, "PrinterEmulatorConfig.json");
|
||||
|
||||
// if no file create it
|
||||
if(!File.Exists(emulatorPath))
|
||||
{
|
||||
Directory.CreateDirectory(testConfigDataPath);
|
||||
|
||||
Dictionary<string, string> userSettings = new Dictionary<string, string>()
|
||||
{
|
||||
["MCPort"] = "",
|
||||
["Printer"] = "",
|
||||
};
|
||||
|
||||
File.WriteAllText(emulatorPath, JsonConvert.SerializeObject(userSettings, Formatting.Indented));
|
||||
}
|
||||
|
||||
|
||||
// open the settings file
|
||||
var jsonDict = JsonConvert.DeserializeObject<Dictionary<string, string>>(File.ReadAllText(emulatorPath));
|
||||
|
||||
// if no com port set, issue instructions on how to set it
|
||||
if(!jsonDict.ContainsKey("MCPort")
|
||||
|| !jsonDict.ContainsKey("Printer")
|
||||
|| string.IsNullOrEmpty(jsonDict["MCPort"])
|
||||
|| string.IsNullOrEmpty(jsonDict["Printer"]))
|
||||
{
|
||||
throw new Exception("You must set the port and printer in: " + emulatorPath);
|
||||
}
|
||||
|
||||
// create the printer
|
||||
//Create printer for sync to see
|
||||
MatterControlUtilities.AddAndSelectPrinter(testRunner, "Airwolf 3D", "HD");
|
||||
|
||||
string comPort = jsonDict["MCPort"];
|
||||
string printerPort = jsonDict["Printer"];
|
||||
|
||||
var process = new Process();
|
||||
process.StartInfo = new ProcessStartInfo()
|
||||
{
|
||||
FileName = "python",
|
||||
Arguments = string.Format("{0} {1}", StaticData.Instance.MapPath("../PrinterEmulator.py"), emulatorCom),
|
||||
Arguments = string.Format("{0} {1}", StaticData.Instance.MapPath("../PrinterEmulator.py"), printerPort),
|
||||
WindowStyle = ProcessWindowStyle.Minimized
|
||||
};
|
||||
|
||||
process.Start();
|
||||
|
||||
// edit the com port
|
||||
testRunner.ClickByName("Edit Printer Button");
|
||||
testRunner.Wait(2);
|
||||
|
||||
testRunner.ClickByName("Com Port Dropdown");
|
||||
|
||||
testRunner.ClickByName(comPort + " Menu Item", 1);
|
||||
|
||||
testRunner.ClickByName("Cancel Wizard Button");
|
||||
|
||||
// connect to the created printer
|
||||
testRunner.ClickByName("Connect to printer button", 2);
|
||||
|
||||
testRunner.Wait(2);
|
||||
|
||||
return process;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue