Control serial port has not to be equal with scale serial port any more
This commit is contained in:
@ -11,6 +11,7 @@ namespace Elwig.Helpers.Weighing {
|
|||||||
protected enum Output { RTS, DTR, OUT1, OUT2 };
|
protected enum Output { RTS, DTR, OUT1, OUT2 };
|
||||||
|
|
||||||
protected SerialPort? Serial = null;
|
protected SerialPort? Serial = null;
|
||||||
|
protected SerialPort? ControlSerialEmpty = null, ControlSerialFilling = null;
|
||||||
protected TcpClient? Tcp = null;
|
protected TcpClient? Tcp = null;
|
||||||
protected Stream Stream;
|
protected Stream Stream;
|
||||||
|
|
||||||
@ -27,7 +28,7 @@ namespace Elwig.Helpers.Weighing {
|
|||||||
public int? WeightLimit { get; private set; }
|
public int? WeightLimit { get; private set; }
|
||||||
public string? LogPath { get; private set; }
|
public string? LogPath { get; private set; }
|
||||||
|
|
||||||
public SystecScale(string id, string model, string connection, string? empty = null, string? fill = null, int? limit = null, string? log = null) {
|
public SystecScale(string id, string model, string connection, string? empty = null, string? filling = null, int? limit = null, string? log = null) {
|
||||||
ScaleId = id;
|
ScaleId = id;
|
||||||
Model = model;
|
Model = model;
|
||||||
IsReady = true;
|
IsReady = true;
|
||||||
@ -46,11 +47,28 @@ namespace Elwig.Helpers.Weighing {
|
|||||||
|
|
||||||
if (empty != null) {
|
if (empty != null) {
|
||||||
var parts = empty.Split(':');
|
var parts = empty.Split(':');
|
||||||
EmptyMode = ConvertOutput(parts[0]);
|
if (parts.Length == 3) {
|
||||||
EmptyDelay = int.Parse(parts[1]);
|
if (parts[0] != Serial?.PortName)
|
||||||
|
ControlSerialEmpty = Utils.OpenSerialConnection($"serial://{parts[0]}:9600");
|
||||||
|
} else if (parts.Length != 2) {
|
||||||
|
throw new ArgumentException("Invalid value for 'empty'");
|
||||||
}
|
}
|
||||||
FillingClearanceMode = ConvertOutput(fill);
|
EmptyMode = ConvertOutput(parts[^2]);
|
||||||
|
EmptyDelay = int.Parse(parts[^1]);
|
||||||
|
}
|
||||||
|
|
||||||
WeightLimit = limit;
|
WeightLimit = limit;
|
||||||
|
if (filling != null) {
|
||||||
|
var parts = filling.Split(':');
|
||||||
|
if (parts.Length == 2) {
|
||||||
|
if (parts[0] != Serial?.PortName)
|
||||||
|
ControlSerialFilling = parts[0] != ControlSerialEmpty?.PortName ? Utils.OpenSerialConnection($"serial://{parts[0]}:9600") : ControlSerialEmpty;
|
||||||
|
} else if (parts.Length != 1) {
|
||||||
|
throw new ArgumentException("Invalid value for 'filling'");
|
||||||
|
}
|
||||||
|
FillingClearanceMode = ConvertOutput(parts[^1]);
|
||||||
|
}
|
||||||
|
|
||||||
if (FillingClearanceMode != null && WeightLimit == null)
|
if (FillingClearanceMode != null && WeightLimit == null)
|
||||||
throw new ArgumentException("Weight limit has to be set, if filling clearance supervision is enabled");
|
throw new ArgumentException("Weight limit has to be set, if filling clearance supervision is enabled");
|
||||||
}
|
}
|
||||||
@ -58,6 +76,8 @@ namespace Elwig.Helpers.Weighing {
|
|||||||
public void Dispose() {
|
public void Dispose() {
|
||||||
Stream.Close();
|
Stream.Close();
|
||||||
Serial?.Close();
|
Serial?.Close();
|
||||||
|
ControlSerialEmpty?.Close();
|
||||||
|
ControlSerialFilling?.Close();
|
||||||
Tcp?.Close();
|
Tcp?.Close();
|
||||||
GC.SuppressFinalize(this);
|
GC.SuppressFinalize(this);
|
||||||
}
|
}
|
||||||
@ -117,7 +137,7 @@ namespace Elwig.Helpers.Weighing {
|
|||||||
throw new IOException($"Invalid response from scale (error code {error})");
|
throw new IOException($"Invalid response from scale (error code {error})");
|
||||||
}
|
}
|
||||||
|
|
||||||
return line[1..(line.Length - 1)];
|
return line[1..^1];
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async Task<WeighingResult> Weigh(bool incIdentNr) {
|
protected async Task<WeighingResult> Weigh(bool incIdentNr) {
|
||||||
@ -164,14 +184,15 @@ namespace Elwig.Helpers.Weighing {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async Task Empty() {
|
public async Task Empty() {
|
||||||
if (EmptyMode == Output.RTS && Serial != null) {
|
SerialPort? p = ControlSerialEmpty ?? Serial;
|
||||||
Serial.RtsEnable = true;
|
if (EmptyMode == Output.RTS && p != null) {
|
||||||
|
p.RtsEnable = true;
|
||||||
await Task.Delay(EmptyDelay);
|
await Task.Delay(EmptyDelay);
|
||||||
Serial.RtsEnable = false;
|
p.RtsEnable = false;
|
||||||
} else if (EmptyMode == Output.DTR && Serial != null) {
|
} else if (EmptyMode == Output.DTR && p != null) {
|
||||||
Serial.DtrEnable = true;
|
p.DtrEnable = true;
|
||||||
await Task.Delay(EmptyDelay);
|
await Task.Delay(EmptyDelay);
|
||||||
Serial.DtrEnable = false;
|
p.DtrEnable = false;
|
||||||
} else if (EmptyMode == Output.OUT1 || EmptyMode == Output.OUT2) {
|
} else if (EmptyMode == Output.OUT1 || EmptyMode == Output.OUT2) {
|
||||||
int output = EmptyMode == Output.OUT1 ? 1 : 2;
|
int output = EmptyMode == Output.OUT1 ? 1 : 2;
|
||||||
await SendCommand($"OS{output:02i}");
|
await SendCommand($"OS{output:02i}");
|
||||||
@ -183,10 +204,11 @@ namespace Elwig.Helpers.Weighing {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected async Task SetFillingClearance(bool status) {
|
protected async Task SetFillingClearance(bool status) {
|
||||||
if (FillingClearanceMode == Output.RTS && Serial != null) {
|
SerialPort? p = ControlSerialFilling ?? Serial;
|
||||||
Serial.RtsEnable = status;
|
if (FillingClearanceMode == Output.RTS && p != null) {
|
||||||
} else if (FillingClearanceMode == Output.DTR && Serial != null) {
|
p.RtsEnable = status;
|
||||||
Serial.DtrEnable = status;
|
} else if (FillingClearanceMode == Output.DTR && p != null) {
|
||||||
|
p.DtrEnable = status;
|
||||||
} else if (FillingClearanceMode == Output.OUT1 || FillingClearanceMode == Output.OUT2) {
|
} else if (FillingClearanceMode == Output.OUT1 || FillingClearanceMode == Output.OUT2) {
|
||||||
string cmd = status ? "OS" : "OC";
|
string cmd = status ? "OS" : "OC";
|
||||||
int output = FillingClearanceMode == Output.OUT1 ? 1 : 2;
|
int output = FillingClearanceMode == Output.OUT1 ? 1 : 2;
|
||||||
|
@ -13,8 +13,11 @@ file = database.sqlite3
|
|||||||
;type = systec
|
;type = systec
|
||||||
;model = IT3000A
|
;model = IT3000A
|
||||||
;connection = serial://COM1:9600,8,N,1
|
;connection = serial://COM1:9600,8,N,1
|
||||||
;empty = RTS:1000
|
;empty = COM2:RTS:1000
|
||||||
;limit = 4000
|
;filling = DTR
|
||||||
|
; Limit on when the filling clearance should be removed
|
||||||
|
;limit = 3500
|
||||||
|
; Enables scale logging
|
||||||
;log = waage.log
|
;log = waage.log
|
||||||
|
|
||||||
;[scale.B]
|
;[scale.B]
|
||||||
@ -23,4 +26,5 @@ file = database.sqlite3
|
|||||||
;connection = tcp://10.0.0.1:1234
|
;connection = tcp://10.0.0.1:1234
|
||||||
;empty = OUT1:3000
|
;empty = OUT1:3000
|
||||||
;filling = OUT2
|
;filling = OUT2
|
||||||
|
; Limit on when the filling clearance should be removed
|
||||||
;limit = 3000
|
;limit = 3000
|
||||||
|
Reference in New Issue
Block a user