private void SimulatorPopulate() { txtSimBatteryCharge.Text = NUT_Processor.SearchNUTData("battery.charge"); txtSimBatteryChargeLow.Text = NUT_Processor.SearchNUTData("battery.charge.low"); txtSimBatteryChargeWarn.Text = NUT_Processor.SearchNUTData("battery.charge.warning"); txtSimBatteryRuntime.Text = NUT_Processor.SearchNUTData("battery.runtime"); txtSimBatteryRuntimeLow.Text = NUT_Processor.SearchNUTData("battery.runtime.low"); txtSimBatteryVoltage.Text = NUT_Processor.SearchNUTData("battery.voltage"); txtSimBatteryVoltageNominal.Text = NUT_Processor.SearchNUTData("battery.voltage.nominal"); txtSimInputVoltage.Text = NUT_Processor.SearchNUTData("input.voltage"); txtSimInputVoltageNominal.Text = NUT_Processor.SearchNUTData("input.voltage.nominal"); txtSimOutputVoltage.Text = NUT_Processor.SearchNUTData("output.voltage"); cmbSimUPSStatus.Text = NUT_Processor.SearchNUTData("ups.status"); lblUPSModel.Text = NUT_Processor.UPSStatistics(); }
private void UPSPoll() { // Pulls latest data from UPSVariables short nutPort = Convert.ToInt16(txtPort.Text); // Determines whether it is in simulation mode (isSimulated) and whether it has already been polled if (Backend.Background.isSimulated && isPolled) { // I have a feeling I'm eventually going to need to put something here. } else { // If simulation mode is not active, it will poll the NUT server try { Tuple <string, bool> TupNutOutput = NUT_Poller.PollNUTServer(txtIPAddress.Text, nutPort); isPolled = TupNutOutput.Item2; string nutOutput = TupNutOutput.Item1; NUT_Processor.ParseNUTOutput(nutOutput); } catch (Exception e) { Console.WriteLine("Exception occured: " + e); } } // Error condition, unable to get data from NUT server for a variety of reasons if (!isPolled) { // Checks to see if this is the first time this program has been run string TempValue = Backend.NUT_Config.GetConfig("IP Address"); if (TempValue == null) { return; } Console.WriteLine("Did not get data successfully"); MessageBox.Show("Was unable to retrieve data from NUT sever. Got an \"Access Denied\" message.\n\nA common cause of this is the IP address of this client not being whitelisted on the NUT server."); isPollingUPS = false; return; } else { isPollingUPS = true; } ushort BatteryPercentage = Convert.ToUInt16(NUT_Processor.SearchNUTData("battery.charge")); if (BatteryPercentage <= AlarmPercentage) { PerformAlarmAction(); } if (Backend.Background.isSimulated && IsSimulatingDecay) { SimulateBatteryDecay(); } // Refreshes the data on the form Tuple <string, double, int> UPSBatteryStatus = NUT_Processor.GetBatteryStatus(); lblUPSStatus.Invoke((MethodInvoker)(() => UpdateUPSStatus(UPSBatteryStatus.Item1, UPSBatteryStatus.Item3))); lblUPSModel.Invoke((MethodInvoker)(() => lblUPSModel.Text = (NUT_Processor.UPSStatistics()))); }