Пример #1
0
        private void StartCharge_ClickAsync(object sender, EventArgs e)
        {
            startCharge.Enabled = false;

            if (ChargerService.IsCharging)
            {
                ChargerService.StopCharge();
            }
            else
            {
                startDischarge.Enabled = false;


                if (ChargerService.State == CanReceivingNode.STATE_WARNING || ChargerService.State == CanReceivingNode.STATE_ON || ChargerService.State == CanReceivingNode.STATE_IDLE)
                {
                    ChargerService.RequestedCurrent   = float.Parse(RequestedChargeCurrent.Value.ToString());
                    ChargerService.RequestedVoltage   = float.Parse(RequestedChargeVoltage.Value.ToString());
                    ChargerService.SupplyCurrentLimit = float.Parse(maxSocketCurrent.SelectedItem.ToString());
                    ChargerService.StartCharge();
                }
                else
                {
                    MessageBox.Show("Charger of battery is currently in an invalid state to start charging",
                                    "Check Battery and Charger",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                }
            }

            UpdateStartStopDetails();
        }
        public async Task <bool> StartCharge()
        {
            IsPrecharging = true;

            latestChargeCurrent = 0;

            // Send 50ma so that the voltage can be measured
            ChargerService.RequestedVoltage = RequestedVoltage;
            ChargerService.RequestedCurrent = 0.05f;

            ChargerService.SupplyCurrentLimit = SupplyCurrentLimit;
            batteryIntegrator = 0;

            ChargerService.StopCharge();

            if (await ChargerService.WaitUntilChargerStopped(1000) == false)
            {
                return(false);
            }

            ChargerService.RequestedVoltage = BatteryService.BatteryData.EstimatePackVoltageFromCMUs / 1000;
            ChargerService.StartCharge();

            if (await ChargerService.WaitUntilChargerStarted(3000) == false ||
                await ChargerService.WaitUntilVoltageReached(RequestedVoltage, 10, 10000) == false)
            {
                await StopCharge();

                return(false);
            }

            await BatteryService.EngageContactors();

            if (await BatteryService.WaitUntilContactorsEngage(10000) == false)
            {
                await StopCharge();

                return(false);
            }

            StartTimer();

            IsPrecharging = false;

            return(true);
        }