Compare commits

..

1 Commits

Author SHA1 Message Date
65544f6f29 Printing: Replace WinziPrint with iText
Some checks failed
Test / Run tests (push) Failing after 2m32s
2026-02-20 00:42:15 +01:00
3 changed files with 7 additions and 33 deletions

View File

@@ -53,16 +53,9 @@ namespace Elwig.Helpers.Weighing {
return line[1..^1];
}
protected async Task<WeighingResult> Weigh(bool incIdentNr, bool retry = true) {
string record;
try {
protected async Task<WeighingResult> Weigh(bool incIdentNr) {
await SendCommand(incIdentNr ? '\x05' : '?');
record = await ReceiveResponse();
} catch (IOException) {
if (!retry || Tcp == null) throw;
ReconnectTcp();
return await Weigh(incIdentNr, false);
}
string record = await ReceiveResponse();
if (record.Length != 45)
throw new FormatException("Invalid response from scale: Received record has invalid size");
var line = record[2..];

View File

@@ -10,7 +10,6 @@ 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;
@@ -38,7 +37,6 @@ 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);
@@ -97,14 +95,6 @@ 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,

View File

@@ -33,9 +33,7 @@ namespace Elwig.Helpers.Weighing {
protected async Task<string> ReceiveResponse() {
var line = await Reader.ReadUntilAsync("\r\n");
if (LogPath != null) await File.AppendAllTextAsync(LogPath, line);
if (line == null) {
throw new IOException("Verbindung zu Waage verloren");
} else if (line.Length < 4 || !line.StartsWith('<') || !line.EndsWith(">\r\n")) {
if (line == null || line.Length < 4 || !line.StartsWith('<') || !line.EndsWith(">\r\n")) {
throw new FormatException("Invalid response from scale");
}
@@ -74,16 +72,9 @@ namespace Elwig.Helpers.Weighing {
return line[1..^3];
}
protected async Task<WeighingResult> Weigh(bool incIdentNr, bool retry = true) {
string record;
try {
protected async Task<WeighingResult> Weigh(bool incIdentNr) {
await SendCommand(incIdentNr ? $"RN{InternalScaleNr}" : $"RM{InternalScaleNr}");
record = await ReceiveResponse();
} catch (IOException) {
if (!retry || Tcp == null) throw;
ReconnectTcp();
return await Weigh(incIdentNr, false);
}
string record = await ReceiveResponse();
if (record.Length != 62)
throw new FormatException("Invalid response from scale: Received record has invalid size");
var line = record[2..];