public bool Connect(string logPatch, string portName, int baudrate, int parityBits, int dataBits, int stopBits) { StopBits stop = new StopBits(); Parity parity = new Parity(); switch (stopBits) { case 0: stop = StopBits.None; break; case 1: stop = StopBits.One; break; case 2: stop = StopBits.Two; break; } switch (parityBits) { case 0: parity = Parity.None; break; case 1: parity = Parity.Even; break; case 2: parity = Parity.Odd; break; } try { this.Port = new SerialPort(portName, baudrate, parity, dataBits, stop); this.Port.DtrEnable = true; this.Port.RtsEnable = true; this.Port.Handshake = Handshake.None; this.Port.DataReceived += new SerialDataReceivedEventHandler(Serial_DataReceived); this.Port.ReadTimeout = 1000; this.Port.WriteTimeout = 1000; this.Port.Open(); return(true); } catch (Exception ex) { ConfigRead.SaveErrorToLog(logPatch, ex.Message); return(false); } }
public MainWindow() { InitializeComponent(); logPatch = @"..\..\Log"; int[] defaultValues = ConfigRead.ReadAndWriteInt(System.Environment.CurrentDirectory + @"\config", logPatch); baudrate = defaultValues[0]; stopBits = defaultValues[1]; parityBits = defaultValues[2]; dataBits = defaultValues[3]; steps = defaultValues[4]; }
public bool SendStringData(string logPatch, string text) { try { Port.WriteLine(text); return(true); } catch (Exception ex) { ConfigRead.SaveErrorToLog(logPatch, ex.Message); return(false); } }
private void menuSettingsMillingMachine_Click(object sender, RoutedEventArgs a) { try { SettingsMillingMachine s = new SettingsMillingMachine(this); s.Owner = this; s.ShowDialog(); } catch (Exception ex) { MessageBox.Show("Błąd podczas otwierania ustawień!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); ConfigRead.SaveErrorToLog(logPatch, ex.Message); } }
private void bEditGCodeWindow_Click(object sender, RoutedEventArgs e) { try { GCode_window.IsReadOnly = false; bCloseEditGCodeWindow.IsEnabled = true; bEditGCodeWindow.IsEnabled = false; } catch (Exception ex) { MessageBox.Show("Błąd edycji!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); ConfigRead.SaveErrorToLog(logPatch, ex.Message); } }
private void menuStop_Click(object sender, RoutedEventArgs a) { try { if ((m_oBackgroundWorker != null) && m_oBackgroundWorker.IsBusy) { m_oBackgroundWorker.CancelAsync(); } } catch (Exception ex) { MessageBox.Show("Błąd zatrzymania frezarki!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); ConfigRead.SaveErrorToLog(logPatch, ex.Message); } }
public bool Disconnect(string logPatch) { try { if (this.Port.IsOpen) { this.Port.Close(); } return(false); } catch (Exception ex) { ConfigRead.SaveErrorToLog(logPatch, ex.Message); return(true); } }
private void menuPauza_Click(object sender, RoutedEventArgs a) { try { if (connected) { } BlockButtons("Y", "none", "none", "none", "none", "none", "none"); statusWork.Background = Brushes.Yellow; } catch (Exception ex) { MessageBox.Show("Błąd wstrzymania pracy frezarki!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); ConfigRead.SaveErrorToLog(logPatch, ex.Message); } }
private void menuAboutProgram_Click(object sender, RoutedEventArgs e) { try { MessageBox.Show("Program PCBFrez jest częścią pracy inżynierskiej wykonywanej przez:" + "\nRafał Kunecki\nArkadiusz Hallmann\n\nProgram służy do obsługi wykonanej frezarki" + "do płyt PCB. Działa on w oparciu G-Code produkowany przez zewnętrzny program." + "Kod ten jest przetwarzany na " + "rozkazy dla sterowników silników krokowych, a" + "następnie wysyłany kolejno do sterowników.\n\nCopyright (C) Rafał Kunecki", "O Programie", MessageBoxButton.OK, MessageBoxImage.Information); } catch (Exception ex) { MessageBox.Show("Błąd podczas otwierania informacji o programie!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); ConfigRead.SaveErrorToLog(logPatch, ex.Message); } }
private void menuBased_Click(object sender, RoutedEventArgs a) { try { BlockButtons("none", "none", "none", "none", "none", "N", "none"); if (connected) { } BlockButtons("none", "none", "none", "none", "none", "Y", "none"); } catch (Exception ex) { BlockButtons("none", "none", "none", "none", "none", "Y", "none"); MessageBox.Show("Błąd bazowania!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); ConfigRead.SaveErrorToLog(logPatch, ex.Message); } }
private void menuDisconnect_Click(object sender, RoutedEventArgs a) { try { connected = serialConnect.Disconnect(logPatch); if (!connected) { BlockButtons("N", "none", "none", "Y", "N", "none", "none"); statusConnection.Background = Brushes.Red; } } catch (Exception ex) { MessageBox.Show("Błąd rozłączenia!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); ConfigRead.SaveErrorToLog(logPatch, ex.Message); } }
private void menuConnect_Click(object sender, RoutedEventArgs a) { try { connected = serialConnect.Connect(logPatch, portName, baudrate, parityBits, dataBits, stopBits); if (connected) { BlockButtons("Y", "none", "none", "N", "Y", "none", "none"); statusConnection.Background = Brushes.LightGreen; } } catch (Exception ex) { MessageBox.Show("Błąd połączenia!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); ConfigRead.SaveErrorToLog(logPatch, ex.Message); } }
private void menuOpen_Click(object sender, RoutedEventArgs e) { try { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "G-Code File NCD(*.ncd)|*.ncd|Text files(*.txt)|*.txt|All files(*.*)|*.*"; if (openFileDialog.ShowDialog() == true) { GCode_window.Text = File.ReadAllText(openFileDialog.FileName); } } catch (Exception ex) { MessageBox.Show("Błąd podczas otwierania pliku!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); ConfigRead.SaveErrorToLog(logPatch, ex.Message); } }
private void menuTest_Click(object sender, RoutedEventArgs a) { try { BlockButtons("none", "none", "none", "none", "none", "none", "N"); if (connected) { serialConnect.SendStringData(logPatch, "Test połączenia, polskie znaki:śćźżąęłó, liczby:1234567890 LRUD lrud"); Thread.Sleep(500); } BlockButtons("none", "none", "none", "none", "none", "none", "Y"); } catch (Exception ex) { BlockButtons("none", "none", "none", "none", "none", "none", "Y"); MessageBox.Show("Błąd Testu!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); ConfigRead.SaveErrorToLog(logPatch, ex.Message); } }
private void bCloseEditGCodeWindow_Click(object sender, RoutedEventArgs e) { try { GCode_window.IsReadOnly = true; bEditGCodeWindow.IsEnabled = true; bCloseEditGCodeWindow.IsEnabled = false; SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "G-Code File NCD(*.ncd)|*.ncd|Text files(*.txt)|*.txt"; if (saveFileDialog.ShowDialog() == true) { File.WriteAllText(saveFileDialog.FileName, GCode_window.Text); } } catch (Exception ex) { MessageBox.Show("Błąd zapisu!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); ConfigRead.SaveErrorToLog(logPatch, ex.Message); } }
private void menuStart_Click(object sender, RoutedEventArgs a) { try { if (connected) { codeConversion.lastPosition.xPosition = 0; codeConversion.lastPosition.yPosition = 0; codeConversion.lastPosition.zPosition = 0; numberOfLines = GCode_window.LineCount; if (m_oBackgroundWorker == null) { m_oBackgroundWorker = new BackgroundWorker(); m_oBackgroundWorker.DoWork += new DoWorkEventHandler(m_oBackgroundWorker_DoWork); m_oBackgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(m_oBackgroundWorker_RunWorkerCompleted); m_oBackgroundWorker.ProgressChanged += new ProgressChangedEventHandler(m_oBackgroundWorker_ProgressChanged); m_oBackgroundWorker.WorkerReportsProgress = true; m_oBackgroundWorker.WorkerSupportsCancellation = true; } pbStatus.Value = 0; m_oBackgroundWorker.RunWorkerAsync(); } bEditGCodeWindow.IsEnabled = false; GCode_window.IsEnabled = false; bCloseEditGCodeWindow.IsEnabled = false; GCode_window.IsReadOnly = true; BlockButtons("N", "Y", "Y", "none", "none", "none", "none"); statusWork.Background = Brushes.LightGreen; } catch (Exception ex) { MessageBox.Show("Błąd podczas startu frezarki!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); ConfigRead.SaveErrorToLog(logPatch, ex.Message); } }
private string[] Convertion(string[] gCodeStep, int stepToOneMM, string logPatch) { string[] result; long xPosition = 0, yPosition = 0, zPosition = 0; string currentCulture = Thread.CurrentThread.CurrentCulture.Name; CultureInfo ci = new CultureInfo(currentCulture); ci.NumberFormat.NumberDecimalSeparator = "."; Thread.CurrentThread.CurrentCulture = ci; try { if (gCodeStep[0] == "G01" || gCodeStep[0] == "G00") { directionX = string.Empty; directionY = string.Empty; directionZ = string.Empty; for (int j = 0; j < gCodeStep.Length; j++) { switch (gCodeStep[j][0]) { case 'X': { ConversionOneStep(gCodeStep[j], stepToOneMM, xPosition, NameOfDimension.X); break; } case 'Y': { ConversionOneStep(gCodeStep[j], stepToOneMM, xPosition, NameOfDimension.Y); break; } case 'Z': { ConversionOneStep(gCodeStep[j], stepToOneMM, xPosition, NameOfDimension.Z); break; } } } int dimensionsCounter = 0; result = new string[numberOfDimensionsInGCode]; if (xTrue) { result[dimensionsCounter] = xPosition.ToString(); dimensionsCounter++; } if (yTrue) { result[dimensionsCounter] = yPosition.ToString(); dimensionsCounter++; } if (zTrue) { result[dimensionsCounter] = zPosition.ToString(); } return(result); } result = new string[1]; result[0] = "nothing;"; return(result); } catch (Exception ex) { ConfigRead.SaveErrorToLog(logPatch, ex.Message); result = null; return(result); } }
public string GetConvertedSteps(string gCodeStep, int stepToOneMM, string logPatch) { string[] resultTable = null; string[] stepTable = null; string result = null; try { stepTable = gCodeStep.Split(new char[] { ' ' }); resultTable = Convertion(stepTable, stepToOneMM, logPatch); result = "S;"; switch (numberOfDimensionsInGCode) { case 1: { if (xTrue) { result += "X;" + resultTable[0] + ";" + directionX + ";"; } if (yTrue) { result += "Y;" + resultTable[0] + ";" + directionY + ";"; } if (zTrue) { result += "Z;" + resultTable[0] + ";" + directionZ + ";"; } numberOfDimensionsInGCode = 0; xTrue = false; yTrue = false; zTrue = false; break; } case 2: { if (xTrue && yTrue) { result += "X;" + resultTable[0] + ";" + directionX + ";" + "Y;" + resultTable[1] + ";" + directionY + ";"; } if (xTrue && zTrue) { result += "X;" + resultTable[0] + ";" + directionX + ";" + "Z;" + resultTable[1] + ";" + directionZ + ";"; } if (yTrue && zTrue) { result += "Y;" + resultTable[0] + ";" + directionY + ";" + "Z;" + resultTable[1] + ";" + directionZ + ";"; } numberOfDimensionsInGCode = 0; xTrue = false; yTrue = false; zTrue = false; break; } case 3: { if (xTrue && yTrue && zTrue) { result += "X;" + resultTable[0] + ";" + directionX + ";" + "Y;" + resultTable[1] + ";" + directionY + ";" + "Z;" + resultTable[2] + ";" + directionZ + ";"; } numberOfDimensionsInGCode = 0; xTrue = false; yTrue = false; zTrue = false; break; } default: { foreach (string x in resultTable) { result += x; } numberOfDimensionsInGCode = 0; xTrue = false; yTrue = false; zTrue = false; break; } } result += "END;"; return(result); } catch (Exception ex) { ConfigRead.SaveErrorToLog(logPatch, ex.Message); return(ex.Message); } }