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;