public MainWindow(HostHandler handler) { try { InitializeComponent(); handler.execute(Command.GetFirmwareVersion, new float[0]); var testPage = new TesterPage(this, handler); var userPage = new UserPage(this, handler); testPage.SetUserPage(userPage); userPage.setTesterPage(testPage); MainView.Child = userPage; } catch (Exception e) { System.Console.WriteLine(e.StackTrace); } }
public void ParseGcode(Stream file, HostHandler handler) { try { //List<List<string>> listOfG = new List<List<string>>(); var g1 = "G1"; var g92 = "G92"; var lineCounter = -1; using (var sr = new StreamReader(file)) { Console.WriteLine("Start Parsing"); while (!sr.EndOfStream) { //List<string> GLine = new List<string>(); lineCounter++; var line = sr.ReadLine(); if (String.IsNullOrEmpty(line)) { continue; } if (line.IndexOf(g1, StringComparison.CurrentCultureIgnoreCase) >= 0) { var eachLine = line.Split(' '); var xString = Array.FindAll(eachLine, x => x.StartsWith("X")); var yString = Array.FindAll(eachLine, x => x.StartsWith("Y")); var eString = Array.FindAll(eachLine, x => x.StartsWith("E")); var zString = Array.FindAll(eachLine, x => x.StartsWith("Z")); if ((xString != null && xString.Length != 0) && (yString != null && yString.Length != 0)) { var xFloat = float.Parse(xString.First().Substring(1)); var yFloat = float.Parse(yString.First().Substring(1)); handler.execute(Command.MoveGalvonometer, new float[] { xFloat * 0.025f, yFloat * 0.025f }); } if (zString != null && zString.Length != 0) { handler.execute(Command.StepStepper, new float[] { 1f }); } if (eString != null && eString.Length != 0) { var eFloat = float.Parse(eString.First().Substring(1)); if (eFloat == 0f) { handler.execute(Command.SetLaser, new float[] { 0f }); } else { handler.execute(Command.SetLaser, new float[] { 1f }); } } } else if (line.IndexOf(g92, StringComparison.CurrentCultureIgnoreCase) >= 0) { handler.execute(Command.SetLaser, new float[] { 0f }); } } Console.WriteLine("End Parsing"); } } catch (Exception e) { System.Console.WriteLine(e.StackTrace); } }
private void Reset_Stepper(object sender, RoutedEventArgs e) { handler.execute(Command.ResetStepper, new float[0]); }