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.

46 lines
1.1 KiB

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<ScaleEventArgs> OnRecData;
public event EventHandler<byte[]> 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();
}
}
}