//TODO Criar exception para nobreak nao conectado public UpsData UpsInquiry() { try { UpsData info = new UpsData(); info = new UpsData { Success = true, TensaoEntrada = RandomNumber(119.0, 127.0), TensaoEntrada2 = 127.0, TensaoSaida = RandomNumber(119.0, 124.0), OMaximumCurrent = 50, Frequencia = RandomNumber(58.0, 61.9), TensaoBateria = RandomNumber(10, 12), Temperatura = RandomNumber(15, 28), UpsStatus = "UPS STATUS", UtilityFailImmediate = false, BateriaBaixa = false, StatusBypassBoostBuckActive = ProbabilityBoolean(0.1), //false, FalhaUps = ProbabilityBoolean(0.2), UpsStandBy = false, TesteEmProgresso = false, DesligamentoAtivo = false, BeepLigado = true }; info.PorcentagemBateria = RandomNumber(30, 100); return(info); } catch (NobreakNotConnectedException) { return(new UpsData() { Success = false }); } }
//TODO Criar exception para nobreak nao conectado public UpsData UpsInquiry() { try { string[] resultQ1 = WriteAndReadFromUPS("Q1\r").Replace('(', ' ').Replace("\r", " ").Replace(".", ",").Split(new char[] { ' ' }); string[] resultF = WriteAndReadFromUPS("F\r").Replace('(', ' ').Replace("\r", " ").Replace(".", ",").Split(new char[] { ' ' });; UpsData info = new UpsData(); if (resultQ1.Count <string>() == 10) { char[] chArray = resultQ1[8].ToCharArray(); int _OMaximumCurrent; Int32.TryParse(resultQ1[4], out _OMaximumCurrent); double _Temperature; Double.TryParse(resultQ1[7], out _Temperature); info = new UpsData { Success = true, TensaoEntrada = Convert.ToDouble(resultQ1[1]), TensaoEntrada2 = Convert.ToDouble(resultQ1[2]), TensaoSaida = Convert.ToDouble(resultQ1[3]), OMaximumCurrent = _OMaximumCurrent, Frequencia = Convert.ToDouble(resultQ1[5]), TensaoBateria = Convert.ToDouble(resultQ1[6]), Temperatura = _Temperature, UpsStatus = resultQ1[8], UtilityFailImmediate = CharToBool(chArray[0]), BateriaBaixa = CharToBool(chArray[1]), StatusBypassBoostBuckActive = CharToBool(chArray[2]), FalhaUps = CharToBool(chArray[3]), UpsStandBy = CharToBool(chArray[4]), TesteEmProgresso = CharToBool(chArray[5]), DesligamentoAtivo = CharToBool(chArray[6]), BeepLigado = CharToBool(chArray[7]), Carga = 0 }; string fdados = WriteAndReadFromUPS("F\r"); NobreakInfo.TensaoSaidaNominal = Conversion.Val(Strings.Mid(fdados, 2, 3)) + Conversion.Val(Strings.Mid(fdados, 6, 1)) / 10.0; NobreakInfo.CargaNominal = checked ((long)Math.Round(Conversion.Val(Strings.Mid(fdados, 8, 3)))); NobreakInfo.FrequenciaNominal = Conversion.Val(Strings.Mid(fdados, 24, 2)) + Conversion.Val(Strings.Mid(fdados, 27, 1)) / 10.0; if (StringType.StrCmp(Strings.Mid(fdados, 14, 1), ".", false) == 0) { NobreakInfo.TensaoBateriaNominal = Conversion.Val(Strings.Mid(fdados, 12, 2)) + Conversion.Val(Strings.Mid(fdados, 15, 2)) / 100.0; } if (StringType.StrCmp(Strings.Mid(fdados, 15, 1), ".", false) != 0) { //return null; } NobreakInfo.TensaoBateriaNominal = Conversion.Val(Strings.Mid(fdados, 12, 3)) + Conversion.Val(Strings.Mid(fdados, 16, 1)) / 10.0; if (info.TensaoBateria != -1.0) { if (NobreakInfo.TensaoBateriaNominal != 0.0 & info.TensaoBateria != 0.0) { int num = !(info.TensaoBateria > 1.0 & info.TensaoBateria <3.0& NobreakInfo.TensaoBateriaNominal> 100.0) ? 1 : 96; NobreakInfo.PorcentagemBateria = checked ((int)Math.Round(unchecked (100.0 * (info.TensaoBateria * (double)num - NobreakInfo.TensaoBateriaNominal * 0.833) / (NobreakInfo.TensaoBateriaNominal * 1.0833 * 0.23)))); if (NobreakInfo.PorcentagemBateria > 100) { NobreakInfo.PorcentagemBateria = 100; } if (NobreakInfo.PorcentagemBateria < 0) { NobreakInfo.PorcentagemBateria = 0; } } else { NobreakInfo.PorcentagemBateria = 0; } } else { NobreakInfo.PorcentagemBateria = -1; } info.PorcentagemBateria = NobreakInfo.PorcentagemBateria; return(info); } return(info); } catch (NobreakNotConnectedException) { return(new UpsData() { Success = false }); } }