private void programaLadderToolStripMenuItem_Click(object sender, EventArgs e) { if (s_port != "") { Teste t; try { System.IO.File.Delete(txt_serial); } catch { } System.IO.File.WriteAllText(txt_cmd, "Co"); System.IO.File.WriteAllText(txt_d, "1"); SetForegroundWindow(p.MainWindowHandle); Thread.Sleep(200); try { cmd = System.IO.File.ReadAllText(txt_serial); t = new Teste(cmd); t.ShowDialog(); SetForegroundWindow(p.MainWindowHandle); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } try { SerialCom.Open(); // MessageBox.Show(cmd); SerialCom.Write("&l" + cmd + "&"); SerialCom.Close(); } catch { MessageBox.Show("Erro ao enviar programa", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { Config_port = new ConfigPort(this); Config_port.Show(); } }
public void conectar() { if (s_port != "") { if (SerialCom.IsOpen == true) { SerialCom.Close(); } SerialCom.PortName = s_port; SerialCom.BaudRate = baud_r; SerialCom.Parity = par; SerialCom.DataBits = Bits_dados; SerialCom.StopBits = Stopbit; } else { Config_port = new ConfigPort(this); Config_port.Show(); } }
private void configurarConecçãoSerialToolStripMenuItem_Click(object sender, EventArgs e) { Config_port = new ConfigPort(this); Config_port.Show(); }
private void autoCLPToolStripMenuItem_Click(object sender, EventArgs e) { #region variaveis bool novo_cil = false, flag_temp = false; int aux_cont = 0; string cil_atual = ""; string TextPic = ""; String[] avanco = { "A", "B", "C", "D", "E", "F" }; String[] retorno = { "a", "b", "c", "d", "e", "f" }; #endregion string testinho = ""; if (s_port != "") { #region Algoritimo_string for (int aux = 0; aux < form2.tamanho_string; aux++) { if (form2.string_mestre.Substring(aux, 1) == "_") { novo_cil = true; } else if (form2.string_mestre.Substring(aux, 2) == "'(") { TextPic += "(;"; //MessageBox.Show(TextPic); aux++; flag_temp = false; } else if (form2.string_mestre.Substring(aux, 2) == ")'") { TextPic += ");"; //MessageBox.Show(TextPic); aux++; flag_temp = false; } else if (form2.string_mestre.Substring(aux, 2) == "),") { TextPic += "};"; // MessageBox.Show(TextPic); aux++; flag_temp = false; } else if (form2.string_mestre.Substring(aux, 2) == ",(") { int j; int aux_temp = 0; for (j = aux + 2; form2.string_mestre.Substring(j, 2) != "),"; j++) { aux_temp++; } switch (aux_temp) { case 1: TextPic += "{;0;0;0;"; break; case 2: TextPic += "{;0;0;"; break; case 3: TextPic += "{;0;"; break; case 4: TextPic += "{;"; break; } // MessageBox.Show(TextPic); aux++; flag_temp = true; } else if (flag_temp) { TextPic += form2.string_mestre.Substring(aux, 1) + ";"; } else if (form2.string_mestre.Substring(aux, 2) == "X.") { TextPic += "];"; // MessageBox.Show(TextPic); aux++; } else if (form2.string_mestre.Substring(aux, 2) == ".(") { int j, k, l; j = aux + 1; aux_cont = 0; int aux_temp = 0; int aux_2 = 0; for (int x = aux + 2; form2.string_mestre.Substring(x, 2) != "X."; x++) { aux_temp++; } for (int y = aux_temp + aux; form2.string_mestre.Substring(y, 1) != ")"; y--, aux_2++) { ; } switch (aux_2) { case 0: TextPic += "[;0;"; break; case 1: TextPic += "[;"; break; } while (j < form2.tamanho_string) { if (form2.string_mestre.Substring(j, 2) == ".(") { aux_cont++; } else if (form2.string_mestre.Substring(j, 2) == "X." && aux_cont == 0) { break; } else if (form2.string_mestre.Substring(j, 2) == "X." && aux_cont > 0) { aux_cont--; } j++; } for (k = j; form2.string_mestre.Substring(k, 1) != ")"; k--) { ; } l = k + 1; do { if (form2.string_mestre.Substring(l, 1) == "X") { aux++; break; } else { TextPic += form2.string_mestre.Substring(l, 1) + ";"; } l++; } while (true); } else if (form2.string_mestre.Substring(aux, 1) == "+") { novo_cil = false; for (int x = 0; x < 6; x++) { if (form2.Names[x] == cil_atual) { TextPic += avanco[x] + ";"; } } cil_atual = ""; } else if (form2.string_mestre.Substring(aux, 1) == "-") { novo_cil = false; for (int x = 0; x < 6; x++) { if (form2.Names[x] == cil_atual) { TextPic += retorno[x] + ";"; } } cil_atual = ""; } else if (novo_cil == true) { cil_atual += form2.string_mestre.Substring(aux, 1); } } if (form2.continuo == true) { TextPic += "*;"; } try { SerialCom.Open(); SerialCom.Write("&a"); testinho += "&a"; for (int x = 0; x < 6; x++) { try { SerialCom.Write(form2.Saidas_fisicas[x].ToString() + ";"); testinho += form2.Saidas_fisicas[x].ToString() + ";"; } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } for (int x = 0; x < 6; x++) { try { SerialCom.Write(form2.avanco[x].ToString() + ";"); testinho += form2.avanco[x].ToString() + ";"; } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } for (int x = 0; x < 6; x++) { try { SerialCom.Write((form2.retorno[x]).ToString() + ";"); testinho += form2.retorno[x].ToString() + ";"; } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } for (int i = 0; i < TextPic.Length; i++) { SerialCom.Write(TextPic[i].ToString()); testinho += TextPic[i].ToString(); } //MessageBox.Show(testinho.ToString()); SerialCom.Write("&"); testinho += "&"; SerialCom.Close(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } else { Config_port = new ConfigPort(this); Config_port.Show(); } #endregion }