[#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:
@@ -10,6 +10,7 @@ namespace Elwig.Helpers.Weighing {
|
||||
|
||||
protected enum Output { RTS, DTR, OUT1, OUT2 };
|
||||
|
||||
protected readonly string Connection;
|
||||
protected SerialPort? Serial = null;
|
||||
protected SerialPort? ControlSerialEmpty = null, ControlSerialFilling = null;
|
||||
protected TcpClient? Tcp = null;
|
||||
@@ -37,6 +38,7 @@ namespace Elwig.Helpers.Weighing {
|
||||
}
|
||||
|
||||
protected Scale(string cnx, string? empty, string? filling, int? limit, string? log, bool softFail = false, bool failSilent = false) {
|
||||
Connection = cnx;
|
||||
if (cnx.StartsWith("serial:")) {
|
||||
try {
|
||||
Serial = Utils.OpenSerialConnection(cnx);
|
||||
@@ -95,6 +97,14 @@ namespace Elwig.Helpers.Weighing {
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
protected void ReconnectTcp() {
|
||||
if (Connection.StartsWith("tcp:")) {
|
||||
Tcp = Utils.OpenTcpConnection(Connection);
|
||||
Stream = Tcp.GetStream();
|
||||
Reader = new(Stream, Encoding.ASCII, false, 512);
|
||||
}
|
||||
}
|
||||
|
||||
protected static Output? ConvertOutput(string? value) {
|
||||
return value switch {
|
||||
null => null,
|
||||
|
||||
Reference in New Issue
Block a user