Fixes in Scales
This commit is contained in:
@ -74,14 +74,15 @@ namespace Elwig {
|
|||||||
foreach (var s in Config.Scales) {
|
foreach (var s in Config.Scales) {
|
||||||
try {
|
try {
|
||||||
var id = s[0];
|
var id = s[0];
|
||||||
var type = s[1].ToLower();
|
var type = s[1]?.ToLower();
|
||||||
var model = s[2];
|
var model = s[2];
|
||||||
var cnx = s[3];
|
var cnx = s[3];
|
||||||
var empty = s[4];
|
var empty = s[4];
|
||||||
var filling = s[5];
|
var filling = s[5];
|
||||||
int? limit = s[6] == null ? null : int.Parse(s[6]);
|
int? limit = s[6] == null ? null : int.Parse(s[6]);
|
||||||
|
var log = s[7];
|
||||||
if (type == "systec") {
|
if (type == "systec") {
|
||||||
list.Add(new SystecScale(id, model, cnx, empty, filling, limit));
|
list.Add(new SystecScale(id, model, cnx, empty, filling, limit, log));
|
||||||
} else {
|
} else {
|
||||||
throw new ArgumentException($"Invalid scale type: \"{type}\"");
|
throw new ArgumentException($"Invalid scale type: \"{type}\"");
|
||||||
}
|
}
|
||||||
|
@ -12,8 +12,8 @@ namespace Elwig.Helpers {
|
|||||||
public string DatabaseFile = App.DataPath + "database.sqlite3";
|
public string DatabaseFile = App.DataPath + "database.sqlite3";
|
||||||
public string? DatabaseLog = null;
|
public string? DatabaseLog = null;
|
||||||
public string? Branch = null;
|
public string? Branch = null;
|
||||||
public IEnumerable<string[]> Scales;
|
public IList<string?[]> Scales;
|
||||||
private readonly LinkedList<string[]> ScaleList = new();
|
private readonly List<string?[]> ScaleList = new();
|
||||||
|
|
||||||
public Config(string filename) {
|
public Config(string filename) {
|
||||||
FileName = filename;
|
FileName = filename;
|
||||||
@ -54,9 +54,16 @@ namespace Elwig.Helpers {
|
|||||||
Scales = ScaleList;
|
Scales = ScaleList;
|
||||||
if (ini != null) {
|
if (ini != null) {
|
||||||
foreach (var s in ini.Sections.Where(s => s.SectionName.StartsWith("scale."))) {
|
foreach (var s in ini.Sections.Where(s => s.SectionName.StartsWith("scale."))) {
|
||||||
ScaleList.AddLast(new string[] {
|
string? scaleLog = null;
|
||||||
|
if (s.Keys["log"] != null) {
|
||||||
|
scaleLog = s.Keys["log"];
|
||||||
|
if (scaleLog.Length <= 1 || (scaleLog[1] != ':' && scaleLog[0] != '/' && scaleLog[0] != '\\')) {
|
||||||
|
scaleLog = App.DataPath + scaleLog;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ScaleList.Add(new string?[] {
|
||||||
s.SectionName[6..], s.Keys["type"], s.Keys["model"], s.Keys["connection"],
|
s.SectionName[6..], s.Keys["type"], s.Keys["model"], s.Keys["connection"],
|
||||||
s.Keys["empty"], s.Keys["filling"], s.Keys["limit"]
|
s.Keys["empty"], s.Keys["filling"], s.Keys["limit"], scaleLog
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -64,6 +71,8 @@ namespace Elwig.Helpers {
|
|||||||
|
|
||||||
public void Write() {
|
public void Write() {
|
||||||
using var file = new StreamWriter(FileName, false, Encoding.UTF8);
|
using var file = new StreamWriter(FileName, false, Encoding.UTF8);
|
||||||
|
file.Write($"\r\n[general]\r\n");
|
||||||
|
if (Branch != null) file.Write($"branch = {Branch}\r\n");
|
||||||
file.Write($"\r\n[database]\r\nfile = {DatabaseFile}\r\n");
|
file.Write($"\r\n[database]\r\nfile = {DatabaseFile}\r\n");
|
||||||
if (DatabaseLog != null) file.Write($"log = {DatabaseLog}\r\n");
|
if (DatabaseLog != null) file.Write($"log = {DatabaseLog}\r\n");
|
||||||
foreach (var s in ScaleList) {
|
foreach (var s in ScaleList) {
|
||||||
@ -71,6 +80,7 @@ namespace Elwig.Helpers {
|
|||||||
if (s[4] != null) file.Write($"empty = {s[4]}\r\n");
|
if (s[4] != null) file.Write($"empty = {s[4]}\r\n");
|
||||||
if (s[5] != null) file.Write($"filling = {s[5]}\r\n");
|
if (s[5] != null) file.Write($"filling = {s[5]}\r\n");
|
||||||
if (s[6] != null) file.Write($"limit = {s[6]}\r\n");
|
if (s[6] != null) file.Write($"limit = {s[6]}\r\n");
|
||||||
|
if (s[7] != null) file.Write($"log = {s[7]}\r\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@ namespace Elwig.Helpers.Weighing {
|
|||||||
public bool IsReady { get; private set; }
|
public bool IsReady { get; private set; }
|
||||||
public bool HasFillingClearance { get; private set; }
|
public bool HasFillingClearance { get; private set; }
|
||||||
public int? WeightLimit { get; private set; }
|
public int? WeightLimit { get; private set; }
|
||||||
|
public string? LogPath { get; private set; }
|
||||||
|
|
||||||
public GassnerScale(string id, string model, string connection) {
|
public GassnerScale(string id, string model, string connection) {
|
||||||
ScaleId = id;
|
ScaleId = id;
|
||||||
|
@ -41,6 +41,11 @@ namespace Elwig.Helpers.Weighing {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
int? WeightLimit { get; }
|
int? WeightLimit { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Where to log the requests and responses from the scale to
|
||||||
|
/// </summary>
|
||||||
|
string? LogPath { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get the current weight on the scale without performing a weighing process
|
/// Get the current weight on the scale without performing a weighing process
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -12,6 +12,7 @@ namespace Elwig.Helpers.Weighing {
|
|||||||
public bool IsReady => throw new NotImplementedException();
|
public bool IsReady => throw new NotImplementedException();
|
||||||
public bool HasFillingClearance => throw new NotImplementedException();
|
public bool HasFillingClearance => throw new NotImplementedException();
|
||||||
public int? WeightLimit => throw new NotImplementedException();
|
public int? WeightLimit => throw new NotImplementedException();
|
||||||
|
public string? LogPath => throw new NotImplementedException();
|
||||||
|
|
||||||
public void Dispose() {
|
public void Dispose() {
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
|
@ -4,6 +4,7 @@ using System.IO.Ports;
|
|||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Shapes;
|
||||||
|
|
||||||
namespace Elwig.Helpers.Weighing {
|
namespace Elwig.Helpers.Weighing {
|
||||||
public class SystecScale : IScale {
|
public class SystecScale : IScale {
|
||||||
@ -25,12 +26,14 @@ namespace Elwig.Helpers.Weighing {
|
|||||||
public bool IsReady { get; private set; }
|
public bool IsReady { get; private set; }
|
||||||
public bool HasFillingClearance { get; private set; }
|
public bool HasFillingClearance { get; private set; }
|
||||||
public int? WeightLimit { get; private set; }
|
public int? WeightLimit { 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) {
|
public SystecScale(string id, string model, string connection, string? empty = null, string? fill = null, int? limit = null, string? log = null) {
|
||||||
ScaleId = id;
|
ScaleId = id;
|
||||||
Model = model;
|
Model = model;
|
||||||
IsReady = true;
|
IsReady = true;
|
||||||
HasFillingClearance = false;
|
HasFillingClearance = false;
|
||||||
|
LogPath = log;
|
||||||
|
|
||||||
if (connection.StartsWith("serial:")) {
|
if (connection.StartsWith("serial:")) {
|
||||||
Serial = Utils.OpenSerialConnection(connection);
|
Serial = Utils.OpenSerialConnection(connection);
|
||||||
@ -61,29 +64,27 @@ namespace Elwig.Helpers.Weighing {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected static Output? ConvertOutput(string? value) {
|
protected static Output? ConvertOutput(string? value) {
|
||||||
if (value == null) return null;
|
return value switch {
|
||||||
value = value.ToUpper();
|
null => null,
|
||||||
if (value == "RTS") {
|
"RTS" => Output.RTS,
|
||||||
return Output.RTS;
|
"DTR" => Output.DTR,
|
||||||
} else if (value == "DTR") {
|
"OUT1" => Output.OUT1,
|
||||||
return Output.DTR;
|
"OUT2" => Output.OUT2,
|
||||||
} else if (value == "OUT1") {
|
_ => throw new ArgumentException($"Invalid value for argument: '{value}'"),
|
||||||
return Output.OUT1;
|
};
|
||||||
} else if (value == "OUT2") {
|
|
||||||
return Output.OUT2;
|
|
||||||
}
|
|
||||||
throw new ArgumentException("Invalid value for argument empty");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async Task SendCommand(string command) {
|
protected async Task SendCommand(string command) {
|
||||||
byte[] bytes = Encoding.ASCII.GetBytes($"<{command}>");
|
byte[] bytes = Encoding.ASCII.GetBytes($"<{command}>");
|
||||||
await Stream.WriteAsync(bytes);
|
await Stream.WriteAsync(bytes);
|
||||||
|
if (LogPath != null) await File.AppendAllTextAsync(LogPath, $"<{command}>");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async Task<string> ReceiveResponse() {
|
protected async Task<string> ReceiveResponse() {
|
||||||
string? line = null;
|
string? line = null;
|
||||||
using (var reader = new StreamReader(Stream, Encoding.ASCII, false, -1, true)) {
|
using (var reader = new StreamReader(Stream, Encoding.ASCII, false, -1, true)) {
|
||||||
line = await reader.ReadLineAsync();
|
line = await reader.ReadLineAsync();
|
||||||
|
if (LogPath != null) await File.AppendAllTextAsync(LogPath, $"{line}\r\n");
|
||||||
}
|
}
|
||||||
if (line == null || line.Length < 4 || !line.StartsWith("<") || !line.EndsWith(">")) {
|
if (line == null || line.Length < 4 || !line.StartsWith("<") || !line.EndsWith(">")) {
|
||||||
throw new IOException("Invalid response from scale");
|
throw new IOException("Invalid response from scale");
|
||||||
|
@ -15,6 +15,7 @@ file = database.sqlite3
|
|||||||
;connection = serial://COM1:9600,8,N,1
|
;connection = serial://COM1:9600,8,N,1
|
||||||
;empty = RTS:1000
|
;empty = RTS:1000
|
||||||
;limit = 4000
|
;limit = 4000
|
||||||
|
;log = waage.log
|
||||||
|
|
||||||
;[scale.B]
|
;[scale.B]
|
||||||
;type = Type
|
;type = Type
|
||||||
|
Reference in New Issue
Block a user