Beispiel #1
0
        /// <summary>
        /// Start selected cycle.
        /// </summary>
        /// <returns>False on error. True if cycle is in process.</returns>
        public bool StartCycle()
        {
            if (taskList == null || taskList.Count == 0)
            {
                LogWrite("No task to run!");
                return(false);
            }

            cancelSource = new CancellationTokenSource();
            cancelToken  = cancelSource.Token;

            LogWrite("Learning cycle started...");
            currentTask = 0;

            GenericTask task = taskList[currentTask];

            taskType = task.GetType();
            LogWrite("Start task " + task.Description);
            try
            {
                cycleInProgress = task.InitializeTask();
                if (cycleInProgress)
                {
                    startTime = DateTime.Now;
                    StartTimer();
                }
                return(cycleInProgress);
            } catch (Exception ex)
            {
                LogWrite("Error processing task. Details: " + ex.Message);
                return(false);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Periodically called, asyncronous processing the cycle status.
        /// </summary>
        /// <param name="state">Not used</param>
        private async void processCycle(object state)
        {
            if (processStatus)
            {
                return;
            }
            processStatus = true;

            processStatus = await Task.Run(() =>
            {
                if (!cycleInProgress)
                {
                    return(false);
                }

                if (currentTask < taskList.Count)
                {
                    GenericTask t = taskList[currentTask];
                    if (t.IsTaskComplete(gauge))
                    {
                        LogWrite("End task: " + t.Name + " completed in " + DateTime.Now.Subtract(t.StartTime).ToString(@"hh\:mm\:ss"));
                        LogWrite("LStatus: " + gauge.GetDisplayValue("LStatus"));

                        currentTask += 1;
                        if (currentTask >= taskList.Count)
                        {   // Entire cycle completed
                            cycleInProgress = false;
                            CycleComplete();
                            OnCycleCompleted(EventArgs.Empty);
                            return(false);
                        }
                        GenericTask task = taskList[currentTask];
                        taskType         = task.GetType();
                        LogWrite("Start task " + task.Description);

                        if (taskType.Name == "RelaxTask")
                        {
                            LogWrite("Relaxing...Please wait...");
                        }

                        cycleInProgress = task.InitializeTask();
                        if (!cycleInProgress)
                        {
                            LogWrite("Error processing task.");
                        }
                    }
                    else if (taskType.Name == "ChargeTask")
                    {
                        if (gauge.Current == 0)
                        {
                            if (cycleModeType == BQEV23K.CycleModeType.Manual)
                            {
                                LogWrite("Charge Mode - Connect charger or power supply now.");
                            }
                            else
                            {
                                gauge.ToggleChargerRelay(true);
                                gauge.ToggleLoadRelay(false);
                                pushLoadStartButton = true;
                            }
                        }
                        elapsedTime = DateTime.Now.Subtract(t.StartTime);
                    }
                    else if (taskType.Name == "RelaxTask")
                    {
                        RelaxTask r = (RelaxTask)t;
                        elapsedTime = r.EndTime.Subtract(DateTime.Now);
                        gauge.ToggleChargerRelay(false);
                        gauge.ToggleLoadRelay(false);
                        pushLoadStartButton = true;
                    }
                    else if (taskType.Name == "DischargeTask")
                    {
                        if (gauge.Current == 0)
                        {
                            if (cycleModeType == BQEV23K.CycleModeType.Manual)
                            {
                                LogWrite("Discharge Mode - Connect load now.");
                            }
                            else
                            {
                                gauge.ToggleChargerRelay(false);
                                gauge.ToggleLoadRelay(true);
                                if (pushLoadStartButton)
                                {
                                    gauge.RemoteLoadStartButton();
                                    pushLoadStartButton = false;
                                }
                            }
                        }
                        elapsedTime = DateTime.Now.Subtract(t.StartTime);
                    }
                }
                return(false);
            }, cancelToken);
        }