页面逻辑添加

This commit is contained in:
2026-05-15 16:33:15 +08:00
parent 5142b68300
commit e0c2eca9f2

View File

@@ -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);
}
}