Update DeliveryAdminWindow

This commit is contained in:
2023-08-14 20:09:53 +02:00
parent f8af155c60
commit 99a6f53307
5 changed files with 149 additions and 78 deletions

View File

@ -161,16 +161,19 @@ namespace Elwig.Helpers.Weighing {
var terminalNr = line[49..52].Trim();
var crc16 = line[52..60].Trim();
if (Utils.CalcCrc16Modbus(record[..54]).ToString() != crc16) {
if (Utils.CalcCrc16Modbus(record[..54]) != ushort.Parse(crc16)) {
throw new IOException($"Invalid response from scale: Invalid CRC16 checksum ({crc16} != {Utils.CalcCrc16Modbus(record[..54]).ToString()})");
} else if (unit != "kg") {
throw new IOException($"Unsupported unit in weighing response: '{unit}'");
}
identNr = identNr.Length > 0 && identNr != "0" ? identNr : null;
var parsedDate = DateOnly.Parse(date);
return new() {
Weight = int.TryParse(netto, out int w) ? w : null,
WeighingId = identNr.Length > 0 && identNr != "0" ? identNr : null,
Date = DateOnly.Parse(date),
Weight = int.Parse(netto),
WeighingId = identNr,
FullWeighingId = identNr != null ? $"{parsedDate:yyyy-MM-dd}/{identNr}" : null,
Date = parsedDate,
Time = TimeOnly.Parse(time),
};
}
@ -195,10 +198,10 @@ namespace Elwig.Helpers.Weighing {
p.DtrEnable = false;
} else if (EmptyMode == Output.OUT1 || EmptyMode == Output.OUT2) {
int output = EmptyMode == Output.OUT1 ? 1 : 2;
await SendCommand($"OS{output:02i}");
await SendCommand($"OS{output:00}");
await ReceiveResponse();
await Task.Delay(EmptyDelay);
await SendCommand($"OC{output:02i}");
await SendCommand($"OC{output:00}");
await ReceiveResponse();
}
}
@ -212,7 +215,7 @@ namespace Elwig.Helpers.Weighing {
} else if (FillingClearanceMode == Output.OUT1 || FillingClearanceMode == Output.OUT2) {
string cmd = status ? "OS" : "OC";
int output = FillingClearanceMode == Output.OUT1 ? 1 : 2;
await SendCommand($"{cmd}{output:02i}");
await SendCommand($"{cmd}{output:00}");
await ReceiveResponse();
}
}