[#71] Weighing: Fix reconnection behaviour when COM port is connected/disconnected
All checks were successful
Test / Run tests (push) Successful in 1m52s
All checks were successful
Test / Run tests (push) Successful in 1m52s
This commit is contained in:
@@ -36,7 +36,7 @@ namespace Elwig.Helpers.Weighing {
|
||||
var line = await Reader.ReadUntilAsync('\x03');
|
||||
if (LogPath != null) await File.AppendAllTextAsync(LogPath, $"{line}\r\n");
|
||||
if (line == null || line.Length < 4 || !line.StartsWith('\x02')) {
|
||||
throw new IOException("Invalid response from scale");
|
||||
throw new FormatException("Invalid response from scale");
|
||||
}
|
||||
|
||||
var status = line[1..3];
|
||||
@@ -45,9 +45,9 @@ namespace Elwig.Helpers.Weighing {
|
||||
switch (status[1]) {
|
||||
case 'M': msg = "Waage in Bewegung"; break;
|
||||
}
|
||||
throw new IOException($"Waagenfehler {status}: {msg}");
|
||||
throw new WeighingException($"Waagenfehler {status}: {msg}");
|
||||
} else if (status[0] != ' ') {
|
||||
throw new IOException($"Invalid response from scale (error code {status})");
|
||||
throw new WeighingException($"Invalid response from scale (error code {status})");
|
||||
}
|
||||
|
||||
return line[1..^1];
|
||||
@@ -57,7 +57,7 @@ namespace Elwig.Helpers.Weighing {
|
||||
await SendCommand(incIdentNr ? '\x05' : '?');
|
||||
string record = await ReceiveResponse();
|
||||
if (record.Length != 45)
|
||||
throw new IOException("Invalid response from scale: Received record has invalid size");
|
||||
throw new FormatException("Invalid response from scale: Received record has invalid size");
|
||||
var line = record[2..];
|
||||
|
||||
var brutto = line[ 0.. 7].Trim();
|
||||
|
||||
Reference in New Issue
Block a user