Пример #1
0
 public PosEventArgs(xyzPoint world, xyzPoint machine, grblState stat, mState msg, pState last, string sraw)
 {
     posWorld   = world;
     posMachine = machine;
     status     = stat;
     statMsg    = msg;
     lastCmd    = last;
     raw        = sraw;
 }
Пример #2
0
        /// <summary>
        /// parse single gcode line to set parser state
        /// </summary>
        public static void updateParserState(string line, ref pState myParserState)
        {
            char   cmd     = '\0';
            string num     = "";
            bool   comment = false;
            double value   = 0;

            if (!(line.StartsWith("$") || line.StartsWith("("))) //do not parse grbl commands
            {
                try
                { foreach (char c in line)
                  {
                      if (c == ';')
                      {
                          break;
                      }
                      if (c == '(')
                      {
                          comment = true;
                      }
                      if (!comment)
                      {
                          if (Char.IsLetter(c))
                          {
                              if (cmd != '\0')
                              {
                                  value = 0;
                                  if (num.Length > 0)
                                  {
                                      try { value = double.Parse(num, System.Globalization.NumberFormatInfo.InvariantInfo); }
                                      catch { }
                                  }
                                  try { setParserState(cmd, value, ref myParserState); }
                                  catch { }
                              }
                              cmd = c;
                              num = "";
                          }
                          else if (Char.IsNumber(c) || c == '.' || c == '-')
                          {
                              num += c;
                          }
                      }
                      if (c == ')')
                      {
                          comment = false;
                      }
                  }
                  if (cmd != '\0')
                  {
                      try { setParserState(cmd, double.Parse(num, System.Globalization.NumberFormatInfo.InvariantInfo), ref myParserState); }
                      catch { }
                  }
                }
                catch { }
            }
        }
Пример #3
0
        /********************************************************
        * handle last sent commands from serial form
        * FeedRate, SpindleSpeed, Spinde/Coolant on/off, G54-Coord
        * update other forms
        ********************************************************/
        private void processParserState(pState cmd)
        {
            if (logPosEvent)
            {
                Logger.Trace("processParserState FR:{0}  SS:{1}  spindle:{2}  coolant:{3}  Tool:{4}  Coord:{5}", cmd.FR.ToString(), cmd.SS.ToString(), cmd.spindle, cmd.coolant, cmd.tool.ToString(), cmd.coord_select.ToString());
            }
            if (cmd.changed)
            {
                actualFR = cmd.FR.ToString();
                if (_streaming_form != null)
                {
                    _streaming_form.show_value_FR(actualFR);
                }
                actualSS = cmd.SS.ToString();
                if (_streaming_form != null)
                {
                    _streaming_form.show_value_SS(actualSS);
                }

                if (grbl.isVersion_0)
                {
                    cBSpindle.CheckedChanged -= cBSpindle_CheckedChanged;
                    cBSpindle.Checked         = (cmd.spindle <= 4) ? true : false; // M3, M4 start, M5 stop
                    cBSpindle.CheckedChanged += cBSpindle_CheckedChanged;
                    cBCoolant.CheckedChanged -= cBCoolant_CheckedChanged;
                    cBCoolant.Checked         = (cmd.coolant <= 8) ? true : false; // M7, M8 on   M9 coolant off
                    cBCoolant.CheckedChanged += cBCoolant_CheckedChanged;
                }
                if (cmd.toolchange)
                {
                    lblTool.Text = cmd.tool.ToString();
                }

                lblCurrentG.Text      = "G" + cmd.coord_select.ToString();
                lblCurrentG.BackColor = (cmd.coord_select == 54) ? Color.Lime : Color.Fuchsia;
                if (_camera_form != null)
                {
                    _camera_form.setCoordG = cmd.coord_select;
                }
                if (_coordSystem_form != null)
                {
                    _coordSystem_form.markActiveCoordSystem(lblCurrentG.Text);
                    _coordSystem_form.updateTLO(cmd.TLOactive, cmd.tool_length);
                }
            }
        }
Пример #4
0
        /// <summary>
        /// set parser state
        /// </summary>
        private static void setParserState(char cmd, double value, ref pState myParserState)
        {
//            myParserState.changed = false;
            switch (Char.ToUpper(cmd))
            {
            case 'G':
                if (value <= 3)
                {
                    myParserState.motion = (byte)value;
                    break;
                }
                if ((value >= 17) && (value <= 19))
                {
                    myParserState.plane_select = (byte)value;
                }
                else if ((value == 20) || (value == 21))
                {
                    myParserState.units = (byte)value;
                }
                else if ((value >= 43) && (value < 44))
                {
                    myParserState.TLOactive = true; getTLO = true;
                }
                else if (value == 49)
                {
                    myParserState.TLOactive = false;
                }
                else if ((value >= 54) && (value <= 59))
                {
                    myParserState.coord_select = (byte)value;
                }
                else if ((value == 90) || (value == 91))
                {
                    myParserState.distance = (byte)value;
                }
                else if ((value == 93) || (value == 94))
                {
                    myParserState.feed_rate = (byte)value;
                }
                myParserState.changed = true;
//                    MessageBox.Show("set parser state "+cmd + "  " + value.ToString()+ "  "+ myParserState.TLOactive.ToString());
                break;

            case 'M':
                if ((value <= 2) || (value == 30))
                {
                    myParserState.program_flow = (byte)value;        // M0, M1 pause, M2, M30 stop
                }
                else if ((value >= 3) && (value <= 5))
                {
                    myParserState.spindle = (byte)value;        // M3, M4 start, M5 stop
                }
                else if ((value >= 7) && (value <= 9))
                {
                    myParserState.coolant = (byte)value;        // M7, M8 on   M9 coolant off
                }
                else if (value == 6)
                {
                    myParserState.toolchange = true;
                }
                myParserState.changed = true;
                break;

            case 'F':
                myParserState.FR      = value;
                myParserState.changed = true;
                break;

            case 'S':
                myParserState.SS      = value;
                myParserState.changed = true;
                break;

            case 'T':
                myParserState.tool    = (byte)value;
                myParserState.changed = true;
                break;

            case 'Z':
                if (getTLO)
                {
                    myParserState.tool_length = value;
                }
                break;
            }
        }
Пример #5
0
        /************************************************************
        * handle status report and position event from serial form
        * processStatus()
        ************************************************************/
        private void OnRaisePosEvent(object sender, PosEventArgs e)
        {
            //  if (logPosEvent)  Logger.Trace("OnRaisePosEvent  {0}  connect {1}  status {2}", e.Status.ToString(), _serial_form.serialPortOpen, e.Status.ToString());
            machineStatus        = e.Status;
            machineStatusMessage = e.StatMsg;
            machineParserState   = e.parserState;

/***** Restore saved position after reset and set initial feed rate: *****/
            if (flagResetOffset || (e.Status == grblState.reset))
            {
                processReset();
            }

/***** process grblState {idle, run, hold, home, alarm, check, door} *****/
            processStatus(e.Raw);

/***** check and submit override values, set labels, checkbox *****/
            processStatusMessage(e.StatMsg);

/***** set DRO digital-read-out labels with machine and work coordinates *****/
            if (!simuEnabled)
            {
                updateDRO();
            }

/***** parser state Spinde/Coolant on/off, on other Forms: FeedRate, SpindleSpeed, G54-Coord *****/
            processParserState(e.parserState);

/***** update 2D view *****/
            if (grbl.posChanged)
            {
                VisuGCode.createMarkerPath();
                VisuGCode.updatePathPositions();
                checkMachineLimit();
                pictureBox1.Invalidate();
                if (Properties.Settings.Default.flowCheckRegistryChange && !isStreaming)
                {
                    gui.writePositionToRegistry();
                }
                grbl.posChanged = false;
            }
            if (grbl.wcoChanged)
            {
                checkMachineLimit();
                grbl.wcoChanged = false;
            }
            if (((isStreaming || isStreamingRequestStop)) && Properties.Settings.Default.guiProgressShow)
            {
                VisuGCode.ProcessedPath.processedPathDraw(grbl.posWork);
            }


            if (_diyControlPad != null)
            {
                if (oldRaw != e.Raw)
                {
                    _diyControlPad.sendFeedback(e.Raw);     //hand over original grbl text
                    oldRaw = e.Raw;
                }
            }
        }
Пример #6
0
        /// <summary>
        /// set parser state
        /// </summary>
        private static void setParserState(char cmd, double value, ref pState myParserState)
        {
            myParserState.changed = false;
            switch (Char.ToUpper(cmd))
            {
            case 'G':
                if (value <= 3)
                {
                    myParserState.motion = (byte)value;
                    break;
                }
                if ((value >= 17) && (value <= 19))
                {
                    myParserState.plane_select = (byte)value;
                }
                if ((value == 20) || (value == 21))
                {
                    myParserState.units = (byte)value;
                }
                if ((value >= 54) && (value <= 59))
                {
                    myParserState.coord_select = (byte)value;
                }
                if ((value == 90) || (value == 91))
                {
                    myParserState.distance = (byte)value;
                }
                if ((value == 93) || (value == 94))
                {
                    myParserState.feed_rate = (byte)value;
                }
                myParserState.changed = true;
                break;

            case 'M':
                if ((value <= 2) || (value == 30))
                {
                    myParserState.program_flow = (byte)value;        // M0, M1 pause, M2, M30 stop
                }
                if ((value >= 3) && (value <= 5))
                {
                    myParserState.spindle = (byte)value;        // M3, M4 start, M5 stop
                }
                if ((value >= 7) && (value <= 9))
                {
                    myParserState.coolant = (byte)value;        // M7, M8 on   M9 coolant off
                }
                if (value == 6)
                {
                    myParserState.toolchange = true;
                }
                myParserState.changed = true;
                break;

            case 'F':
                myParserState.FR      = value;
                myParserState.changed = true;
                break;

            case 'S':
                myParserState.SS      = value;
                myParserState.changed = true;
                break;

            case 'T':
                myParserState.tool    = (byte)value;
                myParserState.changed = true;
                break;
            }
        }