private void ParseG30(string dataReceived) { // Get all responces var responces = dataReceived.Split('\n'); var probePosition = new Position(); string xstring = null; string ystring = null; string zstring = null; // Create G30 responce Event foreach (var responce in responces) { if (responce.Contains("Bed")) { try { // Bed X: 170.00 Y: 180.00 Z: -0.98 // (?: Z:\s[-] *[0 - 9] *.[0 - 9] *\s.*X:)([0 - 9] *.[0 - 9] *) xstring = Regex.Match(responce, @"(?:X:\s)([-]*[0-9]*.[0-9]*)", RegexOptions.CultureInvariant).Groups[ 1].Value; ystring = Regex.Match(responce, @"(?:Y:\s)([-]*[0-9]*.[0-9]*)", RegexOptions.CultureInvariant).Groups[ 1].Value; zstring = Regex.Match(responce, @"(?:Z:\s)([-]*[0-9]*.[0-9]*)", RegexOptions.CultureInvariant).Groups[ 1].Value; } catch (Exception parsException) { MessageBox.Show($"Error in parser of G30. Error: {parsException.Message}"); } if (zstring != null) { probePosition.Zstring = zstring; } if (ystring != null) { probePosition.Ystring = ystring; } if (xstring != null) { probePosition.Xstring = xstring; } ProbeResponceList.Add(probePosition); } } //ProbeResponceList.Add(probePosition); // Create G30 responce Event OnG30ProbeResponce(ProbeResponceList); }
private void ParseG29(string dataReceived) { // Get all responces var responces = dataReceived.Split('\n'); // X:0.00 Y:0.00 Z:5.00 E:0.00 Count X: 0 Y:0 Z:16000 foreach (var row in responces) { var positionPattern = @"X:[0-9]*\.[0-9]*\s*Y:[0-9]*\.[0-9]*\s*Z:[0-9]*\.[0-9]*\s*E:[0-9]*\.[0-9]*\s*Count\s*X:\s*"; var positionMatch = Regex.Match(row, positionPattern); if (positionMatch.Success) { var x = _numberConversion.ConvertStringToDecimal(Regex.Match(row, @"(?<=X:)[0-9]*\.[0-9]*").Value); var y = _numberConversion.ConvertStringToDecimal(Regex.Match(row, @"(?<=Y:)[0-9]*\.[0-9]*").Value); var z = _numberConversion.ConvertStringToDecimal(Regex.Match(row, @"(?<=Z:)[0-9]*\.[0-9]*").Value); ProbeResponceList.Add(new Position { X = x, Y = y, Z = z }); } } // Create G29 responce Event var eventG29Resonce = new Responce(new List <string>()); eventG29Resonce.ResponsRowList.AddRange(responces); OnG29Responce(eventG29Resonce); }
private void ParseG29() { // Return if The _dataReceived not contains ok\n if (WaitForOkAndNewLineToBeReceived() == false) { return; } // Get all responces var responces = GetAllResponces(); // X:0.00 Y:0.00 Z:5.00 E:0.00 Count X: 0 Y:0 Z:16000 foreach (var row in responces) { var positionPattern = @"X:[0-9]*\.[0-9]*\s*Y:[0-9]*\.[0-9]*\s*Z:[0-9]*\.[0-9]*\s*E:[0-9]*\.[0-9]*\s*Count\s*X:\s*"; var positionMatch = Regex.Match(row, positionPattern); if (positionMatch.Success) { var x = (double)Convert.ToDecimal(Regex.Match(row, @"(?<=X:)[0-9]*\.[0-9]*").Value.Replace('.', ',')); var y = (double)Convert.ToDecimal(Regex.Match(row, @"(?<=Y:)[0-9]*\.[0-9]*").Value.Replace('.', ',')); var z = (double)Convert.ToDecimal(Regex.Match(row, @"(?<=Z:)[0-9]*\.[0-9]*").Value.Replace('.', ',')); ProbeResponceList.Add(new Position { X = x, Y = y, Z = z }); } } // Create G29 responce Event var eventG29Resonce = new Responce(new List <string>()); eventG29Resonce.ResponsRowList.AddRange(responces); OnG29Responce(eventG29Resonce); //Delete the responce from the received bytes _dataReceived = DeleteResponceUpToAndInclusiveOk(_dataReceived); // ReadyForNextCommand OnReadyForNextCommand(EventArgs.Empty); }
private void ParseG30() { // Return if The _dataReceived not contains ok\n if (WaitForOkAndNewLineToBeReceived() == false) { return; } // Get all responces var responces = GetAllResponces(); // Create G30 responce Event foreach (var responce in responces) { if (responce.Contains("Bed")) { string xstring = null; string ystring = null; string zstring = null; try { // Bed X: 170.00 Y: 180.00 Z: -0.98 // (?: Z:\s[-] *[0 - 9] *.[0 - 9] *\s.*X:)([0 - 9] *.[0 - 9] *) xstring = Regex.Match(responce, @"(?:X:\s)([-]*[0-9]*.[0-9]*)", RegexOptions.CultureInvariant).Groups[ 1].Value; ystring = Regex.Match(responce, @"(?:Y:\s)([-]*[0-9]*.[0-9]*)", RegexOptions.CultureInvariant).Groups[ 1].Value; zstring = Regex.Match(responce, @"(?:Z:\s)([-]*[0-9]*.[0-9]*)", RegexOptions.CultureInvariant).Groups[ 1].Value; } catch (Exception parsException) { MessageBox.Show($"Error in parser of G30. Error: {parsException.Message}"); } var probePosition = new Position(); if (zstring != null) { probePosition.Z = Convert.ToDouble(zstring.Replace(".", ",")); } if (ystring != null) { probePosition.Y = Convert.ToDouble(ystring.Replace(".", ",")); } if (xstring != null) { probePosition.X = Convert.ToDouble(xstring.Replace(".", ",")); } ProbeResponceList.Add(probePosition); } } // Create G30 responce Event OnG30ProbeResponce(ProbeResponceList); //Delete the responce from the received bytes _dataReceived = DeleteResponceUpToAndInclusiveOk(_dataReceived); // ReadyForNextCommand OnReadyForNextCommand(EventArgs.Empty); }