private void LerExecutavel(String DadosConvertidosChar, String strNomeProjeto) { List <int> lstCodigosLidos = new List <int>(); CodigosInterpretaveis guarda = CodigosInterpretaveis.NENHUM; if (DadosConvertidosChar.IndexOf("@laddermic.com") != -1) { Int32 intContaFim = 0; Int32 intIndiceLinha = 0; Int32 iNumOperandos = 0; EnderecamentoLadder _endLido; TipoEnderecamentoDispositivo _tpEndLido; Int32 _iIndiceEndLido = 0; /// Cria um programa novo vazio ProgramaBasico programa = new ProgramaBasico(); programa.StsPrograma = ProgramaBasico.StatusPrograma.NOVO; programa.Nome = strNomeProjeto; programa.dispositivo = new DispositivoLadder(1); programa.endereco.AlocaEnderecamentoIO(programa.dispositivo); programa.endereco.AlocaEnderecamentoMemoria(programa.dispositivo, programa.endereco.lstMemoria, TipoEnderecamentoDispositivo.DIGITAL_MEMORIA, 10); programa.endereco.AlocaEnderecamentoMemoria(programa.dispositivo, programa.endereco.lstTemporizador, TipoEnderecamentoDispositivo.DIGITAL_MEMORIA_TEMPORIZADOR, 10); programa.endereco.AlocaEnderecamentoMemoria(programa.dispositivo, programa.endereco.lstContador, TipoEnderecamentoDispositivo.DIGITAL_MEMORIA_CONTADOR, 10); intIndiceLinha = programa.InsereLinhaNoFinal(new LinhaCompleta()); for (int i = DadosConvertidosChar.IndexOf("@laddermic.com") + 15; i < DadosConvertidosChar.Length; i++) { guarda = (CodigosInterpretaveis)Convert.ToChar(DadosConvertidosChar.Substring(i, 1)); switch (guarda) { case CodigosInterpretaveis.NENHUM: intContaFim++; iNumOperandos = 0; break; case CodigosInterpretaveis.FIM_DA_LINHA: intContaFim++; iNumOperandos = 0; if ((CodigosInterpretaveis)Convert.ToChar(DadosConvertidosChar.Substring(i + 1, 1)) != CodigosInterpretaveis.NENHUM) { intIndiceLinha = programa.InsereLinhaNoFinal(new LinhaCompleta()); } break; //case CodigosInterpretaveis.INICIO_DA_LINHA: case CodigosInterpretaveis.CONTATO_NA: case CodigosInterpretaveis.CONTATO_NF: intContaFim = 0; iNumOperandos = 2; { SimboloBasico _sb = new SimboloBasico((CodigosInterpretaveis)guarda); //_sb.setOperando(0, programa.endereco.Find((TipoEnderecamentoDispositivo)Convert.ToChar(DadosConvertidosChar.Substring(i + 1, 1)), (Int32)Convert.ToChar(DadosConvertidosChar.Substring(i + 2, 1)))); _tpEndLido = (TipoEnderecamentoDispositivo)Convert.ToChar(DadosConvertidosChar.Substring(i + 1, 1)); _iIndiceEndLido = (Int32)Convert.ToChar(DadosConvertidosChar.Substring(i + 2, 1)); _endLido = programa.endereco.Find(_tpEndLido, _iIndiceEndLido); if (_endLido == null) { programa.dispositivo.lstBitPorta[_iIndiceEndLido - 1].TipoDefinido = _tpEndLido; programa.dispositivo.RealocaEnderecoDispositivo(); programa.endereco.AlocaEnderecamentoIO(programa.dispositivo); _endLido = programa.endereco.Find(_tpEndLido, _iIndiceEndLido); } _sb.setOperando(0, _endLido); i += 2; programa.linhas[intIndiceLinha].simbolos.Add(_sb); } break; case CodigosInterpretaveis.BOBINA_SAIDA: case CodigosInterpretaveis.RESET: intContaFim = 0; iNumOperandos = 2; { ListaSimbolo _lstSB = new ListaSimbolo(); _lstSB.Add(new SimboloBasico((CodigosInterpretaveis)guarda)); _tpEndLido = (TipoEnderecamentoDispositivo)Convert.ToChar(DadosConvertidosChar.Substring(i + 1, 1)); _iIndiceEndLido = (Int32)Convert.ToChar(DadosConvertidosChar.Substring(i + 2, 1)); _endLido = programa.endereco.Find(_tpEndLido, _iIndiceEndLido); if (_endLido == null) { programa.dispositivo.lstBitPorta[_iIndiceEndLido - 1].TipoDefinido = _tpEndLido; programa.dispositivo.RealocaEnderecoDispositivo(); programa.endereco.AlocaEnderecamentoIO(programa.dispositivo); _endLido = programa.endereco.Find(_tpEndLido, _iIndiceEndLido); } _lstSB[_lstSB.Count - 1].setOperando(0, _endLido); i += 2; programa.linhas[intIndiceLinha].Insere2Saida(_lstSB); _lstSB.Clear(); } break; case CodigosInterpretaveis.PARALELO_INICIAL: case CodigosInterpretaveis.PARALELO_FINAL: case CodigosInterpretaveis.PARALELO_PROXIMO: intContaFim = 0; iNumOperandos = 0; programa.linhas[intIndiceLinha].simbolos.Add(new SimboloBasico((CodigosInterpretaveis)guarda)); break; case CodigosInterpretaveis.CONTADOR: intContaFim = 0; iNumOperandos = 3; { ListaSimbolo _lstSB = new ListaSimbolo(); _lstSB.Add(new SimboloBasico((CodigosInterpretaveis)guarda)); _lstSB[_lstSB.Count - 1].setOperando(0, programa.endereco.Find(TipoEnderecamentoDispositivo.DIGITAL_MEMORIA_CONTADOR, (Int32)Convert.ToChar(DadosConvertidosChar.Substring(i + 1, 1)))); ((EnderecamentoLadder)_lstSB[_lstSB.Count - 1].getOperandos(0)).Contador.Tipo = (Int32)Convert.ToChar(DadosConvertidosChar.Substring(i + 2, 1)); ((EnderecamentoLadder)_lstSB[_lstSB.Count - 1].getOperandos(0)).Contador.Preset = (Int32)Convert.ToChar(DadosConvertidosChar.Substring(i + 3, 1)); _lstSB[_lstSB.Count - 1].setOperando(1, ((EnderecamentoLadder)_lstSB[_lstSB.Count - 1].getOperandos(0)).Contador.Tipo); _lstSB[_lstSB.Count - 1].setOperando(2, ((EnderecamentoLadder)_lstSB[_lstSB.Count - 1].getOperandos(0)).Contador.Preset); i += 3; programa.linhas[intIndiceLinha].Insere2Saida(_lstSB); _lstSB.Clear(); } break; case CodigosInterpretaveis.TEMPORIZADOR: intContaFim = 0; iNumOperandos = 4; { ListaSimbolo _lstSB = new ListaSimbolo(); _lstSB.Add(new SimboloBasico((CodigosInterpretaveis)guarda)); _lstSB[_lstSB.Count - 1].setOperando(0, programa.endereco.Find(TipoEnderecamentoDispositivo.DIGITAL_MEMORIA_TEMPORIZADOR, (Int32)Convert.ToChar(DadosConvertidosChar.Substring(i + 1, 1)))); ((EnderecamentoLadder)_lstSB[_lstSB.Count - 1].getOperandos(0)).Temporizador.Tipo = (Int32)Convert.ToChar(DadosConvertidosChar.Substring(i + 2, 1)); ((EnderecamentoLadder)_lstSB[_lstSB.Count - 1].getOperandos(0)).Temporizador.BaseTempo = (Int32)Convert.ToChar(DadosConvertidosChar.Substring(i + 3, 1)); ((EnderecamentoLadder)_lstSB[_lstSB.Count - 1].getOperandos(0)).Temporizador.Preset = (Int32)Convert.ToChar(DadosConvertidosChar.Substring(i + 4, 1)); _lstSB[_lstSB.Count - 1].setOperando(1, ((EnderecamentoLadder)_lstSB[_lstSB.Count - 1].getOperandos(0)).Temporizador.Tipo); _lstSB[_lstSB.Count - 1].setOperando(2, ((EnderecamentoLadder)_lstSB[_lstSB.Count - 1].getOperandos(0)).Temporizador.Preset); _lstSB[_lstSB.Count - 1].setOperando(4, ((EnderecamentoLadder)_lstSB[_lstSB.Count - 1].getOperandos(0)).Temporizador.BaseTempo); i += 4; programa.linhas[intIndiceLinha].Insere2Saida(_lstSB); _lstSB.Clear(); } break; } /// fim dos códigos if (intContaFim >= 2) { /// grava os dados lidos do codigo intepretavel ModuloIntegracaoMSP430 p = new ModuloIntegracaoMSP430(); p.CriaArquivo("codigosinterpretaveis.txt", DadosConvertidosChar.Substring(DadosConvertidosChar.IndexOf("@laddermic.com"), i - DadosConvertidosChar.IndexOf("@laddermic.com") + 1)); /// força saída do loop i = DadosConvertidosChar.Length; } } frmProj = new ProjetoLadder(programa); frmProj.MdiParent = this; frmProj.Show(); frmProj.SetText(); } else { MessageBox.Show("O arquivo não foi reconhecido pelo sistema!", "Abrir Arquivos ...", MessageBoxButtons.OK, MessageBoxIcon.Error); } }