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.

58 lines
1.3 KiB

using EC.AutoWeightServer.Model.EventArgsEx;
using EC.Utils;
using System;
using System.Text;
using EC.AutoWeightServer.Model.Config;
namespace EC.AutoWeightServer.IfManager.Scales
{
public class ScalesZhuHai : Scales
{
public ScalesZhuHai()
{
}
public ScalesZhuHai(string comName, int baudRate)
{
this.ComName = comName;
this.BaudRate = baudRate;
}
public ScalesZhuHai(string comName, int baudRate, int receivedBytesThreshold)
{
this.ComName = comName;
this.BaudRate = baudRate;
this.ReceivedBytesThreshold = 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();
}
}
}