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.

45 lines
1.2 KiB

using EC.AutoWeightServer.Model.Config;
using EC.AutoWeightServer.Model.EventArgsEx;
using EC.Utils;
using System;
using System.Text;
using System.Text.RegularExpressions;
namespace EC.AutoWeightServer.IfManager.Scales
{
public class ScalesHuiZhou : Scales
{
public ScalesHuiZhou(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);
string tempBuf = Encoding.UTF8.GetString(buf);
string[] splitBufArray = tempBuf.Split('\r');
foreach (var item in splitBufArray)
{
if (item.Length != 16) { continue; }
tempBuf = item;
MatchCollection mc = Regex.Matches(tempBuf, @"(\d+)");
if (mc.Count != 3) { continue; }
string weightArg = mc[1].Value;
decimal weight = CommonUtil.WeightStrToDec(weightArg) / 1000;
string unit = "t";
var scaleArgs = new ScaleEventArgs(weight, unit);
OnRecData?.Invoke(sender, scaleArgs);
break;
}
if (ServerConfig.WTDiscardInBufferFlag > 0)
_port.DiscardInBuffer();
}
}
}