[#74] Weighing: Try to reconnect tcp scales on first error
All checks were successful
Test / Run tests (push) Successful in 3m0s
All checks were successful
Test / Run tests (push) Successful in 3m0s
This commit is contained in:
@@ -53,9 +53,16 @@ namespace Elwig.Helpers.Weighing {
|
||||
return line[1..^1];
|
||||
}
|
||||
|
||||
protected async Task<WeighingResult> Weigh(bool incIdentNr) {
|
||||
await SendCommand(incIdentNr ? '\x05' : '?');
|
||||
string record = await ReceiveResponse();
|
||||
protected async Task<WeighingResult> Weigh(bool incIdentNr, bool retry = true) {
|
||||
string record;
|
||||
try {
|
||||
await SendCommand(incIdentNr ? '\x05' : '?');
|
||||
record = await ReceiveResponse();
|
||||
} catch (IOException) {
|
||||
if (!retry || Tcp == null) throw;
|
||||
ReconnectTcp();
|
||||
return await Weigh(incIdentNr, false);
|
||||
}
|
||||
if (record.Length != 45)
|
||||
throw new FormatException("Invalid response from scale: Received record has invalid size");
|
||||
var line = record[2..];
|
||||
|
||||
Reference in New Issue
Block a user