public void loop_enviaExistentes() { tempo_decorrido.Restart(); while (!para_looping_envios) { if (tempo_decorrido.ElapsedMilliseconds >= 2000) { if (esperandoF) { cont_conexao_erro++; if (cont_conexao_erro >= 3) { MessageBox.Show("Conexão perdida.", "Erro!", MessageBoxButtons.OK, MessageBoxIcon.Error); esperandoF = false; cont_conexao_erro = 0; Ligar.Invoke(new MethodInvoker(() => { Ligar.Enabled = true; Ligar.PerformClick(); })); } } envios.Fila.Add(15); tempo_decorrido.Restart(); esperandoF = true; } if (envios.Fila.Count > 0 && em_uso == false) { em_uso = true; var tmpDados = new List <byte>(); foreach (var dadoItem in envios.Fila.ToList()) { if (dadoItem == -5) { ConexaoBO.enviaDados(tmpDados, SrpComm); tmpDados.Clear(); } else { tmpDados.Add(dadoItem); } } if (tmpDados.Count > 0) { ConexaoBO.enviaDados(tmpDados, SrpComm); } envios.Fila.Clear(); em_uso = false; } //Thread.Sleep(50); ProcessaDados(); } Thread.Sleep(1000); SrpComm.Close(); }
public void toggleBotaoLigar(bool ativo) { if (Ligar.InvokeRequired) { Ligar.Invoke(new MethodInvoker(() => { Ligar.Enabled = ativo; })); } else { Ligar.Enabled = ativo; } }
private void Sair_Click(object sender, EventArgs e) { if (!para_looping_envios) { Sair.Enabled = false; Ligar.PerformClick(); Thread.Sleep(1000); Close(); } else { Sair.Enabled = false; Thread.Sleep(1000); Close(); } }
void OnDrawGizmosSelected() { if (opcao == Opcao.GERAR_PONTOS) { opcao = Opcao.ESTATICO; listaNodos.Clear(); float z = 0; int cont = 0; for (int i = 0; i < sizeZ; i++) { float x = 0; for (int j = 0; j < sizeX; j++) { Transform obj = Instantiate(prefabNodo) as Transform; obj.transform.position = new Vector3(this.transform.position.x + x, 0, this.transform.position.z + z); obj.gameObject.name = string.Format("[ P{0} - {1} ]", ++cont, name); Nodo node = obj.gameObject.GetComponent<Nodo>(); node.Id = cont; obj.parent = transform; x += raio; } z += raio; } } if (ligar == Ligar.LIGA) { ligar = Ligar.NAO_LIGA; float raioRaizDe2 = raio * 1.415f; List<Nodo> listaTemp = new List<Nodo>(); Nodo[] filhos = GetComponentsInChildren<Nodo>(); for (int i = 0; i < filhos.Length; i++) { listaTemp.Clear(); for (int j = 0; j < filhos.Length; j++) { if (i != j) { distancia = Vector3.Distance(filhos[i].transform.position, filhos[j].transform.position); if (distancia < raioRaizDe2) { listaTemp.Add(filhos[j]); } } } filhos[i].ListaAdj = listaTemp; filhos[i].adjacentes = listaTemp.ToArray(); } } }
public void ProcessaDados() { em_uso = true; if (aguardando_conexao) { Thread.Sleep(250); } var bytesToRead = SrpComm.BytesToRead; if (bytesToRead > 0) { cont_conexao_erro = 0; tempo_decorrido.Restart(); var buffer = new byte[bytesToRead]; SrpComm.Read(buffer, 0, bytesToRead); processando = true; try { for (var i = 0; i < buffer.Length; i++) { var b = buffer[i]; if (configurar_leds) { Configura_LEDs(b); configurar_leds = false; continue; } if (b == 1) { limpaTela(); } else if (b >= 165 && b <= 169) { conexao_sucesso = true; envios.Fila.Add(3); } else if (b >= 32 && b <= 127) { var lbl = buscarLabelPorNome("lbl" + posinicial); var txt = ((char)b).ToString(); if (lbl.InvokeRequired) { lbl.Invoke(new MethodInvoker(() => { lbl.Text = txt; })); } else { lbl.Text = txt; } posinicial++; if (posinicial == 160) { posinicial = 192; } else if (posinicial == 224) { posinicial = 223; } } else if (b == 162 || b == 163) { var lbl = buscarLabelPorNome("lbl" + posinicial); var txt = " "; txt = b == 162 ? "\u2193" : "\u2191"; if (lbl.InvokeRequired) { lbl.Invoke(new MethodInvoker(() => { lbl.Text = txt; })); } else { lbl.Text = txt; } } else if ((b >= 128 && b <= 159) || (b >= 192 && b <= 223)) { posinicial = b; } else if (b == 3) { configurar_leds = true; } else if (b == 15) { esperandoF = false; } } } catch (Exception e) { MessageBox.Show(e.ToString()); MessageBox.Show(posinicial.ToString()); } } if (aguardando_conexao) { if (!conexao_sucesso) { MessageBox.Show("Não foi possível fazer conexão com o equipamento.", "Erro!", MessageBoxButtons.OK, MessageBoxIcon.Error); Ligar.Invoke(new MethodInvoker(() => { Ligar.Enabled = true; Ligar.PerformClick(); })); } else { toggleBotoesNavegacao(true); toggleBotaoLigar(true); } aguardando_conexao = false; conexao_sucesso = true; } em_uso = false; processando = false; }