From e0c2eca9f23008fbe8a76a73edd9226aab9d2bf1 Mon Sep 17 00:00:00 2001 From: rain Date: Fri, 15 May 2026 16:33:15 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E9=80=BB=E8=BE=91=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Views/ShowData.xaml.cs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Views/ShowData.xaml.cs b/Views/ShowData.xaml.cs index a570ef1..70b4441 100644 --- a/Views/ShowData.xaml.cs +++ b/Views/ShowData.xaml.cs @@ -90,7 +90,7 @@ namespace 片剂四用仪.Views var tb = FindName(m.TextBoxName) as TextBox; if (tb == null) continue; - tb.LostFocus += async (s, e) => + tb.GotFocus += async (s, e) => { try { @@ -103,14 +103,17 @@ namespace 片剂四用仪.Views { if (double.TryParse(tb.Text, out double val)) { - byte[] bytes = BitConverter.GetBytes(val); - ushort[] regs = new ushort[2]; - regs[0] = (ushort)(BitConverter.ToUInt16(bytes, 2)); - regs[1] = (ushort)(BitConverter.ToUInt16(bytes, 0)); - + // 弹窗修改值 if (UIInputDialog.ShowInputDoubleDialog(ref val, UIStyle.Inherited, 3, desc: "请输入值", showMask: false)) { + // 更新界面 + tb.Text = val.ToString("F3"); + // 写入PLC(浮点数双寄存器) + byte[] bytes = BitConverter.GetBytes(val); + ushort[] regs = new ushort[2]; + regs[0] = (ushort)BitConverter.ToUInt16(bytes, 2); + regs[1] = (ushort)BitConverter.ToUInt16(bytes, 0); await _plc.WriteRegisterAsync((ushort)m.Address, (ushort)val); } }