Weighing: Fix scale L320 for Baden
This commit is contained in:
@ -183,6 +183,9 @@ namespace Elwig {
|
||||
}
|
||||
|
||||
private async void Application_Exit(object sender, ExitEventArgs evt) {
|
||||
foreach (var s in EventScales) {
|
||||
s.Dispose();
|
||||
}
|
||||
await Pdf.Cleanup();
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,7 @@ namespace Elwig.Helpers {
|
||||
}
|
||||
|
||||
public static string? ReadUntil(this StreamReader reader, char delimiter) {
|
||||
return ReadUntil(reader, new char[] { delimiter });
|
||||
return ReadUntil(reader, [ delimiter ]);
|
||||
}
|
||||
|
||||
public static string? ReadUntil(this StreamReader reader, char[] delimiter) {
|
||||
@ -45,7 +45,7 @@ namespace Elwig.Helpers {
|
||||
}
|
||||
|
||||
public static Task<string?> ReadUntilAsync(this StreamReader reader, char delimiter) {
|
||||
return ReadUntilAsync(reader, new char[] { delimiter });
|
||||
return ReadUntilAsync(reader, [ delimiter ]);
|
||||
}
|
||||
|
||||
public static async Task<string?> ReadUntilAsync(this StreamReader reader, char[] delimiter) {
|
||||
|
@ -58,11 +58,19 @@ namespace Elwig.Helpers.Weighing {
|
||||
}
|
||||
|
||||
protected async Task<WeighingResult?> Receive() {
|
||||
var line = await Reader.ReadUntilAsync("\r\n");
|
||||
var line = "";
|
||||
while (line.Length < 33) {
|
||||
var ch = Reader.Read();
|
||||
if (ch == -1) {
|
||||
return null;
|
||||
} else if (line.Length > 0 || ch == ' ') {
|
||||
line += char.ToString((char)ch);
|
||||
}
|
||||
}
|
||||
if (LogPath != null) await File.AppendAllTextAsync(LogPath, line);
|
||||
if (line == null || line == "") {
|
||||
return null;
|
||||
} else if (line.Length != 35 || line[0] != ' ' || line[9] != ' ' || line[15] != ' ' || line[20] != ' ' || line[32] != ' ') {
|
||||
} else if (line.Length != 33 || line[0] != ' ' || line[9] != ' ' || line[15] != ' ' || line[20] != ' ' || line[32] != ' ') {
|
||||
throw new IOException($"Invalid event from scale: '{line}'");
|
||||
}
|
||||
|
||||
|
@ -171,11 +171,11 @@ namespace Tests.WeighingTests {
|
||||
Thread.Sleep(100);
|
||||
|
||||
if (invalid) {
|
||||
return ("abcd\r\n", false);
|
||||
return ("abcd", false);
|
||||
}
|
||||
|
||||
bool incr = true;
|
||||
return ($" {new DateTime(2020, 9, 28, 9, 8, 0):dd.MM.yy HH:mm} {identNr,4} {weight,9}{(unit ? "lb" : "kg")} \r\n", incr);
|
||||
return ($" {new DateTime(2020, 9, 28, 9, 8, 0):dd.MM.yy HH:mm} {identNr,4} {weight,9}{(unit ? "lb" : "kg")} ", incr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user