Hi, I am making SW that uses CAD drawing to generate G-code, and then sends it to arduino. So far so good, everything work on arduino (Arduino UNO, I use Arduino IDE), except one thing. In one form, that is used to actually run G-code and show tool possition. When I run the program, C# app sends one line of G-code, Arduino receive it, runs it. It sends number of steps, that it have done, it works and shows ok. After it is done, it sends an "OK" message(it does) and after that message code should send another line of G-Code, but it does not. Could anyone help me? thanks
Code in C#:
Run button click:
private void button1_Click(object sender, EventArgs e)
{
button1.Enabled = false;
button1.Text = "";
Thread.Sleep(2000);
while (!port.IsOpen)
{
}
if (port.IsOpen)
{
data_comm();
}
}
Read from arduino:
public void Read()
{
while (port.IsOpen)
{
try
{
string message = port.ReadLine();
if (message == "OK")
{
data_comm();
}
else
{
SetText(message);
}
}
catch (TimeoutException) { }
}
}
Send g_line:
public void data_comm()
{
textBox3.Text = SortedList*;*
_ string[] word = SortedList*.Split(' ');_
_ if (word[0] == "G1")_
_ {_
string x = Math.Round(double.Parse(word[1].Remove(0, 1), CultureInfo.InvariantCulture) / precission_X_Y, 0, MidpointRounding.ToEven).ToString().PadLeft(6, '0');
string y = Math.Round(double.Parse(word[2].Remove(0, 1), CultureInfo.InvariantCulture) / precission_X_Y, 0, MidpointRounding.ToEven).ToString().PadLeft(6, '0');
_ port.WriteLine("#G01X" + x + "Y" + y);_
_ }_
_ else if (word[0] == "G0")_
_ {_
string x = Math.Round(double.Parse(word[1].Remove(0, 1), CultureInfo.InvariantCulture) / precission_X_Y, 0, MidpointRounding.ToEven).ToString().PadLeft(6, '0');
string y = Math.Round(double.Parse(word[2].Remove(0, 1), CultureInfo.InvariantCulture) / precission_X_Y, 0, MidpointRounding.ToEven).ToString().PadLeft(6, '0');
_ port.WriteLine("#G00X" + x + "Y" + y);_
_ }_
_ i++;_
_ }_
Show possition from arduino:
private void SetText(string text)
_ {_
_ Graphics g = pictureBox1.CreateGraphics();_
_ g.TranslateTransform(0, pictureBox1.Height);_
_ g.ScaleTransform(0.3f, -0.3f);_
_ if (this.textBox1.InvokeRequired && this.textBox2.InvokeRequired)_
_ {_
_ SetTextCallback d = new SetTextCallback(SetText);_
_ this.Invoke(d, new object[] { text });_
_ }_
_ else*_
* {*
* try*
* {*
x_pos = Single.Parse(text.Substring(1, 6)) * 0.07f;
y_pos = Single.Parse(text.Substring(8, 6)) * 0.07f;
* this.textBox1.Text = Math.Round(x_pos, 0, MidpointRounding.ToEven).ToString();
this.textBox2.Text = Math.Round(y_pos, 0, MidpointRounding.ToEven).ToString();
g.DrawRectangle(p, x_pos, y_pos, 1, 1);
_ string[] word = SortedList.Split(' ');
}
catch { }
}
}*_