From 627825f0d6f49739a8cad43b8db8d338d4edb08d Mon Sep 17 00:00:00 2001 From: yibo <361071264@qq.com> Date: Wed, 16 Sep 2020 18:01:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E7=A7=B0=E5=9E=8B=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controls/Utils/DataFormatBase.cs | 2 +- .../Controls/Utils/JST2018SDataFormat.cs | 24 +++++++++++++++++-- ButcherFactory.Form/Controls/WeightControl.cs | 2 +- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/ButcherFactory.Form/Controls/Utils/DataFormatBase.cs b/ButcherFactory.Form/Controls/Utils/DataFormatBase.cs index 48aac80..ab91d4d 100644 --- a/ButcherFactory.Form/Controls/Utils/DataFormatBase.cs +++ b/ButcherFactory.Form/Controls/Utils/DataFormatBase.cs @@ -36,7 +36,7 @@ namespace ButcherFactory.Controls public const short BUFSIZE = 36; // 根据开始字符找出 一个完整的数据帧 - public string FindDataFrame(string buf, int fSize) + public virtual string FindDataFrame(string buf, int fSize) { var bufSize = buf.Length; if (fSize > bufSize) diff --git a/ButcherFactory.Form/Controls/Utils/JST2018SDataFormat.cs b/ButcherFactory.Form/Controls/Utils/JST2018SDataFormat.cs index a04d61d..ad88ba9 100644 --- a/ButcherFactory.Form/Controls/Utils/JST2018SDataFormat.cs +++ b/ButcherFactory.Form/Controls/Utils/JST2018SDataFormat.cs @@ -25,7 +25,7 @@ namespace ButcherFactory.Controls public override short Bufsize { - get { return 36; } + get { return 9; } } public override string ParseData(string buf, out bool isStatic) @@ -45,7 +45,7 @@ namespace ButcherFactory.Controls // buffer[1] 符号位 if (buf[5] == 0x01) { - weight = (Convert.ToDecimal(weight) / 1000).ToString("#0.0"); + weight = (Convert.ToDecimal(weight) / 1000).ToString("#0.0000"); } if ((buf[1] & 0x20) == 1) weight = "-" + weight; @@ -72,6 +72,26 @@ namespace ButcherFactory.Controls return true; } + public override string FindDataFrame(string buf, int fSize) + { + var bufSize = buf.Length; + if (fSize > bufSize) + { + return string.Empty; + } + + int index = buf.IndexOf(Beginchar); // 查找开始字符的索引 + + if (index < 0 || (index + fSize) > bufSize) + { + return string.Empty; + } + + string data = buf.Substring(index, fSize); + + return data; + } + private static string InsertDot(string weight, int dotBits) { var rst = weight.Insert(weight.Length - dotBits, ".").Trim('0'); diff --git a/ButcherFactory.Form/Controls/WeightControl.cs b/ButcherFactory.Form/Controls/WeightControl.cs index 2b3a736..48d796f 100644 --- a/ButcherFactory.Form/Controls/WeightControl.cs +++ b/ButcherFactory.Form/Controls/WeightControl.cs @@ -193,7 +193,7 @@ namespace ButcherFactory.Controls _dataStrBuilder.Clear(); _dataStrBuilder.Append(c); } - else if (c == _dataFormat.Endchar || _dataStrBuilder.Length > _dataFormat.Bufsize) + else if (c == _dataFormat.Endchar || _dataStrBuilder.Length >= _dataFormat.Bufsize) { _dataStrBuilder.Append(c); bool isStatic;