public static void FillStructure(DataRow lastDataRow, ref DataRow nextDataRow) { // Установим большинство параметров, из предыдущей строки, // и при дальнейшем парсинге, изменим только те поля которые встретятся в анализируемой строке nextDataRow.duplicate(lastDataRow); //получим символ разделения дробной и целой части. string symbSeparatorDec = CultureInfo.CurrentCulture.NumberFormat.CurrencyDecimalSeparator; char csourse = '.'; char cdestination = ','; if (symbSeparatorDec == ".") { csourse = ','; cdestination = '.'; } nextDataRow.DataString = nextDataRow.DataString.ToUpper(); // 1) распарсим строку на отдельные строки с параметрами List<string> lcmd = ParseStringToSubString(nextDataRow.DataString); if (lcmd.Count == 0) return; //необходимо для получения следующей команды, т.к. команда G04 P500 будет раздельно int index = 0; foreach (string code in lcmd) { if (code == "M3") { nextDataRow.Machine.SpindelON = true; } if (code == "M5") { nextDataRow.Machine.SpindelON = false; } if (code == "M7") { nextDataRow.Machine.Chanel2ON = true; } if (code == "M8") { nextDataRow.Machine.Chanel3ON = true; } if (code == "M9") { nextDataRow.Machine.Chanel2ON = false; nextDataRow.Machine.Chanel3ON = false; } if (code == "G0") //холостое движение { nextDataRow.Machine.NumGkode = 0; } if (code == "G1") //рабочее движение { nextDataRow.Machine.NumGkode = 1; nextDataRow.Machine.WithoutPause = false; } // TODO: добавить условие при котором данная команда доступна только с контроллером MK2, или вместо неё просто срабатывает команда g1 if (code == "G1.1") //рабочее движение без дальнейшей остановки в конце отрезка { nextDataRow.Machine.NumGkode = 1; nextDataRow.Machine.WithoutPause = true; } if (code == "G2") //TODO: не реализовано { nextDataRow.Machine.NumGkode = 2; } if (code == "G3") //TODO: не реализовано { nextDataRow.Machine.NumGkode = 3; } if (code == "G4") //пауза { try { //следующий параметр должен быть длительностью типа P500 string strNext = lcmd[index + 1].ToUpper(); 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; } } #region G92 - несколько кодов отвечающие за смещение координат if (code == "G92") { //TODO: пока применим простое смещение с переносом в точку ноль Controller.CorrectionPos.useCorrection = true; Controller.CorrectionPos.deltaX = Controller.INFO.AxesX_PositionMM; Controller.CorrectionPos.deltaY = Controller.INFO.AxesY_PositionMM; Controller.CorrectionPos.deltaZ = Controller.INFO.AxesZ_PositionMM; Controller.CorrectionPos.deltaA = Controller.INFO.AxesA_PositionMM; } if (code == "G92.1") { Controller.CorrectionPos.useCorrection = false; Controller.CorrectionPos.deltaX = 0; Controller.CorrectionPos.deltaY = 0; Controller.CorrectionPos.deltaZ = 0; Controller.CorrectionPos.deltaA = 0; } if (code == "G92.2") { Controller.CorrectionPos.useCorrection = false; } if (code == "G92.3") { Controller.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.POS.X = pos; else nextDataRow.POS.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.POS.Y = pos; else nextDataRow.POS.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.POS.Z = pos; else nextDataRow.POS.Z += pos; } if (code.Substring(0, 1) == "A") //координата { string svalue = code.Substring(1); decimal pos = 0; decimal.TryParse(svalue, out pos); if (AbsolutlePosParsing) nextDataRow.POS.A = pos; else nextDataRow.POS.A += pos; } if (code == "G90") { AbsolutlePosParsing = true; //применяем абсолютные координаты } if (code == "G91") { AbsolutlePosParsing = false;//применяем относительные координаты } index++; }//foreach (string CODE in lcmd) }
public static void FillStructure(DataRow lastDataRow, ref DataRow nextDataRow) { // Установим большинство параметров, из предыдущей строки, // и при дальнейшем парсинге, изменим только те поля которые встретятся в анализируемой строке nextDataRow.duplicate(lastDataRow); //получим символ разделения дробной и целой части. string symbSeparatorDec = CultureInfo.CurrentCulture.NumberFormat.CurrencyDecimalSeparator; char csourse = '.'; char cdestination = ','; if (symbSeparatorDec == ".") { csourse = ','; cdestination = '.'; } nextDataRow.DataString = nextDataRow.DataString.ToUpper(); // 1) распарсим строку на отдельные строки с параметрами List <string> lcmd = ParseStringToSubString(nextDataRow.DataString); if (lcmd.Count == 0) { return; } //необходимо для получения следующей команды, т.к. команда G04 P500 будет раздельно int index = 0; foreach (string code in lcmd) { if (code == "M3") { nextDataRow.Machine.SpindelON = true; } if (code == "M5") { nextDataRow.Machine.SpindelON = false; } if (code == "M7") { nextDataRow.Machine.Chanel2ON = true; } if (code == "M8") { nextDataRow.Machine.Chanel3ON = true; } if (code == "M9") { nextDataRow.Machine.Chanel2ON = false; nextDataRow.Machine.Chanel3ON = false; } if (code == "G0") //холостое движение { nextDataRow.Machine.NumGkode = 0; } if (code == "G1") //рабочее движение { nextDataRow.Machine.NumGkode = 1; nextDataRow.Machine.WithoutPause = false; } // TODO: добавить условие при котором данная команда доступна только с контроллером MK2, или вместо неё просто срабатывает команда g1 if (code == "G1.1") //рабочее движение без дальнейшей остановки в конце отрезка { nextDataRow.Machine.NumGkode = 1; nextDataRow.Machine.WithoutPause = true; } if (code == "G2") //TODO: не реализовано { nextDataRow.Machine.NumGkode = 2; } if (code == "G3") //TODO: не реализовано { nextDataRow.Machine.NumGkode = 3; } if (code == "G4") //пауза { try { //следующий параметр должен быть длительностью типа P500 string strNext = lcmd[index + 1].ToUpper(); 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; } } #region G92 - несколько кодов отвечающие за смещение координат if (code == "G92") { //TODO: пока применим простое смещение с переносом в точку ноль Controller.CorrectionPos.useCorrection = true; Controller.CorrectionPos.deltaX = Controller.INFO.AxesX_PositionMM; Controller.CorrectionPos.deltaY = Controller.INFO.AxesY_PositionMM; Controller.CorrectionPos.deltaZ = Controller.INFO.AxesZ_PositionMM; Controller.CorrectionPos.deltaA = Controller.INFO.AxesA_PositionMM; } if (code == "G92.1") { Controller.CorrectionPos.useCorrection = false; Controller.CorrectionPos.deltaX = 0; Controller.CorrectionPos.deltaY = 0; Controller.CorrectionPos.deltaZ = 0; Controller.CorrectionPos.deltaA = 0; } if (code == "G92.2") { Controller.CorrectionPos.useCorrection = false; } if (code == "G92.3") { Controller.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.POS.X = pos; } else { nextDataRow.POS.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.POS.Y = pos; } else { nextDataRow.POS.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.POS.Z = pos; } else { nextDataRow.POS.Z += pos; } } if (code.Substring(0, 1) == "A") //координата { string svalue = code.Substring(1); decimal pos = 0; decimal.TryParse(svalue, out pos); if (AbsolutlePosParsing) { nextDataRow.POS.A = pos; } else { nextDataRow.POS.A += pos; } } if (code == "G90") { AbsolutlePosParsing = true; //применяем абсолютные координаты } if (code == "G91") { AbsolutlePosParsing = false;//применяем относительные координаты } index++; }//foreach (string CODE in lcmd) }
/// <summary> /// Заполнение структуры данными для станка, на основании предыдущих данных, и новой строки с данными /// </summary> /// <param name="lastDataRow"></param> /// <param name="nextDataRow"></param> public static void FillStructure(DataRow lastDataRow, ref DataRow nextDataRow) { // Установим большинство параметров, из предыдущей строки, // и при дальнейшем парсинге, изменим только те поля которые встретятся в анализируемой строке nextDataRow.duplicate(lastDataRow); //получим символ разделения дробной и целой части. string symbSeparatorDec = CultureInfo.CurrentCulture.NumberFormat.CurrencyDecimalSeparator; char csourse = '.'; char cdestination = ','; if (symbSeparatorDec == ".") { csourse = ','; cdestination = '.'; } nextDataRow.DataString = nextDataRow.DataString.ToUpper(); // 1) распарсим строку на отдельные строки с параметрами List <string> lcmd = ParseStringToSubString(nextDataRow.DataString); if (lcmd.Count == 0) { return; } //необходимо для получения следующей команды, т.к. команда G04 P500 будет раздельно int index = 0; foreach (string code in lcmd) { if (code == "M3") { nextDataRow.Machine.SpindelON = true; } if (code == "M5") { nextDataRow.Machine.SpindelON = false; } if (code == "M7") { nextDataRow.Machine.Chanel2ON = true; } if (code == "M8") { nextDataRow.Machine.Chanel3ON = true; } if (code == "M9") { nextDataRow.Machine.Chanel2ON = false; nextDataRow.Machine.Chanel3ON = false; } if (code == "G0") //холостое движение { nextDataRow.Machine.NumGkode = 0; } if (code.Length >= 2 && code.Substring(0, 2) == "G1") //рабочее движение { nextDataRow.Machine.NumGkode = 1; 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; } } } if (code == "G2") //TODO: не реализовано { nextDataRow.Machine.NumGkode = 2; } if (code == "G3") //TODO: не реализовано { nextDataRow.Machine.NumGkode = 3; } if (code == "G4") //пауза { try { //следующий параметр должен быть длительностью типа P500 string strNext = lcmd[index + 1].ToUpper(); 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; } } #region G92 - несколько кодов отвечающие за смещение координат if (code == "G92") { //TODO: пока применим простое смещение с переносом в точку ноль ControllerPlanetCNC.CorrectionPos.UseCorrection = true; ControllerPlanetCNC.CorrectionPos.DeltaX = ControllerPlanetCNC.Info.AxesX_PositionMM; ControllerPlanetCNC.CorrectionPos.DeltaY = ControllerPlanetCNC.Info.AxesY_PositionMM; ControllerPlanetCNC.CorrectionPos.DeltaZ = ControllerPlanetCNC.Info.AxesZ_PositionMM; ControllerPlanetCNC.CorrectionPos.DeltaA = ControllerPlanetCNC.Info.AxesA_PositionMM; } 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.POS.X = pos; } else { nextDataRow.POS.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.POS.Y = pos; } else { nextDataRow.POS.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.POS.Z = pos; } else { nextDataRow.POS.Z += pos; } } if (code.Substring(0, 1) == "A") //координата { string svalue = code.Substring(1); decimal pos = 0; decimal.TryParse(svalue, out pos); if (AbsolutlePosParsing) { nextDataRow.POS.A = pos; } else { nextDataRow.POS.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) }