private void GRBLMachinePlugin_State(GRBLMachinePlugin.MachineState state, int code) { if (_lastState != GRBLMachinePlugin.MachineState.Hold && state == GRBLMachinePlugin.MachineState.Hold) { System.Media.SystemSounds.Asterisk.Play(); } _lastState = state; _lastCode = code; StatusLabel.Text = state.ToString().ToUpper(); Hold.Enabled = state != GRBLMachinePlugin.MachineState.Hold; Resume.Enabled = state == GRBLMachinePlugin.MachineState.Hold; Alarm.Enabled = state == GRBLMachinePlugin.MachineState.Alarm; X_OriginZero.Enabled = Y_OriginZero.Enabled = Z_OriginZero.Enabled = state == GRBLMachinePlugin.MachineState.Idle; if (state == GRBLMachinePlugin.MachineState.Idle || state == GRBLMachinePlugin.MachineState.Jog) { X_AxisContextMenu.Enabled = true; Z_AxisContextMenu.Enabled = true; Y_AxisContextMenu.Enabled = true; FeedUnitsContextMenu.Enabled = true; } else { X_AxisContextMenu.Enabled = false; Z_AxisContextMenu.Enabled = false; Y_AxisContextMenu.Enabled = false; FeedUnitsContextMenu.Enabled = false; } }
private void GRBLMachinePlugin_State(GRBLMachinePlugin.MachineState state, int code) { if (state == GRBLMachinePlugin.MachineState.Idle || state == GRBLMachinePlugin.MachineState.Jog) { if (!ContentPanel.Enabled) { ContentPanel.Enabled = true; if (_toolChangeBusy) { HomeButton.Enabled = false; OriginButton.Enabled = false; ResetXButton.Enabled = false; ResetYButton.Enabled = false; WCSButton.Enabled = false; } } } else { if (ContentPanel.Enabled) { ContentPanel.Enabled = false; } } if (_jogLeadIn == null) { _jogLeadIn = ConnectionExpander.GrblIsV1 ? V1JOG : string.Empty; } }
private void GRBLMachinePlugin_State(GRBLMachinePlugin.MachineState state, int code) { _lastState = state; if (_jogLeadIn == null) { _jogLeadIn = ConnectionExpander.GrblIsV1 ? V1JOG : string.Empty; } }
private void WaitHold() { _lastState = GRBLMachinePlugin.MachineState.Jog; while (_lastState != GRBLMachinePlugin.MachineState.Hold) { Thread.Sleep(100); } }
private void WaitIdle() { while (!ConnectionExpander.IsCOMPortIdle) { Thread.Sleep(100); } _lastState = GRBLMachinePlugin.MachineState.Jog; while (_lastState != GRBLMachinePlugin.MachineState.Idle) { Thread.Sleep(100); } }
private void WriteThread() { FileStream fs = null; StreamReader sr = null; try { if (JobStarted != null) { InvokeOnUI(() => { JobStarted(); }); } string s; int i; fs = new FileStream(_sendingFileName, FileMode.Open, FileAccess.Read, FileShare.Read); sr = new StreamReader(fs); Message("Parsing: "); while ((s = sr.ReadLine()) != null) { _pauseEvent.WaitOne(); GRBLMachinePlugin.Log("---" + s, true); bool removeComments = true; foreach (string nrc in _noRemoveCommentGCODEs) { if (s.ToUpper().StartsWith(nrc)) { removeComments = false; break; } } if (removeComments) { StringBuilder line = new StringBuilder(); string[] comments = s.Split('(', ')', ';', '%'); for (i = 1; i < comments.Length; i++) { line.Append(comments[i]); } if (line.Length != 0) { GRBLMachinePlugin.Log("// " + line.ToString()); } if (comments.Length != 0) { line = new StringBuilder(); string[] packed = comments[0].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); foreach (string p in packed) { if (_unsupportedGCODEs.Contains(p)) { GRBLMachinePlugin.Log("!! Unsuppported GCODE '" + p + "' skipped"); } else { line.Append(p); } } if (line.Length != 0) { _fileData.AddLast(line.ToString()); } } } else { _fileData.AddLast(s); } } sr.Close(); sr = null; fs.Close(); fs = null; InvokeOnUI(() => { LinesTotal.Text = _fileData.Count.ToString(); LinesSent.Text = "0"; }); Message("Sending: "); i = 0; _lastState = GRBLMachinePlugin.MachineState.Jog; WaitIdle(); foreach (string line in _fileData) { _pauseEvent.WaitOne(); _toolChangingEvent.WaitOne(); if (line.ToUpper().Contains("M6")) { switch (GRBLMachinePlugin.Props.ToolChangeProcess) { case IgnoreProcessPassOn.Ignore: break; case IgnoreProcessPassOn.Process: DoToolChange(line); break; case IgnoreProcessPassOn.PassOn: ConnectionExpander.WriteCOMPort(line); break; } } else { ConnectionExpander.WriteCOMPort(line); } InvokeOnUI(() => { GRBLMachinePlugin.Log("=== " + line, true); LinesSent.Text = (++i).ToString(); }); } } catch (ThreadAbortException) { GRBLMachinePlugin.Log("\naborted"); ConnectionExpander.WriteCOMPort((char)0x18); } catch (ThreadInterruptedException) { GRBLMachinePlugin.Log("\nstopped"); ConnectionExpander.WriteCOMPort((char)0x18); } catch (Exception ex) { InvokeOnUI(() => { MessageBox.Show(ex.ToString()); }); } finally { if (sr != null) { sr.Close(); } if (fs != null) { fs.Close(); } ConnectionExpander.WriteCOMPort("M5"); _writeThread = null; InvokeOnUI(() => { SystemSounds.Asterisk.Play(); Message("Done:"); EnableButtons(); FileName.Enabled = true; BrowseButton.Enabled = true; _pauseEvent.Set(); _toolChangerEvent.Set(); _toolChangingEvent.Set(); if (JobStopped != null) { JobStopped(); } if (!ToolChangeButton.Enabled) { ToolChangeEnd(); } }); } }