105 lines
3.7 KiB
C#
105 lines
3.7 KiB
C#
namespace Tests.WeighingTests {
|
|
public static class ScaleHandlers {
|
|
|
|
public static (string, bool) Handle_IT3000A(string req, int weight, string? error, int identNr) {
|
|
var modes = error?.Split(';') ?? [];
|
|
var overloaded = modes.Contains("overloaded");
|
|
var moving = modes.Contains("moving");
|
|
var invalid = modes.Contains("invalid");
|
|
var crc = modes.Contains("crc");
|
|
var unit = modes.Contains("unit");
|
|
|
|
Thread.Sleep(100);
|
|
|
|
if (invalid) {
|
|
return ("abcd\r\n", false);
|
|
} else if (!req.StartsWith('<') || !req.EndsWith('>')) {
|
|
return ("<31>\r\n", false);
|
|
}
|
|
req = req[1..^1];
|
|
|
|
bool incr;
|
|
if (req.Length > 3) {
|
|
return ("<32>\r\n", false);
|
|
} else if (req.StartsWith("RN")) {
|
|
incr = true;
|
|
} else if (req.StartsWith("RM")) {
|
|
incr = false;
|
|
} else {
|
|
return ("<32>\r\n", false);
|
|
}
|
|
|
|
if (overloaded) {
|
|
return ("<12>\r\n", false);
|
|
} else if (weight == 0) {
|
|
incr = false;
|
|
}
|
|
|
|
if (moving && incr)
|
|
return ("<13>\r\n", false);
|
|
|
|
string data = $"00{(moving ? 1 : 0)}0{new DateTime(2020, 10, 15, 12, 34, 0):dd.MM.yyHH:mm}{(incr ? identNr : 0),4}1" +
|
|
$"{weight,8}{0,8}{weight,8}{(unit ? "lb" : "kg")} {"1",3}";
|
|
ushort checksum = Elwig.Helpers.Utils.CalcCrc16Modbus(data);
|
|
if (crc) checksum += 10;
|
|
return ($"<{data}{checksum,8}>\r\n", incr);
|
|
}
|
|
|
|
public static (string, bool) Handle_L246(string req, int weight, string? error, int identNr) {
|
|
var modes = error?.Split(';') ?? [];
|
|
var overloaded = modes.Contains("overloaded");
|
|
var moving = modes.Contains("moving");
|
|
var invalid = modes.Contains("invalid");
|
|
var crc = modes.Contains("crc");
|
|
var unit = modes.Contains("unit");
|
|
|
|
Thread.Sleep(100);
|
|
|
|
if (invalid) {
|
|
return ("abcd\r\n", false);
|
|
} else if (!req.StartsWith('<') || !req.EndsWith('>')) {
|
|
return ("<31>\r\n", false);
|
|
}
|
|
req = req[1..^1];
|
|
|
|
bool incr;
|
|
if (req.Length > 3) {
|
|
return ("<32>\r\n", false);
|
|
} else if (req.StartsWith("RN")) {
|
|
incr = true;
|
|
} else if (req.StartsWith("RM")) {
|
|
incr = false;
|
|
} else {
|
|
return ("<32>\r\n", false);
|
|
}
|
|
|
|
if (overloaded)
|
|
return ("<12>\r\n", false);
|
|
|
|
if (moving && incr)
|
|
return ("<13>\r\n", false);
|
|
|
|
string data = $"00{(moving ? 1 : 0)}0{new DateTime(2020, 10, 17, 14, 23, 0):dd.MM.yyHH:mm}{(incr ? identNr : 0),4}1" +
|
|
$"{weight,8}{0,8}{weight,8}{(unit ? "lb" : "kg")} {"001",3}";
|
|
ushort checksum = Elwig.Helpers.Utils.CalcCrc16Modbus(data);
|
|
if (crc) checksum += 10;
|
|
return ($"<{data}{checksum,8}>\r\n", incr);
|
|
}
|
|
|
|
public static (string, bool) Handle_L320(int weight, string? error, int identNr) {
|
|
var modes = error?.Split(';') ?? [];
|
|
var invalid = modes.Contains("invalid");
|
|
var unit = modes.Contains("unit");
|
|
|
|
Thread.Sleep(100);
|
|
|
|
if (invalid) {
|
|
return ("abcd\r\n", 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);
|
|
}
|
|
}
|
|
}
|