Weighing: Add ICommandScale and IEventScale

This commit is contained in:
2024-02-10 18:43:45 +01:00
parent 68f1a2c091
commit 9ecad6aa79
8 changed files with 58 additions and 82 deletions

View File

@ -0,0 +1,35 @@
using System.Threading.Tasks;
namespace Elwig.Helpers.Weighing {
/// <summary>
/// Interface for controlling a a scale which responds to commands sent to it
/// </summary>
public interface ICommandScale : IScale {
/// <summary>
/// Get the current weight on the scale without performing a weighing process
/// </summary>
/// <returns>Result of the weighing process (probably without a weighing id)</returns>
Task<WeighingResult> GetCurrentWeight();
/// <summary>
/// Perform a weighing process
/// </summary>
/// <returns>Result of the weighing process (including a weighing id)</returns>
Task<WeighingResult> Weigh();
/// <summary>
/// Empty the scale container or grant clearance to do so
/// </summary>
Task Empty();
/// <summary>
/// Grant clearance to fill the scale container
/// </summary>
Task GrantFillingClearance();
/// <summary>
/// Revoke clearance to fill the scale container
/// </summary>
Task RevokeFillingClearance();
}
}

View File

@ -0,0 +1,8 @@
namespace Elwig.Helpers.Weighing {
/// <summary>
/// Interface for controlling a a scale which automatically sends weighing updates
/// </summary>
public interface IEventScale : IScale {
}
}

View File

@ -1,9 +1,8 @@
using System;
using System.Threading.Tasks;
namespace Elwig.Helpers.Weighing {
/// <summary>
/// Interface for controlling a industrial scale
/// Interface for controlling a industrial scale (industrial terminal, "IT")
/// </summary>
public interface IScale : IDisposable {
/// <summary>
@ -45,32 +44,5 @@ namespace Elwig.Helpers.Weighing {
/// Where to log the requests and responses from the scale to
/// </summary>
string? LogPath { get; }
/// <summary>
/// Get the current weight on the scale without performing a weighing process
/// </summary>
/// <returns>Result of the weighing process (probably without a weighing id)</returns>
Task<WeighingResult> GetCurrentWeight();
/// <summary>
/// Perform a weighing process
/// </summary>
/// <returns>Result of the weighing process (including a weighing id)</returns>
Task<WeighingResult> Weigh();
/// <summary>
/// Empty the scale container or grant clearance to do so
/// </summary>
Task Empty();
/// <summary>
/// Grant clearance to fill the scale container
/// </summary>
Task GrantFillingClearance();
/// <summary>
/// Revoke clearance to fill the scale container
/// </summary>
Task RevokeFillingClearance();
}
}

View File

@ -1,44 +1,19 @@
using System;
using System.Threading.Tasks;
namespace Elwig.Helpers.Weighing {
public class InvalidScale : IScale {
public class InvalidScale(string id) : IScale {
public string Manufacturer => "NONE";
public string Model => "NONE";
public string ScaleId { get; private set; }
public string ScaleId => id;
public int InternalScaleNr => 0;
public bool IsReady => false;
public bool HasFillingClearance => false;
public int? WeightLimit => null;
public string? LogPath => null;
public InvalidScale(string id) {
ScaleId = id;
}
public void Dispose() {
GC.SuppressFinalize(this);
}
public Task<WeighingResult> Weigh() {
throw new NotImplementedException();
}
public Task<WeighingResult> GetCurrentWeight() {
throw new NotImplementedException();
}
public Task Empty() {
throw new NotImplementedException();
}
public Task GrantFillingClearance() {
throw new NotImplementedException();
}
public Task RevokeFillingClearance() {
throw new NotImplementedException();
}
}
}

View File

@ -1,9 +1,7 @@
using System;
using System.Threading.Tasks;
namespace Elwig.Helpers.Weighing {
// TODO implement SchemberScale
public class SchemberScale : IScale {
public class SchemberScale : IEventScale {
public string Manufacturer => "Schember";
public string Model => throw new NotImplementedException();
@ -18,24 +16,7 @@ namespace Elwig.Helpers.Weighing {
throw new NotImplementedException();
}
public Task Empty() {
throw new NotImplementedException();
}
public Task<WeighingResult> GetCurrentWeight() {
throw new NotImplementedException();
}
public Task GrantFillingClearance() {
throw new NotImplementedException();
}
public Task RevokeFillingClearance() {
throw new NotImplementedException();
}
public Task<WeighingResult> Weigh() {
throw new NotImplementedException();
}
}
}

View File

@ -6,7 +6,7 @@ using System.Text;
using System.Threading.Tasks;
namespace Elwig.Helpers.Weighing {
public class SystecScale : IScale {
public class SystecScale : ICommandScale {
protected enum Output { RTS, DTR, OUT1, OUT2 };

View File

@ -1,6 +1,7 @@
using Elwig.Documents;
using Elwig.Helpers;
using Elwig.Helpers.Export;
using Elwig.Helpers.Weighing;
using Elwig.Models.Entities;
using LinqKit;
using Microsoft.EntityFrameworkCore;
@ -968,7 +969,8 @@ namespace Elwig.Windows {
CancelCreatingButton.IsEnabled = false;
try {
var s = App.Scales[index];
var res = await s.Weigh();
if (s is not ICommandScale cs) return;
var res = await cs.Weigh();
if ((res.Weight ?? 0) > 0 && res.FullWeighingId != null) {
WeightInput.Text = $"{res.Weight:N0}";
ScaleId = s.ScaleId;
@ -1080,8 +1082,8 @@ namespace Elwig.Windows {
private void EmptyScale() {
var scale = App.Scales.Where(s => s.ScaleId == ScaleId).FirstOrDefault();
if (scale == null) return;
scale.Empty();
if (scale is not ICommandScale cs) return;
cs.Empty();
}
private async void NewDeliveryPartButton_Click(object sender, RoutedEventArgs evt) {

View File

@ -2,6 +2,7 @@ using Elwig.Documents;
using Elwig.Helpers;
using Elwig.Helpers.Billing;
using Elwig.Helpers.Export;
using Elwig.Helpers.Weighing;
using Elwig.Models.Dtos;
using Microsoft.EntityFrameworkCore;
using System;
@ -27,7 +28,8 @@ namespace Elwig.Windows {
private async void WeighingButton1_Click(object sender, RoutedEventArgs evt) {
try {
var res = await App.Scales[0].GetCurrentWeight();
if (App.Scales[0] is not ICommandScale cs) return;
var res = await cs.GetCurrentWeight();
Output.Text = res.ToString();
} catch (Exception e) {
MessageBox.Show($"Beim Wiegen ist ein Fehler aufgetreten:\n\n{e.Message}", "Waagenfehler",
@ -37,7 +39,8 @@ namespace Elwig.Windows {
private async void WeighingButton2_Click(object sender, RoutedEventArgs evt) {
try {
var res = await App.Scales[0].Weigh();
if (App.Scales[0] is not ICommandScale cs) return;
var res = await cs.Weigh();
Output.Text = res.ToString();
} catch (Exception e) {
MessageBox.Show($"Beim Wiegen ist ein Fehler aufgetreten:\n\n{e.Message}", "Waagenfehler",