Add weight limit to scale

This commit is contained in:
2023-04-26 19:17:35 +02:00
parent 0621716636
commit ee5bda2fe3
4 changed files with 15 additions and 3 deletions

View File

@ -47,8 +47,9 @@ namespace Elwig {
var cnx = s[3]; var cnx = s[3];
var empty = s[4]; var empty = s[4];
var filling = s[5]; var filling = s[5];
int? limit = s[6] == null ? null : int.Parse(s[6]);
if (type == "systec") { if (type == "systec") {
list.AddLast(new SystecScale(scaleNr, model, cnx, empty, filling)); list.AddLast(new SystecScale(scaleNr, model, cnx, empty, filling, limit));
} }
} catch (Exception e) { } catch (Exception e) {
MessageBox.Show($"Unable to create scale {s[0]}:\n\n{e.Message}", "Scale Error", MessageBoxButton.OK, MessageBoxImage.Error); MessageBox.Show($"Unable to create scale {s[0]}:\n\n{e.Message}", "Scale Error", MessageBoxButton.OK, MessageBoxImage.Error);

View File

@ -48,7 +48,8 @@ namespace Elwig.Helpers {
if (ini != null) { if (ini != null) {
foreach (var s in ini.Sections.Where(s => s.SectionName.StartsWith("scale."))) { foreach (var s in ini.Sections.Where(s => s.SectionName.StartsWith("scale."))) {
ScaleList.AddLast(new string[] { ScaleList.AddLast(new string[] {
s.SectionName[6..], s.Keys["type"], s.Keys["model"], s.Keys["connection"], s.Keys["empty"], s.Keys["filling"] s.SectionName[6..], s.Keys["type"], s.Keys["model"], s.Keys["connection"],
s.Keys["empty"], s.Keys["filling"], s.Keys["limit"]
}); });
} }
} }
@ -62,6 +63,7 @@ namespace Elwig.Helpers {
file.Write($"\r\n[scale.{s[0]}]\r\ntype = {s[1]}\r\nmodel = {s[2]}\r\nconnection = {s[3]}\r\n"); file.Write($"\r\n[scale.{s[0]}]\r\ntype = {s[1]}\r\nmodel = {s[2]}\r\nconnection = {s[3]}\r\n");
if (s[4] != null) file.Write($"empty = {s[4]}\r\n"); if (s[4] != null) file.Write($"empty = {s[4]}\r\n");
if (s[5] != null) file.Write($"filling = {s[5]}\r\n"); if (s[5] != null) file.Write($"filling = {s[5]}\r\n");
if (s[6] != null) file.Write($"limit = {s[6]}\r\n");
} }
} }
} }

View File

@ -36,6 +36,11 @@ namespace Elwig.Helpers.Weighing {
/// </summary> /// </summary>
bool HasFillingClearance { get; } bool HasFillingClearance { get; }
/// <summary>
/// The maximal configured weight limit of the scale in kg
/// </summary>
int? WeightLimit { get; }
/// <summary> /// <summary>
/// Get the current weight on the scale without performing a weighing process /// Get the current weight on the scale without performing a weighing process
/// </summary> /// </summary>

View File

@ -29,8 +29,9 @@ namespace Elwig.Helpers.Weighing {
public int ScaleNr { get; private set; } public int ScaleNr { get; private set; }
public bool IsReady { get; private set; } public bool IsReady { get; private set; }
public bool HasFillingClearance { get; private set; } public bool HasFillingClearance { get; private set; }
public int? WeightLimit { get; private set; }
public SystecScale(int scaleNr, string model, string connection, string? empty = null, string? fill = null) { public SystecScale(int scaleNr, string model, string connection, string? empty = null, string? fill = null, int? limit = null) {
ScaleNr = scaleNr; ScaleNr = scaleNr;
Model = model; Model = model;
IsReady = true; IsReady = true;
@ -81,6 +82,9 @@ namespace Elwig.Helpers.Weighing {
EmptyDelay = int.Parse(parts[1]); EmptyDelay = int.Parse(parts[1]);
} }
FillingClearanceMode = ConvertOutput(fill); FillingClearanceMode = ConvertOutput(fill);
WeightLimit = limit;
if (FillingClearanceMode != null && WeightLimit == null)
throw new ArgumentException("Weight limit has to be set, if filling clearance supervision is enalbed");
Writer = new(stream, Encoding.ASCII, -1, true); Writer = new(stream, Encoding.ASCII, -1, true);
Reader = new(stream, Encoding.ASCII, false, -1, true); Reader = new(stream, Encoding.ASCII, false, -1, true);