This commit is contained in:
meelstorm
2025-09-29 09:31:57 +02:00
parent 87c1145744
commit 1aecb79ade
16 changed files with 110 additions and 16 deletions

View File

@@ -0,0 +1,6 @@
namespace VisionBuilder.UI.Common.Commands;
public class ErrorsInSequenceEvent
{
public int Errors { get; set; }
}

View File

@@ -128,7 +128,7 @@ public abstract class BaseRecognitionControl: IRecognitionControl
SessionEnded = DateTime.Now
});
_loadingService.StopLoading($"Stopping {_settings.CameraName}");
IsPaused=false; // ensure paused is reset
}
public void Pause()
@@ -141,6 +141,8 @@ public abstract class BaseRecognitionControl: IRecognitionControl
IsPaused = false;
}
int _errorsInSequence = 0;
private async Task Loop(CancellationToken token)
{
@@ -149,7 +151,7 @@ public abstract class BaseRecognitionControl: IRecognitionControl
{
if (IsPaused)
{
await Task.Delay(100, token);
await Task.Delay(100, token).ConfigureAwait(false);
continue;
}
@@ -165,6 +167,18 @@ public abstract class BaseRecognitionControl: IRecognitionControl
Thread.Sleep(_settings.MinimumProcessingTime - (int)processed.Value.processingTime.Milliseconds);
}
if (processed.Value.errorNames.Length > 0)
{
_errorsInSequence++;
if (_errorsInSequence >= _settings.ErrorsInSequenceAlarm)
{
ErrorsInSequenceAlarm(new ErrorsInSequenceEvent(){Errors = _errorsInSequence});
}
}
else
{
_errorsInSequence = 0;
}
var processingResult = new ImageProcessedEvent()
{
@@ -188,6 +202,7 @@ public abstract class BaseRecognitionControl: IRecognitionControl
}
public event Action<ImageProcessedEvent> ImageProcessed = delegate { };
public event Action<SessionStartedEvent>? SessionStarted = delegate { };
public event Action<SessionEndedEvent>? SessionEnded = delegate { };
public event Action<SessionStartedEvent> SessionStarted = delegate { };
public event Action<SessionEndedEvent> SessionEnded = delegate { };
public event Action<ErrorsInSequenceEvent> ErrorsInSequenceAlarm = delegate { };
}

View File

@@ -8,10 +8,12 @@ public abstract class BaseRecognitionControlSettings(string cameraName) : ISetti
public int MinimumProcessingTime { get; set; }
public string RecipeNameFilter { get; set; } = "*";
public int ErrorsInSequenceAlarm { get; set; } = 5;
public virtual void RegisterSettings(InspectronSettings settings)
{
settings.RegisterSimple(this, () => this.MinimumProcessingTime, CameraName + "/Hawkeye recognition", "Minimum processing time (ms)");
settings.RegisterSimple(this, () => this.RecipeNameFilter, CameraName + "/Hawkeye recognition", nameof(RecipeNameFilter));
settings.RegisterSimple(this, () => this.ErrorsInSequenceAlarm, CameraName + "/Hawkeye recognition", nameof(ErrorsInSequenceAlarm));
}
}

View File

@@ -15,5 +15,6 @@ public interface IRecognitionControl
event Action<ImageProcessedEvent> ImageProcessed;
event Action<SessionStartedEvent> SessionStarted;
event Action<SessionEndedEvent> SessionEnded;
event Action<ErrorsInSequenceEvent> ErrorsInSequenceAlarm;
}

View File

@@ -123,19 +123,29 @@ namespace VisionBuilder.UI.Common
}
[RelayCommand(CanExecute = nameof(CanStart))]
public void Start()
public async Task Start()
{
_handlingEnabled = true;
_recognitionControl.Start();
IsRunning = true;
await Task.Run(() =>
{
_recognitionControl.Start();
});
_handlingEnabled = true;
}
[RelayCommand(CanExecute = nameof(CanStop))]
public void Stop()
public async Task Stop()
{
_handlingEnabled = false;
_recognitionControl.Stop();
await Task.Run(() =>
{
_recognitionControl.Stop();
});
IsPaused = false;
IsRunning = false;
}
[RelayCommand(CanExecute = nameof(IsResumed))]