Weighing: Add Gassner scale and update tests

This commit is contained in:
2024-04-13 18:00:17 +02:00
parent c6905bbb42
commit 443e111594
12 changed files with 626 additions and 21 deletions

View File

@ -31,12 +31,9 @@ namespace Elwig.Helpers.Weighing {
}
protected async Task<string> ReceiveResponse() {
string? line = null;
using (var reader = new StreamReader(Stream, Encoding.ASCII, false, -1, true)) {
line = await reader.ReadLineAsync();
if (LogPath != null) await File.AppendAllTextAsync(LogPath, $"{line}\r\n");
}
if (line == null || line.Length < 4 || !line.StartsWith('<') || !line.EndsWith('>')) {
var line = await Reader.ReadUntilAsync("\r\n");
if (LogPath != null) await File.AppendAllTextAsync(LogPath, line);
if (line == null || line.Length < 4 || !line.StartsWith('<') || !line.EndsWith(">\r\n")) {
throw new IOException("Invalid response from scale");
}
@ -68,7 +65,7 @@ namespace Elwig.Helpers.Weighing {
throw new IOException($"Invalid response from scale (error code {error})");
}
return line[1..^1];
return line[1..^3];
}
protected async Task<WeighingResult> Weigh(bool incIdentNr) {
@ -82,7 +79,7 @@ namespace Elwig.Helpers.Weighing {
var date = line[ 2..10];
var time = line[10..15];
var identNr = line[15..19].Trim();
var scaleNr = line[19..20];
var scaleNr = line[19..20].Trim();
var brutto = line[20..28].Trim();
var tara = line[28..36].Trim();
var netto = line[36..44].Trim();