You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.1 KiB
48 lines
1.1 KiB
using EC.AutoWeightServer.Model.EventArgsEx;
|
|
using EC.Utils;
|
|
using System;
|
|
using System.Text;
|
|
using System.Text.RegularExpressions;
|
|
|
|
namespace EC.AutoWeightServer.IfManager.Scales
|
|
{
|
|
public class ScalesDefault : Scales
|
|
{
|
|
public ScalesDefault()
|
|
{
|
|
}
|
|
|
|
public ScalesDefault(string comName, int baudRate)
|
|
{
|
|
this.ComName = comName;
|
|
this.BaudRate = baudRate;
|
|
}
|
|
|
|
public override event EventHandler<ScaleEventArgs> OnRecData;
|
|
|
|
public override void RecData(object sender, byte[] buf)
|
|
{
|
|
var weightBuf = Encoding.UTF8.GetString(buf);
|
|
var weightArgs = weightBuf.Split('\n');
|
|
|
|
foreach (var weightArg in weightArgs)
|
|
{
|
|
var args = Regex.Split(weightArg.Trim(), @"\s+", RegexOptions.IgnoreCase);
|
|
if (args.Length != 3)
|
|
continue;
|
|
if (!(args[0].Equals("+") ^ args[0].Equals("-")))
|
|
continue;
|
|
|
|
var weight = CommonUtil.WeightStrToDec(args[0] + args[1]);
|
|
var units = args[2];
|
|
if (weight <= 0)
|
|
continue;
|
|
|
|
var scaleArgs = new ScaleEventArgs(weight, units);
|
|
|
|
OnRecData?.Invoke(sender, scaleArgs);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|