Ejemplo n.º 1
0
 private void Resume_Click(object sender, EventArgs e)
 {
     if (_connected)
     {
         ConnectionExpander.WriteCOMPort('~');
     }
 }
Ejemplo n.º 2
0
        private void _jogTimer_Tick(object sender, EventArgs e)
        {
            if (!_mouseIsJogging || GRBLMachinePlugin.CurrentMachineState == GRBLMachinePlugin.MachineState.Alarm)
            {
                _jogTimer.Stop();
                return;
            }

            /*if (!ConnectionExpander.IsCOMPortIdle) {
             * return; // Still moving
             * }*/

            const float px2mm        = 0.5f;
            const float maxMmPerMove = 10;
            const float nominalFeed  = 1000;

            float relX         = Math.Abs(_mouseJogDelta.X) * px2mm;
            float relY         = Math.Abs(_mouseJogDelta.Y) * px2mm;
            float largestDelta = Math.Max(relX, relY);
            float speedPercent = 1.0f;

            if (largestDelta > maxMmPerMove)
            {
                // Make sure we never move more than 5mm per jog command
                relX        *= maxMmPerMove / largestDelta;
                relY        *= maxMmPerMove / largestDelta;
                speedPercent = largestDelta / maxMmPerMove;
            }
            float moveX = relX * Math.Sign(_mouseJogDelta.X);
            float moveY = relY * -Math.Sign(_mouseJogDelta.Y);
            float feed  = speedPercent * nominalFeed;

            ConnectionExpander.WriteCOMPort((char)0x85); // Jog cancel for previous jog
            ConnectionExpander.WriteCOMPortFmt("$J=G91 G21 X{0:+#;-#;+0} Y{1:+#;-#;+0} F{2}", moveX, moveY, feed);
        }
Ejemplo n.º 3
0
 private void ResetZMenu_Click(object sender, EventArgs e)
 {
     if (_connected)
     {
         ConnectionExpander.WriteCOMPort("G10 P0 L20 Z0");
     }
 }
Ejemplo n.º 4
0
        private void PauseButton_Click(object sender, EventArgs e)
        {
            if (PauseButton.Checked)
            {
                _pauseEvent.Reset();

                ConnectionExpander.WriteCOMPort('!');

                LinesTotal.Text = _fileData.Count.ToString();

                Message("Pausing... ");

                if (JobPaused != null)
                {
                    JobPaused();
                }

                EnableButtons();
            }
            else
            {
                Message("Resuming... ");

                ConnectionExpander.WriteCOMPort('~');

                _pauseEvent.Set();

                if (JobResumed != null)
                {
                    JobResumed();
                }

                EnableButtons();
            }
        }
Ejemplo n.º 5
0
 private void Goto_Click(object sender, EventArgs e)
 {
     if (!string.IsNullOrEmpty(GotoText.Text))
     {
         ConnectionExpander.WriteCOMPortFmt("$J=G53 {0}", GotoText.Text);
     }
 }
Ejemplo n.º 6
0
 private void MouseJog_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
 {
     Console.WriteLine($"Jogger Mouse Up {e.Location}");
     _mouseJogDelta  = Point.Empty;
     _mouseIsJogging = false;
     _jogTimer.Stop();
     _jogTimer.Tick -= _jogTimer_Tick;
     ConnectionExpander.WriteCOMPort((char)0x85); // Jog cancel
 }
Ejemplo n.º 7
0
        private void Command_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                ConnectionExpander.WriteCOMPort(Command.Text);

                e.Handled = true;
            }
        }
Ejemplo n.º 8
0
 private void ZProbeButton_Click(object sender, EventArgs e)
 {
     OriginButton.Enabled = false;                                                                                   // Will run your router drill into the workpiece ...
     ThreadedGCodeExecute(
         () => ConnectionExpander.WriteCOMPort("G43.1 Z0"),                                                          // Remove any existing tool offset
         () => ConnectionExpander.WriteCOMPort("G10 L2 P0 Z0"),                                                      // Reset WCS to absolute machine 0 (Z-Probe target Z is based on WCS origin)
         () => ConnectionExpander.WriteCOMPortFmt("G38.2 F200 Z{0}", GRBLMachinePlugin.Props.ZProbeToolDropTargetZ), // Perform Z-Probe
         () => ConnectionExpander.WriteCOMPort("G10 L20 P0 Z0"),                                                     // Set WCS Z to probe Z
         () => ConnectionExpander.WriteCOMPortFmt("G43.1 Z{0}", GRBLMachinePlugin.Props.ZProbeToolOffset)            // Set tool offset again
         );
 }
Ejemplo n.º 9
0
        private void FeedUnitInches_Click(object sender, EventArgs e)
        {
            if (!_connected)
            {
                return;
            }

            ConnectionExpander.WriteCOMPort("$13=1");
            GRBLMachinePlugin.PropertyChange("ReportInInches", GRBLMachinePlugin.Props.ReportInInches = InchMM.Inches);
            CamBamUI.MainUI.ObjectProperties.Refresh();
        }
Ejemplo n.º 10
0
        private void GotoMouse_Click(object sender, EventArgs e)
        {
            MoveToLocationMode editMode = new MoveToLocationMode(CamBamUI.MainUI.ActiveView);

            editMode.DefaultValue = (object)null;
            editMode.Prompt       = "Select Move Destination";
            editMode.OnReturnOK  += (o, ea) => {
                Point3F moveDelta = editMode.MoveDestination - editMode.MoveSource;
                ThisApplication.AddLogMessage("MoveDelta = " + moveDelta);
                ConnectionExpander.WriteCOMPortFmt("$J=G91 G21 X{0:+#;-#;+0} Y{1:+#;-#;+0} F4000", moveDelta.X, moveDelta.Y);
            };
            CamBamUI.MainUI.ActiveView.SetEditMode((EditMode)editMode);
            CamBamUI.MainUI.ActiveView.RepaintEditMode();
        }
Ejemplo n.º 11
0
        private void JogToToolChangePosition()
        {
            GRBLProps props = GRBLMachinePlugin.Props;

            WaitIdle();

            _preChangeX     = _lastX.GetWorkOrMachinePosition(_lastType, _WCO_X, PosType.WorkCoordinates, props.ReportInInches, props.ReportInInches);
            _preChangeY     = _lastY.GetWorkOrMachinePosition(_lastType, _WCO_Y, PosType.WorkCoordinates, props.ReportInInches, props.ReportInInches);
            _preChangeZ     = _lastZ.GetWorkOrMachinePosition(_lastType, _WCO_Z, PosType.WorkCoordinates, props.ReportInInches, props.ReportInInches);
            _preChangeSpeed = _lastSpeed;
            _preChangeType  = _lastType;

            ConnectionExpander.WriteCOMPort(_jogLeadIn + "G53 " + (props.ToolChangeUnits == InchMM.Inches ? "G20" : "G21") + " F4000 G90 Z" + props.ToolChangeZ.ToString(EN_US));
            WaitIdle();
            ConnectionExpander.WriteCOMPort("S0");
            ConnectionExpander.WriteCOMPort(_jogLeadIn + "G53 " + (props.ToolChangeUnits == InchMM.Inches ? "G20" : "G21") + " F4000 G90 X" + props.ToolChangeX.ToString(EN_US) + " Y" + props.ToolChangeY.ToString(EN_US));
        }
Ejemplo n.º 12
0
        private void Alarm_Click(object sender, EventArgs e)
        {
            if (!_connected)
            {
                return;
            }

            ConnectionExpander.WriteCOMPort((char)0x18);
            Thread.Sleep(250);
            ConnectionExpander.WriteCOMPort("$X");

            /**if (MessageBox.Show("GRBL has been reset,\r\nperforming a Homing Cycle and/or\r\nreset your WCS origin is highly recommended !\r\n\r\nMove to WCS origin (0.0.0) now ?","GRBLMachine", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
             * {
             * ConnectionExpander.WriteCOMPort("G91 G21 G0 Z" + GRBLMachinePlugin.Props.JogZPullup.ToString(new CultureInfo("en-US")));
             * ConnectionExpander.WriteCOMPort("G90 G0 X0 Y0");
             * ConnectionExpander.WriteCOMPort("G90 G0 Z0");
             * }*/
        }
Ejemplo n.º 13
0
        private void JogFromToolChangePosition()
        {
            GRBLProps props = GRBLMachinePlugin.Props;

            if (_lastZ != props.ToolChangeZ)
            {
                WaitIdle();
                ConnectionExpander.WriteCOMPort(_jogLeadIn + "G53 " + (props.ToolChangeUnits == InchMM.Inches ? "G20" : "G21") + " F4000 G90 Z" + props.ToolChangeZ.ToString(EN_US));
            }

            WaitIdle();
            ConnectionExpander.WriteCOMPort(_jogLeadIn + (GRBLMachinePlugin.Props.ReportInInches == InchMM.Inches ? "G20" : "G21") + " F4000 G90 X" + _preChangeX.ToString(EN_US) + " Y" + _preChangeY.ToString(EN_US));
            WaitIdle();
            ConnectionExpander.WriteCOMPort("S" + _preChangeSpeed);
            WaitIdle();
            ConnectionExpander.WriteCOMPort(_jogLeadIn + (props.ReportInInches == InchMM.Inches ? "G20" : "G21") + " F" + 4000d.GetUnitsFromReportAndDrawing(InchMM.Millimeters, props.ReportInInches).ToString("0.0000", EN_US) + " G90 Z" + (_preChangeZ + props.ToolChangePlungeDistance.GetUnitsFromReportAndDrawing(props.ToolChangeUnits, props.ReportInInches)).ToString("0.0000", EN_US));
            ConnectionExpander.WriteCOMPort(_jogLeadIn + (props.ReportInInches == InchMM.Inches ? "G20" : "G21") + " F" + props.ToolChangePlungeFeed.GetUnitsFromReportAndDrawing(props.ToolChangeUnits, props.ReportInInches).ToString("0.0000", EN_US) + " G90 Z" + (_preChangeZ.ToString("0.0000", EN_US)));

            WaitIdle();
        }
Ejemplo n.º 14
0
        private void storeCurrentPositionToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ToolStripItem item = (sender as ToolStripItem);

            if (item != null)
            {
                ContextMenuStrip owner = item.Owner as ContextMenuStrip;
                if (owner != null)
                {
                    if (owner.SourceControl == PosA)
                    {
                        ConnectionExpander.WriteCOMPort("G28.1");
                    }
                    if (owner.SourceControl == PosB)
                    {
                        ConnectionExpander.WriteCOMPort("G30.1");
                    }
                }
            }
        }
Ejemplo n.º 15
0
        public ConnectionExpander()
        {
            _this = this;

            InitializeComponent();

            _serialPort = ThePort;

            COMPort.Items.Clear();
            COMPort.Items.AddRange(SerialPort.GetPortNames());
            COMPort.SelectedItem = GRBLMachinePlugin.Props.COMPort;

            Baudrate.SelectedItem = GRBLMachinePlugin.Props.Baudrate.ToString();

            AutoConnect.Checked = GRBLMachinePlugin.Props.AutoConnect;

            WqlEventQuery          insertQuery   = new WqlEventQuery("SELECT * FROM __InstanceCreationEvent WITHIN 2 WHERE TargetInstance ISA 'Win32_PnPEntity'");
            ManagementEventWatcher insertWatcher = new ManagementEventWatcher(insertQuery);

            insertWatcher.EventArrived += new EventArrivedEventHandler(DeviceInsertedEvent);
            insertWatcher.Start();

            WqlEventQuery removeQuery = new WqlEventQuery("SELECT * FROM __InstanceDeletionEvent WITHIN 2 WHERE TargetInstance ISA 'Win32_PnPEntity'");

            ManagementEventWatcher removeWatcher = new ManagementEventWatcher(removeQuery);

            removeWatcher.EventArrived += new EventArrivedEventHandler(DeviceRemovedEvent);
            removeWatcher.Start();

            Connected    += ConnectionExpander_Connected;
            Disconnected += ConnectionExpander_Disconnected;

            GRBLMachinePlugin.PropertyChanged += Props_PropertyChanged;

            AutoConnect.CheckedChanged += AutoConnect_CheckedChanged;
        }
Ejemplo n.º 16
0
 private void HomeButton_Click(object sender, EventArgs e)
 {
     ConnectionExpander.WriteCOMPort("$H");
 }
Ejemplo n.º 17
0
 private void OriginXYButton_Click(object sender, EventArgs e)
 {
     ConnectionExpander.WriteCOMPort("G91 G21 G0 Z" + GRBLMachinePlugin.Props.JogZPullup.ToString(EN_US));
     ConnectionExpander.WriteCOMPort("G90 G0 X0 Y0");
 }
Ejemplo n.º 18
0
 private void WCSButton_Click(object sender, EventArgs e)
 {
     ConnectionExpander.WriteCOMPort("G10 P0 L20 X0 Y0 Z0");
 }
Ejemplo n.º 19
0
 private void PosB_Click(object sender, EventArgs e)
 {
     ConnectionExpander.WriteCOMPort("G30");
 }
Ejemplo n.º 20
0
        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();
                    }
                });
            }
        }
Ejemplo n.º 21
0
 private void Z_Plus_Click(object sender, EventArgs e)
 {
     ConnectionExpander.WriteCOMPort(_jogLeadIn + (Inches.Checked ? "G20" : "G21") + " G91 Z+" + StepZ.Text);
 }