private void tmrRefresh_Tick(object sender, EventArgs e) { lblModel.Text = $"Model:\n{Device.GetDeviceModel()}"; lblCapacity.Text = $"Capacity:\n{Device.GetDeviceCapacity():0} W {Device.GetDeviceCapacityVA():0} VA"; lblVoltageInput.Text = $"Input voltage:\n{Device.GetInputVoltage():0.0} V"; lblVoltageOutput.Text = $"Output voltage:\n{Device.GetOutputVoltage():0.0} V"; lblFrequency.Text = $"Frequency:\n{Device.GetFrequency():0.0} Hz"; lblLoadPercentage.Text = $"Load:\n{Device.GetLoadPercentage():0%}"; lblBatteryPercentage.Text = $"Battery remaining:\n{Device.GetBatteryPercentage():0%}"; lblBatteryRuntime.Text = $"Battery runtime:\n{Device.GetBatteryRuntime():0} minutes"; var status = ""; if (Device.IsPoweredOn() == true) { status += "Powered on\n"; } if (Device.IsPoweredOff() == true) { status += "Powered off\n"; } if (Device.IsPendingPowerOn() == true) { status += "Pending power on\n"; } if (Device.IsPendingPowerOff() == true) { status += "Pending power off\n"; } if (Device.IsTestInProgress() == true) { status += "Testing\n"; } if (Device.IsAlarmActive() == true) { status += "Alarm active\n"; } if (Device.IsUsingBattery() == true) { status += "On battery power\n"; } if (Device.IsBatteryLow() == true) { status += "Battery low\n"; } if (Device.IsBatteryCharging() == true) { status += "Battery charging\n"; } if (Device.IsBatteryFull() == true) { status += "Battery full\n"; } lblStatus.Text = status.Trim(); }
public void CurrentInformation_Flags() { var stream = new TestStream(); using var device = new CyberCard(stream); // survive without data Assert.Null(device.IsPendingPowerOn()); Assert.Null(device.IsPendingPowerOff()); Assert.Null(device.IsTestInProgress()); Assert.Null(device.IsAlarmActive()); Assert.Null(device.IsUsingBattery()); Assert.Null(device.IsBatteryLow()); Assert.Null(device.IsBatteryCharging()); Assert.Null(device.IsBatteryFull()); Assert.Null(device.IsPoweredOff()); Assert.Null(device.IsPoweredOn()); Assert.Equal("D\rD\rD\rD\rD\rD\rD\rD\rD\rD\r", Encoding.ASCII.GetString(stream.ToWrittenArray())); // check we tried for each // now we have data stream.SetupRead(Encoding.Latin1.GetBytes("#I121.0O121.0L042B088F060.1R073S\x80\x84\x90\x80\x80\r")); Assert.False(device.IsPendingPowerOn()); Assert.False(device.IsPendingPowerOff()); Assert.False(device.IsTestInProgress()); Assert.False(device.IsAlarmActive()); Assert.False(device.IsUsingBattery()); Assert.False(device.IsBatteryLow()); Assert.True(device.IsBatteryCharging()); Assert.False(device.IsBatteryFull()); Assert.False(device.IsPoweredOff()); Assert.True(device.IsPoweredOn()); Assert.Equal("D\rD\rD\rD\rD\rD\rD\rD\rD\rD\rD\r", Encoding.ASCII.GetString(stream.ToWrittenArray())); // check we tried only once more // subsequent read goes from cache Assert.False(device.IsPendingPowerOn()); Assert.False(device.IsPendingPowerOff()); Assert.False(device.IsTestInProgress()); Assert.False(device.IsAlarmActive()); Assert.False(device.IsUsingBattery()); Assert.False(device.IsBatteryLow()); Assert.True(device.IsBatteryCharging()); Assert.False(device.IsBatteryFull()); Assert.False(device.IsPoweredOff()); Assert.True(device.IsPoweredOn()); Assert.Equal("D\rD\rD\rD\rD\rD\rD\rD\rD\rD\rD\r", Encoding.ASCII.GetString(stream.ToWrittenArray())); // no new reads // wait for cache to expire Thread.Sleep(1000); stream.SetupRead(Encoding.Latin1.GetBytes("#I000.0O120.0L000B100F060.1R084S\xc0\x81\x88\x80\x80\r")); Assert.False(device.IsPendingPowerOn()); Assert.False(device.IsPendingPowerOff()); Assert.False(device.IsTestInProgress()); Assert.False(device.IsAlarmActive()); Assert.True(device.IsUsingBattery()); Assert.False(device.IsBatteryLow()); Assert.False(device.IsBatteryCharging()); Assert.False(device.IsBatteryFull()); Assert.False(device.IsPoweredOff()); Assert.True(device.IsPoweredOn()); Assert.Equal("D\rD\rD\rD\rD\rD\rD\rD\rD\rD\rD\rD\r", Encoding.ASCII.GetString(stream.ToWrittenArray())); // check we tried only once more }