public void CurrentInformation() { var stream = new TestStream(); using var device = new CyberCard(stream); // survive without data Assert.Null(device.GetInputVoltage()); Assert.Null(device.GetOutputVoltage()); Assert.Null(device.GetFrequency()); Assert.Null(device.GetLoadPercentage()); Assert.Null(device.GetBatteryPercentage()); Assert.Null(device.GetBatteryRuntime()); Assert.Equal("D\rD\rD\rD\rD\rD\r", Encoding.ASCII.GetString(stream.ToWrittenArray())); // check we tried for each // now we have data stream.SetupRead(Encoding.ASCII.GetBytes("#I121.0O121.0L042B088F060.1R073S\x80\x84\x90\x80\x80\r")); Assert.Equal(121, device.GetInputVoltage()); Assert.Equal(121, device.GetOutputVoltage()); Assert.Equal(60.1, device.GetFrequency()); Assert.Equal(0.42, device.GetLoadPercentage()); Assert.Equal(0.88, device.GetBatteryPercentage()); Assert.Equal(73, device.GetBatteryRuntime()); Assert.Equal("D\rD\rD\rD\rD\rD\rD\r", Encoding.ASCII.GetString(stream.ToWrittenArray())); // check we tried only once more // subsequent read goes from cache Assert.Equal(121, device.GetInputVoltage()); Assert.Equal(121, device.GetOutputVoltage()); Assert.Equal(60.1, device.GetFrequency()); Assert.Equal(0.42, device.GetLoadPercentage()); Assert.Equal(0.88, device.GetBatteryPercentage()); Assert.Equal(73, device.GetBatteryRuntime()); Assert.Equal("D\rD\rD\rD\rD\rD\rD\r", Encoding.ASCII.GetString(stream.ToWrittenArray())); // no new reads }
public void CurrentInformation_Cache() { var stream = new TestStream(); using var device = new CyberCard(stream); // we have data stream.SetupRead(Encoding.ASCII.GetBytes("#I121.0O121.0L042B088F060.1R073S\x80\x84\x90\x80\x80\r")); Assert.Equal(121, device.GetInputVoltage()); Assert.Equal(121, device.GetOutputVoltage()); Assert.Equal(60.1, device.GetFrequency()); Assert.Equal(0.42, device.GetLoadPercentage()); Assert.Equal(0.88, device.GetBatteryPercentage()); Assert.Equal(73, device.GetBatteryRuntime()); Assert.Equal("D\r", Encoding.ASCII.GetString(stream.ToWrittenArray())); // check we tried only once // subsequent read goes from cache Assert.Equal(121, device.GetInputVoltage()); Assert.Equal(121, device.GetOutputVoltage()); Assert.Equal(60.1, device.GetFrequency()); Assert.Equal(0.42, device.GetLoadPercentage()); Assert.Equal(0.88, device.GetBatteryPercentage()); Assert.Equal(73, device.GetBatteryRuntime()); Assert.Equal("D\r", Encoding.ASCII.GetString(stream.ToWrittenArray())); // no new reads // expire cache Thread.Sleep(1000); Assert.Null(device.GetInputVoltage()); Assert.Null(device.GetOutputVoltage()); Assert.Null(device.GetFrequency()); Assert.Null(device.GetLoadPercentage()); Assert.Null(device.GetBatteryPercentage()); Assert.Null(device.GetBatteryRuntime()); Assert.Equal("D\rD\rD\rD\rD\rD\rD\r", Encoding.ASCII.GetString(stream.ToWrittenArray())); // cache failure causes a new read every time // new data stream.SetupRead(Encoding.ASCII.GetBytes("#I121.4O122L41B087F060.4R033S\x80\x84\x90\x80\x80\r")); Assert.Equal(121.4, device.GetInputVoltage()); Assert.Equal(122, device.GetOutputVoltage()); Assert.Equal(60.4, device.GetFrequency()); Assert.Equal(0.41, device.GetLoadPercentage()); Assert.Equal(0.87, device.GetBatteryPercentage()); Assert.Equal(33, device.GetBatteryRuntime()); Assert.Equal("D\rD\rD\rD\rD\rD\rD\rD\r", Encoding.ASCII.GetString(stream.ToWrittenArray())); // only one new read once we have data // subsequent read goes from cache Assert.Equal(121.4, device.GetInputVoltage()); Assert.Equal(122, device.GetOutputVoltage()); Assert.Equal(60.4, device.GetFrequency()); Assert.Equal(0.41, device.GetLoadPercentage()); Assert.Equal(0.87, device.GetBatteryPercentage()); Assert.Equal(33, device.GetBatteryRuntime()); Assert.Equal("D\rD\rD\rD\rD\rD\rD\rD\r", Encoding.ASCII.GetString(stream.ToWrittenArray())); // no new reads }
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(); }