Ejemplo n.º 1
0
        public static void Parsing()
        {
            Point3D.Clear();

            //получим символ разделения дробной и целой части.
            string symbSeparatorDec = CultureInfo.CurrentCulture.NumberFormat.CurrencyDecimalSeparator;

            char csourse      = '.';
            char cdestination = ',';

            if (symbSeparatorDec == ".")
            {
                csourse      = ',';
                cdestination = '.';
            }

            bool AbsolutlePosParsing = true;

            PointCNC LastPoint = new PointCNC(ControllerPlanetCNC.Info.AxesXPositionMm, ControllerPlanetCNC.Info.AxesYPositionMm, ControllerPlanetCNC.Info.AxesZPositionMm, ControllerPlanetCNC.Info.AxesAPositionMm);

            int numRow = 0;

            foreach (string str in Gkode)
            {
                List <string> lcmd = ParseStringToListString(str);

                if (lcmd.Count == 0)
                {
                    continue;
                }


                //необходимо для получения следующей команды, т.к. команда G04 P500 будет раздельно
                int index = 0;
                foreach (string code in lcmd)
                {
                    if (code == "M3" || code == "M03")
                    {
                        LastPoint.InstrumentOn = true;
                    }

                    if (code == "M5" || code == "M05")
                    {
                        LastPoint.InstrumentOn = false;
                    }

                    if (code == "G0" || code == "G00") //холостое движение
                    {
                        LastPoint.workSpeed = false;
                    }

                    if (code == "G1" || code == "G01") //рабочее движение
                    {
                        LastPoint.workSpeed = true;
                    }

                    if (code.Substring(0, 1) == "X") //координата
                    {
                        string  svalue = code.Substring(1).Replace(csourse, cdestination);;
                        decimal pos    = 0;
                        decimal.TryParse(svalue, out pos);

                        if (AbsolutlePosParsing)
                        {
                            LastPoint.X = pos;
                        }
                        else
                        {
                            LastPoint.X += pos;
                        }
                    }


                    if (code.Substring(0, 1) == "Y") //координата
                    {
                        string  svalue = code.Substring(1).Replace(csourse, cdestination);;
                        decimal pos    = 0;
                        decimal.TryParse(svalue, out pos);

                        if (AbsolutlePosParsing)
                        {
                            LastPoint.Y = pos;
                        }
                        else
                        {
                            LastPoint.Y += pos;
                        }
                    }


                    if (code.Substring(0, 1) == "Z") //координата
                    {
                        string  svalue = code.Substring(1).Replace(csourse, cdestination);;
                        decimal pos    = 0;
                        decimal.TryParse(svalue, out pos);

                        if (AbsolutlePosParsing)
                        {
                            LastPoint.Z = pos;
                        }
                        else
                        {
                            LastPoint.Z += pos;
                        }
                    }


                    if (code.Substring(0, 1) == "A") //координата
                    {
                        string  svalue = code.Substring(1);
                        decimal pos    = 0;
                        decimal.TryParse(svalue, out pos);

                        if (AbsolutlePosParsing)
                        {
                            LastPoint.A = pos;
                        }
                        else
                        {
                            LastPoint.A += pos;
                        }
                    }

                    if (code == "G90")
                    {
                        AbsolutlePosParsing = true; //применяем абсолютные координаты
                    }

                    if (code == "G91")
                    {
                        AbsolutlePosParsing = false;//применяем относительные координаты
                    }

                    index++;
                }//foreach (string CODE in lcmd)

                LastPoint.numRow = numRow;

                Point3D.Add(LastPoint);

                numRow++;
            }
        }
        /// <summary>
        /// Заполнение структуры данными для станка, на основании предыдущих данных, и новой строки с данными
        /// </summary>
        /// <param name="lastDataRow"></param>
        /// <param name="nextDataRow"></param>
        public static void FillStructure(PointCNC lastDataRow, ref PointCNC nextDataRow, string _cmd)
        {
            // Установим большинство параметров, из предыдущей строки,
            // и при дальнейшем парсинге, изменим только те поля которые встретятся в анализируемой строке
            nextDataRow.X            = lastDataRow.X;
            nextDataRow.Y            = lastDataRow.Y;
            nextDataRow.Z            = lastDataRow.Z;
            nextDataRow.A            = lastDataRow.A;
            nextDataRow.InstrumentOn = lastDataRow.InstrumentOn;
            nextDataRow.workSpeed    = lastDataRow.workSpeed;

            //получим символ разделения дробной и целой части.
            string symbSeparatorDec = CultureInfo.CurrentCulture.NumberFormat.CurrencyDecimalSeparator;

            char csourse      = '.';
            char cdestination = ',';

            if (symbSeparatorDec == ".")
            {
                csourse      = ',';
                cdestination = '.';
            }

            //nextDataRow.DataString = nextDataRow.DataString.ToUpper();

            // 1) распарсим строку на отдельные строки с параметрами
            List <string> lcmd = ParseStringToSubString(_cmd);

            if (lcmd.Count == 0)
            {
                return;
            }

            //необходимо для получения следующей команды, т.к. команда G04 P500 будет раздельно
            int index = 0;

            foreach (string code in lcmd)
            {
                if (code == "M3")
                {
                    nextDataRow.InstrumentOn = true;
                }

                if (code == "M5")
                {
                    nextDataRow.InstrumentOn = false;
                }



                if (code == "G0") //холостое движение
                {
                    nextDataRow.workSpeed = false;
                }

                if (code.Length >= 2 && code.Substring(0, 2) == "G1") //рабочее движение
                {
                    nextDataRow.workSpeed = true;

                    //if (GlobalSetting.AppSetting.Controller == ControllerModel.PlanetCNC_MK2)
                    //{
                    //    if (code.Contains("."))
                    //    {
                    //        //извлечем значение после точки
                    //        string stmp = code.Substring(code.IndexOf(".")+1);

                    //        int inttmp = 57;

                    //        int.TryParse(stmp, out inttmp);

                    //        if (inttmp < 0) inttmp = 0;

                    //        if (inttmp > 57) inttmp = 57;

                    //        nextDataRow.Machine.TimeOutPause = (byte)inttmp;
                    //    }
                    //}
                }



                //#region G92 - несколько кодов отвечающие за смещение координат

                //if (code == "G92")
                //{
                //    //TODO: пока применим простое смещение с переносом в точку ноль
                //    ControllerPlanetCNC.CorrectionPos.UseCorrection = true;
                //    ControllerPlanetCNC.CorrectionPos.DeltaX = ControllerPlanetCNC.Info.AxesXPositionMm;
                //    ControllerPlanetCNC.CorrectionPos.DeltaY = ControllerPlanetCNC.Info.AxesYPositionMm;
                //    ControllerPlanetCNC.CorrectionPos.DeltaZ = ControllerPlanetCNC.Info.AxesZPositionMm;
                //    ControllerPlanetCNC.CorrectionPos.DeltaA = ControllerPlanetCNC.Info.AxesAPositionMm;
                //}

                //if (code == "G92.1")
                //{
                //    ControllerPlanetCNC.CorrectionPos.UseCorrection = false;
                //    ControllerPlanetCNC.CorrectionPos.DeltaX = 0;
                //    ControllerPlanetCNC.CorrectionPos.DeltaY = 0;
                //    ControllerPlanetCNC.CorrectionPos.DeltaZ = 0;
                //    ControllerPlanetCNC.CorrectionPos.DeltaA = 0;
                //}


                //if (code == "G92.2")
                //{
                //    ControllerPlanetCNC.CorrectionPos.UseCorrection = false;
                //}


                //if (code == "G92.3")
                //{
                //    ControllerPlanetCNC.CorrectionPos.UseCorrection = true;
                //}

                //#endregion


                //if (code.Substring(0, 1) == "F") //скорость движения, извлечем
                //{
                //    string svalue = code.Substring(1).Replace(csourse, cdestination);
                //    int spd;
                //    int.TryParse(svalue, out spd);

                //    nextDataRow.Machine.SpeedMaсhine = spd;
                //}

                //if (code.Substring(0, 1) == "N") //номер кадра
                //{
                //    string svalue = code.Substring(1).Replace(csourse, cdestination); ;
                //    int numKadr = 0;
                //    int.TryParse(svalue, out numKadr);

                //    nextDataRow.numberKadr = numKadr;
                //}

                //if (code.Substring(0, 1) == "S") //скорость движения, извлечем
                //{
                //    string svalue = code.Substring(1).Replace(csourse, cdestination); ;
                //    int spd = 0;
                //    int.TryParse(svalue, out spd);
                //    nextDataRow.Machine.SpeedSpindel = spd;
                //}


                if (code.Substring(0, 1) == "X") //координата
                {
                    string  svalue = code.Substring(1).Replace(csourse, cdestination);;
                    decimal pos    = 0;
                    decimal.TryParse(svalue, out pos);

                    if (AbsolutlePosParsing)
                    {
                        nextDataRow.X = pos;
                    }
                    else
                    {
                        nextDataRow.X += pos;
                    }
                }


                if (code.Substring(0, 1) == "Y") //координата
                {
                    string  svalue = code.Substring(1).Replace(csourse, cdestination);;
                    decimal pos    = 0;
                    decimal.TryParse(svalue, out pos);

                    if (AbsolutlePosParsing)
                    {
                        nextDataRow.Y = pos;
                    }
                    else
                    {
                        nextDataRow.Y += pos;
                    }
                }


                if (code.Substring(0, 1) == "Z") //координата
                {
                    string  svalue = code.Substring(1).Replace(csourse, cdestination);;
                    decimal pos    = 0;
                    decimal.TryParse(svalue, out pos);

                    if (AbsolutlePosParsing)
                    {
                        nextDataRow.Z = pos;
                    }
                    else
                    {
                        nextDataRow.Z += pos;
                    }
                }


                if (code.Substring(0, 1) == "A") //координата
                {
                    string  svalue = code.Substring(1);
                    decimal pos    = 0;
                    decimal.TryParse(svalue, out pos);

                    if (AbsolutlePosParsing)
                    {
                        nextDataRow.A = pos;
                    }
                    else
                    {
                        nextDataRow.A += pos;
                    }
                }

                //if (code == "G90")
                //{
                //    AbsolutlePosParsing = true; //применяем абсолютные координаты
                //}

                //if (code == "G91")
                //{
                //    AbsolutlePosParsing = false;//применяем относительные координаты
                //}


                //// информация о инструменте
                //if (code == "M6")
                //{

                //    try
                //    {
                //    //    //следующий параметр должен быть длительностью типа P500
                //        string strNumInstr = lcmd[index + 1].ToUpper();
                //        string strDiametrn = lcmd[index + 2].ToUpper();

                //        int NumInstr;
                //        int.TryParse(strNumInstr.Substring(1), out NumInstr);

                //        float Diametrn;
                //        float.TryParse(strDiametrn.Substring(1), out Diametrn);


                //        nextDataRow.Tools.NumberTools = NumInstr;
                //        nextDataRow.Tools.DiametrTools = Diametrn;
                //        nextDataRow.Tools.NeedChange = true;

                //        //    if (strNext.Substring(0, 1) == "P")
                //        //    {
                //        //        int times;
                //        //        int.TryParse(strNext.Substring(1), out times);
                //        //        nextDataRow.Extra.NeedPause = true;
                //        //        nextDataRow.Extra.timeoutMsec = times;
                //        //    }
                //    }
                //    catch (Exception)
                //    {

                //    //    nextDataRow.Extra.NeedPause = false;
                //    }

                //}


                index++;
            }//foreach (string CODE in lcmd)
        }