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 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; } } } }