using EC.AutoWeightServer.Model.Config; using EC.AutoWeightServer.Model.EventArgsEx; using EC.Utils; using System; using System.Text; namespace EC.AutoWeightServer.IfManager.Scales { public class ScalesZhuHai : Scales { public ScalesZhuHai(string comName, int baudRate, int receivedBytesThreshold) : base(comName, baudRate, receivedBytesThreshold) { } public override event EventHandler OnRecData; public event EventHandler OnRecTransmit = null; public override void RecData(object sender, byte[] buf) { OnRecTransmit?.Invoke(sender, buf); var weightBuf = CommonUtil.Reverse(Encoding.UTF8.GetString(buf).Replace(".", "").Trim()); var weightArgs = weightBuf.Split('='); foreach (var weightArg in weightArgs) { if (string.IsNullOrEmpty(weightArg)) continue; if (!CommonUtil.IsNumber(weightArg)) continue; var weight = CommonUtil.WeightStrToDec(weightArg) / 1000; var unit = "t"; var scaleArgs = new ScaleEventArgs(weight, unit); OnRecData?.Invoke(sender, scaleArgs); break; } if (ServerConfig.WTDiscardInBufferFlag > 0) _port.DiscardInBuffer(); } } }