From 4d93d994510436743a6599884773fb0e0098893e Mon Sep 17 00:00:00 2001 From: "Robin_PC\\robin" <3504557@qq.com> Date: Sat, 9 May 2026 19:10:49 +0800 Subject: [PATCH] =?UTF-8?q?=E9=9C=80=E6=B1=82=E5=8D=95No.3208?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ButcherFactory.Form.csproj | 1 + .../Controls/Utils/JST2018SDataFormat.cs | 3 + .../Controls/Utils/JST8180DataFormat.cs | 70 +++++++++++++++++++ ButcherFactory.Form/Controls/WeightControl.cs | 3 + .../Controls/WeightSettingFrom.cs | 2 +- 5 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 ButcherFactory.Form/Controls/Utils/JST8180DataFormat.cs diff --git a/ButcherFactory.Form/ButcherFactory.Form.csproj b/ButcherFactory.Form/ButcherFactory.Form.csproj index ce7a0c7..4622525 100644 --- a/ButcherFactory.Form/ButcherFactory.Form.csproj +++ b/ButcherFactory.Form/ButcherFactory.Form.csproj @@ -117,6 +117,7 @@ UserControl1.cs + diff --git a/ButcherFactory.Form/Controls/Utils/JST2018SDataFormat.cs b/ButcherFactory.Form/Controls/Utils/JST2018SDataFormat.cs index 470bea5..74a7e81 100644 --- a/ButcherFactory.Form/Controls/Utils/JST2018SDataFormat.cs +++ b/ButcherFactory.Form/Controls/Utils/JST2018SDataFormat.cs @@ -8,6 +8,9 @@ namespace ButcherFactory.Controls { internal class JST2018SDataFormat : DataFormatBase { + // 00007RX: FF 43 78 40 00 10 00 00 00 37 + // 00009RX: FF 43 88 40 00 10 00 00 00 37 + public override int DataLength { get { return 8; } diff --git a/ButcherFactory.Form/Controls/Utils/JST8180DataFormat.cs b/ButcherFactory.Form/Controls/Utils/JST8180DataFormat.cs new file mode 100644 index 0000000..c529e6f --- /dev/null +++ b/ButcherFactory.Form/Controls/Utils/JST8180DataFormat.cs @@ -0,0 +1,70 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ButcherFactory.Controls +{ + internal class JST8180DataFormat : DataFormatBase + { + public override int DataLength => 8; + public override char Beginchar => (char)0x3D; // = 开头 + public override char Endchar => (char)0xFF; + public override short Bufsize => 7; + + public override string ParseData(string buf, out bool isStatic) + { + // 3D 34 39 2E 36 30 30 30 + // 6.94 + + isStatic = true; + try + { + // 1. 去掉 = 和 . 例:=49.6000 → 496000 + string raw = buf.TrimStart('=').Replace(".", ""); + + // 2. 反转数字 496000 → 000694 + char[] arr = raw.ToCharArray(); + Array.Reverse(arr); + string reversed = new string(arr); + + // 3. 插入小数点(固定2位小数) + decimal weight = decimal.Parse(reversed) / 100m; + + // 4. 输出仪表显示值 + return weight.ToString("0.00"); + } + catch + { + return "0.00"; + } + } + + public override bool ParseAscii(string buf, out string weight, out bool isStatic) + { + weight = string.Empty; + isStatic = false; + string frame = FindDataFrame(buf, DataLength); + if (string.IsNullOrEmpty(frame)) return false; + + weight = ParseData(frame, out isStatic); + return true; + } + + public override string FindDataFrame(string buf, int fSize) + { + if (buf == null || buf.Length < fSize) return ""; + int idx = buf.IndexOf(Beginchar); + if (idx < 0 || idx + fSize > buf.Length) return ""; + return buf.Substring(idx, fSize); + } + + public override bool ParseAscii(string buf, out string weight, out bool isStatic, out string subStr) + { + weight = ""; isStatic = false; subStr = ""; return false; + } + } + + +} diff --git a/ButcherFactory.Form/Controls/WeightControl.cs b/ButcherFactory.Form/Controls/WeightControl.cs index ac235de..8d70bda 100644 --- a/ButcherFactory.Form/Controls/WeightControl.cs +++ b/ButcherFactory.Form/Controls/WeightControl.cs @@ -145,6 +145,9 @@ namespace ButcherFactory.Controls case "JST2018S": _dataFormat = new JST2018SDataFormat(); break; + case "JST8180": + _dataFormat = new JST8180DataFormat(); + break; case "一体称"://02 10 53 54 2C 47 53 3A 20 30 30 30 31 2E 37 31 6B 67 A8 FE 00 49 01 00 AC 99 A8 FE 00 _dataFormat = new CombineWeightDataFormat(); break; diff --git a/ButcherFactory.Form/Controls/WeightSettingFrom.cs b/ButcherFactory.Form/Controls/WeightSettingFrom.cs index 52b1598..406dbd5 100644 --- a/ButcherFactory.Form/Controls/WeightSettingFrom.cs +++ b/ButcherFactory.Form/Controls/WeightSettingFrom.cs @@ -12,7 +12,7 @@ namespace ButcherFactory.Controls { public partial class WeightSettingFrom : Form { - List weight = new List { "IND560", "Xk3124", "Xk3190A9", "Xk3190D10", "IND231", "AHS3000", "JST2018S", "一体称" }; + List weight = new List { "IND560", "Xk3124", "Xk3190A9", "Xk3190D10", "IND231", "AHS3000", "JST2018S", "一体称" , "JST8180" }; List com = new List { "COM1", "COM2", "COM3", "COM4", "COM5" }; List rate = new List { "1200", "2400", "4800", "7200", "9600" }; List bit = new List { "5", "6", "7", "8" };