Esempio n. 1
0
 public void TurnOff()
 {
     if (mStatus != MachineStatus.TurnedOff)
     {
         Recognizer?.Stop($"{nameof(Machine)} requested to be turned off");
         OnMachineShouldFinish.Invoke();
         ClearItemInfo();
         mStatus = MachineStatus.TurnedOff;
         OnMachineTurnOff?.Invoke(null);
         mLogger.WriteLine("Recognizer machine turned off");
     }
 }
Esempio n. 2
0
        public void StartWorking()
        {
            if (ItemInfo == null)
            {
                string errorMsg = $"{nameof(ItemInfo)} is unknown, machine will not start";
                mLogger.WriteLine(errorMsg);
                OnMachineFailedToStart?.Invoke(errorMsg);
                return;
            }

            if (Recognizer == null)
            {
                string errorMsg = $"{nameof(Recognizer)} is unknown, machine will not start";
                mLogger.WriteLine(errorMsg);
                OnMachineFailedToStart?.Invoke(errorMsg);
                return;
            }

            mStatus = MachineStatus.OnAndWorking;
            mLogger.WriteLine("Recognizer machine started");

            int maxHeatingTimeAllowedInMS = Math.Min(
                (ItemInfo as ItemInfo).MaxHeatingTimeInSeconds * MS_IN_ONE_SECOND,
                MaximalWorkingTimeInMS);

            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            mLogger.WriteLine("Recognizer machine start working...");

            new Thread(() => Recognizer.ProcessNewData(ItemInfo)).Start();

            while (mStatus != MachineStatus.OnAndShouldStop)
            {
                // Checks if the machine reaches timeout.
                if (stopwatch.ElapsedMilliseconds >= maxHeatingTimeAllowedInMS)
                {
                    string stopReason = $"{nameof(Machine)} should stop since reached maximal working time allowed {maxHeatingTimeAllowedInMS}";
                    Recognizer.Stop(stopReason);
                    OnMachineShouldFinish.Invoke();
                }
            }

            stopwatch.Stop();
            OnMachineFinishedWithResult?.Invoke(Recognizer.RecognitionStatus.ToString());
            StopMachine();
        }
Esempio n. 3
0
 private void SetShouldStopStatus(object sender, RecognizerFinishedEventArgs eventArgs)
 {
     mStatus = MachineStatus.OnAndShouldStop;
     OnMachineShouldFinish.Invoke();
 }