Exemplo n.º 1
0
        public void ModelInformation()
        {
            var stream = new TestStream();

            using var device = new CyberCard(stream);

            // survive without data
            Assert.Null(device.GetDeviceModel());
            Assert.Null(device.GetDeviceFirmware());
            Assert.Null(device.GetDeviceSerial());
            Assert.Null(device.GetDeviceManufacturer());
            Assert.Equal("P4\rP4\rP4\rP4\r", Encoding.ASCII.GetString(stream.ToWrittenArray()));  // check we tried for each

            // now we have data
            stream.SetupRead(Encoding.ASCII.GetBytes("#OR700LCDRM1U,BFE7103_8S1,000000000000,CyberPower\r"));
            Assert.Equal("OR700LCDRM1U", device.GetDeviceModel());
            Assert.Equal("BFE7103_8S1", device.GetDeviceFirmware());
            Assert.Equal("", device.GetDeviceSerial());                                              // ignore all 0's serial
            Assert.Equal("CyberPower", device.GetDeviceManufacturer());
            Assert.Equal("P4\rP4\rP4\rP4\rP4\r", Encoding.ASCII.GetString(stream.ToWrittenArray())); // check we tried only once more

            // subsequent read goes from cache
            Assert.Equal("OR700LCDRM1U", device.GetDeviceModel());
            Assert.Equal("BFE7103_8S1", device.GetDeviceFirmware());
            Assert.Equal("", device.GetDeviceSerial());
            Assert.Equal("CyberPower", device.GetDeviceManufacturer());
            Assert.Equal("P4\rP4\rP4\rP4\rP4\r", Encoding.ASCII.GetString(stream.ToWrittenArray()));  // no new reads
        }
Exemplo n.º 2
0
        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();
        }