Add more scale types
This commit is contained in:
@ -3,7 +3,6 @@ using System.IO;
|
||||
using System.IO.Ports;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Elwig.Helpers.Weighing {
|
||||
@ -20,9 +19,6 @@ namespace Elwig.Helpers.Weighing {
|
||||
protected readonly Output? FillingClearanceMode = null;
|
||||
protected readonly int EmptyDelay;
|
||||
|
||||
protected static readonly Regex SerialRe = new(@"^serial://([A-Za-z0-9]+):([0-9]+)(,([5-9]),([NOEMSnoems]),(0|1|1\.5|2|))?$", RegexOptions.Compiled);
|
||||
protected static readonly Regex TcpRe = new(@"^tcp://[A-Za-z0-9:._-]+(:[0-9]+)?$", RegexOptions.Compiled);
|
||||
|
||||
public string Manufacturer => "SysTec";
|
||||
public int InternalScaleNr => 1;
|
||||
public string Model { get; private set; }
|
||||
@ -38,39 +34,11 @@ namespace Elwig.Helpers.Weighing {
|
||||
HasFillingClearance = false;
|
||||
|
||||
Stream stream;
|
||||
|
||||
if (connection.StartsWith("serial:")) {
|
||||
var m = SerialRe.Match(connection);
|
||||
if (!m.Success)
|
||||
throw new ArgumentException("Invalid connection string for scheme \"serial\"");
|
||||
|
||||
var stop = m.Groups[6].Value;
|
||||
var parity = m.Groups[5].Value.ToUpper();
|
||||
var data = m.Groups[4].Value;
|
||||
Serial = new() {
|
||||
PortName = m.Groups[1].Value,
|
||||
BaudRate = int.Parse(m.Groups[2].Value),
|
||||
Parity = parity == "E" ? Parity.Even :
|
||||
parity == "O" ? Parity.Odd :
|
||||
parity == "M" ? Parity.Mark :
|
||||
parity == "S" ? Parity.Space :
|
||||
Parity.None,
|
||||
DataBits = data == "" ? 8 : int.Parse(data),
|
||||
StopBits = (StopBits)(stop == "" ? 1 : stop == "1.5" ? 3 : stop[0] - '0'),
|
||||
Handshake = Handshake.None,
|
||||
};
|
||||
Serial.Open();
|
||||
Serial = Utils.OpenSerialConnection(connection);
|
||||
stream = Serial.BaseStream;
|
||||
} else if (connection.StartsWith("tcp:")) {
|
||||
var m = TcpRe.Match(connection);
|
||||
if (!m.Success)
|
||||
throw new ArgumentException("Invalid connection string for scheme \"tcp\"");
|
||||
|
||||
Tcp = new() {
|
||||
SendTimeout = 250,
|
||||
ReceiveTimeout = 250,
|
||||
};
|
||||
Tcp.Connect(m.Groups[1].Value, int.Parse(m.Groups[2].Value));
|
||||
Tcp = Utils.OpenTcpConnection(connection);
|
||||
stream = Tcp.GetStream();
|
||||
} else {
|
||||
throw new ArgumentException("Unsupported scheme");
|
||||
|
Reference in New Issue
Block a user