1.0.6
This commit is contained in:
@@ -13,22 +13,23 @@ public class CandyboxBarcodeReader : IVisionBuilderModule
|
||||
private readonly ILoadingService _loadingService;
|
||||
|
||||
private readonly CandyboxBarcodeReaderSettings _settings;
|
||||
private readonly IRecognitionControl _recognitionControl;
|
||||
private readonly SingleCameraVM _singleCameraVm;
|
||||
private readonly VisionBuilderStatistics _statistics;
|
||||
private SerialPort _port;
|
||||
public EReaderState _readerState = EReaderState.ReadingRecipe;
|
||||
private MaterialCancellableLoader? _loader;
|
||||
|
||||
public CandyboxBarcodeReader(CandyboxBarcodeReaderSettings settings, IRecognitionControl recognitionControl, VisionBuilderStatistics statistics)
|
||||
public CandyboxBarcodeReader(CandyboxBarcodeReaderSettings settings, SingleCameraVM singleCameraVm, VisionBuilderStatistics statistics)
|
||||
{
|
||||
_settings = settings;
|
||||
_recognitionControl = recognitionControl;
|
||||
_singleCameraVm = singleCameraVm;
|
||||
_statistics = statistics;
|
||||
}
|
||||
|
||||
private void _port_DataReceived(object sender, SerialDataReceivedEventArgs e)
|
||||
{
|
||||
Thread.Sleep(100);
|
||||
Thread.Sleep(500);
|
||||
if(_singleCameraVm.IsRunning)return;
|
||||
if(_readerState == EReaderState.ReadingRecipe)
|
||||
ReadRecipe();
|
||||
if (_readerState == EReaderState.ReadingAUF)
|
||||
@@ -37,14 +38,21 @@ public class CandyboxBarcodeReader : IVisionBuilderModule
|
||||
|
||||
private void ReadRecipe()
|
||||
{
|
||||
if (_recognitionControl.IsRunning) return;
|
||||
if (_singleCameraVm.IsRunning) return;
|
||||
|
||||
byte[] buffer = new byte[_port.BytesToRead];
|
||||
_port.Read(buffer, 0, _port.BytesToRead);
|
||||
var data = Encoding.ASCII.GetString(buffer).Trim();
|
||||
var recipes = _recognitionControl.GetRecipesData();
|
||||
if (string.IsNullOrEmpty(data))
|
||||
{
|
||||
Log.Warning("Received empty recipe");
|
||||
return;
|
||||
}
|
||||
var vm = _singleCameraVm.GetRecipeSelectionVm();
|
||||
var recipes = vm.Recipes;
|
||||
|
||||
string searchString = data;
|
||||
Log.Information("Read Recipe: {Recipe}", data);
|
||||
if (_settings.BarcodeRecipeMappings.Any(x => x.Barcode == searchString))
|
||||
{
|
||||
searchString = _settings.BarcodeRecipeMappings.First(x => x.Barcode == searchString).RecipeName;
|
||||
@@ -56,20 +64,29 @@ public class CandyboxBarcodeReader : IVisionBuilderModule
|
||||
Log.Warning("No matching recipe found for data: {Data}", data);
|
||||
return;
|
||||
}
|
||||
|
||||
_recognitionControl.SetRecipe(existingRecipe);
|
||||
vm.SelectedRecipe = vm.Recipes.FirstOrDefault(r => r.RecipeName == existingRecipe.RecipeName);
|
||||
_singleCameraVm.SynchronizationContext!.Post((_) =>
|
||||
{
|
||||
_loader = new MaterialCancellableLoader();
|
||||
_loader.StartLoading("Waiting for AUF...");
|
||||
_loader.LoadingCancelled += CancelWaiting;
|
||||
_singleCameraVm.ProcessRecipeSelectionVm(vm);
|
||||
}, null);
|
||||
Application.DoEvents();
|
||||
_readerState = EReaderState.ReadingAUF;
|
||||
_loader = new MaterialCancellableLoader();
|
||||
_loader.StartLoading("Waiting for AUF...");
|
||||
_loader.LoadingCancelled += CancelWaiting;
|
||||
|
||||
}
|
||||
|
||||
private void CancelWaiting(object? sender, string e)
|
||||
{
|
||||
_singleCameraVm.SynchronizationContext!.Post((_) =>
|
||||
{
|
||||
_loader.FinishLoading("Waiting for AUF...");
|
||||
_loader.LoadingCancelled -= CancelWaiting;
|
||||
_loader = null;
|
||||
}, null);
|
||||
_readerState = EReaderState.ReadingRecipe;
|
||||
_loader.Close();
|
||||
_loader.LoadingCancelled -= CancelWaiting;
|
||||
_loader = null;
|
||||
|
||||
}
|
||||
|
||||
private void ReadAUF()
|
||||
@@ -77,17 +94,22 @@ public class CandyboxBarcodeReader : IVisionBuilderModule
|
||||
byte[] buffer = new byte[_port.BytesToRead];
|
||||
_port.Read(buffer, 0, _port.BytesToRead);
|
||||
var data = Encoding.ASCII.GetString(buffer).Trim();
|
||||
if (string.IsNullOrEmpty(data))
|
||||
{
|
||||
Log.Warning("Received empty AUF");
|
||||
return;
|
||||
}
|
||||
Log.Information("Read AUF: {AUF}", data);
|
||||
if (_loader != null)
|
||||
{
|
||||
_loader.Close();
|
||||
_loader.LoadingCancelled -= CancelWaiting;
|
||||
_loader = null;
|
||||
CancelWaiting(this, string.Empty);
|
||||
}
|
||||
|
||||
|
||||
_statistics.Metadata = data;
|
||||
_recognitionControl.Start();
|
||||
_readerState = EReaderState.ReadingAUF;
|
||||
_=_singleCameraVm.Start().ConfigureAwait(false);
|
||||
Application.DoEvents();
|
||||
_readerState = EReaderState.ReadingRecipe;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user