Weighing: Differentiate between scale and terminal
This commit is contained in:
@@ -8,15 +8,14 @@ namespace Elwig.Helpers.Weighing {
|
||||
public class SysTecITScale : Scale, ICommandScale {
|
||||
|
||||
public string Manufacturer => "SysTec";
|
||||
public int InternalScaleNr => 1;
|
||||
public string Model { get; private set; }
|
||||
public string ScaleId { get; private set; }
|
||||
public string ScaleTerminalId { get; private set; }
|
||||
public bool IsReady { get; private set; }
|
||||
public bool HasFillingClearance { get; private set; }
|
||||
|
||||
public SysTecITScale(string id, string model, string cnx, string? empty = null, string? filling = null, int? limit = null, string? log = null) :
|
||||
base(cnx, empty, filling, limit, log) {
|
||||
ScaleId = id;
|
||||
ScaleTerminalId = id;
|
||||
Model = model;
|
||||
IsReady = true;
|
||||
HasFillingClearance = false;
|
||||
@@ -74,15 +73,15 @@ namespace Elwig.Helpers.Weighing {
|
||||
return line[1..^3];
|
||||
}
|
||||
|
||||
protected async Task<WeighingResult> Weigh(bool incIdentNr, bool retry = true) {
|
||||
protected async Task<WeighingResult> Weigh(int internalScalNr, bool incIdentNr, bool retry = true) {
|
||||
string record;
|
||||
try {
|
||||
await SendCommand(incIdentNr ? $"RN{InternalScaleNr}" : $"RM{InternalScaleNr}");
|
||||
await SendCommand(incIdentNr ? $"RN{internalScalNr}" : $"RM{internalScalNr}");
|
||||
record = await ReceiveResponse();
|
||||
} catch (IOException) {
|
||||
if (!retry || Tcp == null) throw;
|
||||
ReconnectTcp();
|
||||
return await Weigh(incIdentNr, false);
|
||||
return await Weigh(internalScalNr, incIdentNr, false);
|
||||
}
|
||||
if (record.Length != 62)
|
||||
throw new FormatException("Invalid response from scale: Received record has invalid size");
|
||||
@@ -114,6 +113,7 @@ namespace Elwig.Helpers.Weighing {
|
||||
GrossWeight = int.Parse(brutto),
|
||||
TareWeight = int.Parse(tara),
|
||||
NetWeight = int.Parse(netto),
|
||||
ScaleId = scaleNr,
|
||||
WeighingId = identNr,
|
||||
FullWeighingId = identNr != null ? $"{parsedDate:yyyy-MM-dd}/{identNr}" : null,
|
||||
Date = parsedDate,
|
||||
@@ -121,12 +121,12 @@ namespace Elwig.Helpers.Weighing {
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<WeighingResult> Weigh() {
|
||||
return await Weigh(true);
|
||||
public async Task<WeighingResult> Weigh(int? scaleNr = 1) {
|
||||
return await Weigh(scaleNr ?? 1, true);
|
||||
}
|
||||
|
||||
public async Task<WeighingResult> GetCurrentWeight() {
|
||||
return await Weigh(false);
|
||||
public async Task<WeighingResult> GetCurrentWeight(int? scaleNr = 1) {
|
||||
return await Weigh(scaleNr ?? 1, false);
|
||||
}
|
||||
|
||||
public async Task Empty() {
|
||||
|
||||
Reference in New Issue
Block a user