private void buttonStartGode_Click(object sender, EventArgs e) { DataToMach3 dt = new DataToMach3(); textBoxGCode.Text = dt.ConvertToGCode(dataGridView1, Double.Parse(textBoxBoardOffsetX.Text), Double.Parse(textBoxBoardOffsetY.Text), textBoxRunSpeed.Text); }
private void backgroundWorkerDoCommand_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; DataView rundata = new DataView(); rundata = dtom3.ConvertToGCode(dataGridView1, Double.Parse(ribbonTextBoxBoardOffsetX.TextBoxText), Double.Parse(ribbonTextBoxBoardOffsetY.TextBoxText)); RunMach3Command(Script, "F" + FeedRate.ToString()); int currentrow = 0; int totalrows = rundata.Count; if (totalrows > 0) { // MessageBox.Show(totalrows.ToString()); RunMach3Command(Script, "G01 B0 C0"); /* table columns * RefDes * Type * PosX * PosY * ComponentRotation * ComponentValue * feederNumber * Code * * * ComponentHeight * DefaultRotation * VerifywithCamera * TapeFeeder * * * feederPosX * feederPosY * feederPosZ * PickPlusChipHeight * */ double progresspert = 0; double progresspertcalc = 100 / totalrows; while (currentrow < totalrows) { if (backgroundWorkerDoCommand.CancellationPending) { e.Cancel = true; SetCurrentCommandText("Stopped"); rundata.Dispose(); break; } if (currentrow == 0) { SetFeederOutputs(Int32.Parse(rundata[currentrow]["FeederNumber"].ToString())); // send feeder to position } SetCurrentCommandText("Feeder Activate"); SetCurrentCommandText(rundata[currentrow]["RefDes"].ToString()); StetActiveComponentText(rundata[currentrow]["RefDes"].ToString()); if (!rundata[currentrow]["TapeFeeder"].ToString().Equals("True")) { RunMach3Command(Script, "G01 A" + CalcAZHeight(ClearHeight)); } RunMach3Command(Script, "G01 X" + rundata[currentrow]["feederPosX"].ToString() + " Y" + rundata[currentrow]["feederPosY"].ToString()); SetCurrentCommandText("Picking Component"); if (rundata[currentrow]["TapeFeeder"].ToString().Equals("True")) { // use picker 1 RunMach3Command(Script, "G01 A" + CalcAZHeight(Double.Parse(rundata[currentrow]["feederPosZ"].ToString()))); // go down and turn on suction ChangeVacOutput(1, true); RunMach3Command(Script, "G01 A" + CalcAZHeight(LowClearHeight)); } else { // use picker 2 RunMach3Command(Script, "G01 Z" + CalcAZHeight(Double.Parse(rundata[currentrow]["feederPosZ"].ToString()))); // go down and turn on suction ChangeVacOutput(2, true); //Thread.Sleep(500); RunMach3Command(Script, "G01 Z" + CalcAZHeight(ClearHeight)); } // send picker to pick next item if (currentrow >= 0 && (currentrow + 1) < totalrows) { SetFeederOutputs(Int32.Parse(rundata[currentrow + 1]["FeederNumber"].ToString())); // send feeder to position } // rotate head double ComponentRotation = Double.Parse(rundata[currentrow]["ComponentRotation"].ToString()); double DefaultRotation = Double.Parse(rundata[currentrow]["DefaultRotation"].ToString()); RunMach3Command(Script, "G92 B0 C0 "); SetResultsLabelText("Placing Component"); if (rundata[currentrow]["TapeFeeder"].ToString().Equals("True")) { // use picker 1 if (DefaultRotation != ComponentRotation) { double newrotation = DefaultRotation + ComponentRotation; RunMach3Command(Script, "G01 B" + newrotation.ToString() + " X" + rundata[currentrow]["PosX"].ToString() + " Y" + rundata[currentrow]["PosY"].ToString()); } else { RunMach3Command(Script, "G01 X" + rundata[currentrow]["PosX"].ToString() + " Y" + rundata[currentrow]["PosY"].ToString()); } RunMach3Command(Script, "G01 A" + CalcAZPlaceHeight(Double.Parse(rundata[currentrow]["ComponentHeight"].ToString()))); // go down and turn off suction ChangeVacOutput(1, false); RunMach3Command(Script, "G01 A" + CalcAZHeight(LowClearHeight)); } else { // use picker 2 CalcXwithNeedleSpacing if (DefaultRotation != ComponentRotation) { double newrotation = DefaultRotation + ComponentRotation; RunMach3Command(Script, "G01 C" + newrotation.ToString() + " X" + CalcXwithNeedleSpacing(Double.Parse(rundata[currentrow]["PosX"].ToString())).ToString() + " Y" + rundata[currentrow]["PosY"].ToString()); } else { RunMach3Command(Script, "G01 X" + CalcXwithNeedleSpacing(Double.Parse(rundata[currentrow]["PosX"].ToString())).ToString() + " Y" + rundata[currentrow]["PosY"].ToString()); } RunMach3Command(Script, "G01 Z" + CalcAZPlaceHeight(Double.Parse(rundata[currentrow]["ComponentHeight"].ToString()))); // go down and turn off suction ChangeVacOutput(2, false); RunMach3Command(Script, "G01 Z" + CalcAZHeight(ClearHeight)); } currentrow++; progresspert = currentrow * progresspertcalc; worker.ReportProgress(Int32.Parse(progresspert.ToString())); } rundata.Dispose(); // home all axis and zero SetResultsLabelText("Home and Reset"); RunMach3Command(Script, "G92 B0 C0 "); Thread thrd = new Thread(new ThreadStart(DoHomeAll)); thrd.Start(); thrd.IsBackground = true; } else { MessageBox.Show("Board file not loaded"); } backgroundWorkerDoCommand.CancelAsync(); worker.ReportProgress(100); }