public EnderecamentoLadder LeEndereco(ref Int32 _pos, EnderecamentoPrograma enderecamento) { EnderecamentoLadder _endLido = null; TipoEnderecamentoDispositivo _tpEndLido; Int32 _iIndiceEndLido = 0; SimboloBasico _sb = null; _sb = new SimboloBasico(LeCodigoInterpretavel(_pos)); switch (_sb.getCI()) { case CodigosInterpretaveis.NENHUM: break; case CodigosInterpretaveis.FIM_DA_LINHA: break; case CodigosInterpretaveis.CONTATO_NA: case CodigosInterpretaveis.CONTATO_NF: _tpEndLido = LeTipoEnderecamento(_pos); _pos++; _iIndiceEndLido = LeInteiro(_pos); _pos++; _endLido = enderecamento.Find(_tpEndLido, _iIndiceEndLido); break; case CodigosInterpretaveis.BOBINA_SAIDA: case CodigosInterpretaveis.RESET: break; case CodigosInterpretaveis.PARALELO_INICIAL: case CodigosInterpretaveis.PARALELO_FINAL: case CodigosInterpretaveis.PARALELO_PROXIMO: break; case CodigosInterpretaveis.CONTADOR: break; case CodigosInterpretaveis.TEMPORIZADOR: break; } return(_endLido); }
private ProgramaBasico LerExecutavel(String strNomeProjeto) { List <int> lstCodigosLidos = new List <int>(); CodigosInterpretaveis guarda = CodigosInterpretaveis.NENHUM; if (this.ExisteCodigoInterpretavel()) { Int32 intContaFim = 0; Int32 intIndiceLinha = 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 = this.PosInicial; i < DadosConvertidosChar.Length; i++) { guarda = LeCodigoInterpretavel(i); i++; switch (guarda) { case CodigosInterpretaveis.NENHUM: intContaFim++; break; case CodigosInterpretaveis.FIM_DA_LINHA: intContaFim++; if (LeCodigoInterpretavel(i + 1) != CodigosInterpretaveis.NENHUM) { intIndiceLinha = programa.InsereLinhaNoFinal(new LinhaCompleta()); } break; case CodigosInterpretaveis.CONTATO_NA: case CodigosInterpretaveis.CONTATO_NF: intContaFim = 0; { SimboloBasico _sb = new SimboloBasico((CodigosInterpretaveis)guarda); _tpEndLido = LeTipoEnderecamento(i); i++; _iIndiceEndLido = LeInteiro(i); i++; _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; { 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; programa.linhas[intIndiceLinha].simbolos.Add(new SimboloBasico((CodigosInterpretaveis)guarda)); break; case CodigosInterpretaveis.CONTADOR: intContaFim = 0; { 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; { 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; } } return(programa); } return(null); }