页面逻辑添加
This commit is contained in:
@@ -40,7 +40,7 @@
|
||||
<!-- 输入框样式 -->
|
||||
<Style x:Key="SettingTextBox" TargetType="TextBox">
|
||||
<Setter Property="Width" Value="160"/>
|
||||
<Setter Property="Height" Value="30"/>
|
||||
<Setter Property="Height" Value="35"/>
|
||||
<Setter Property="FontSize" Value="13"/>
|
||||
<Setter Property="Margin" Value="0 6 0 6"/>
|
||||
<Setter Property="Padding" Value="8"/>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Microsoft.Win32;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
@@ -47,13 +48,31 @@ namespace 片剂四用仪.Views
|
||||
if (m.Type == PlcParamType.Int)
|
||||
{
|
||||
ushort[] res = await _plc.ReadHoldingRegistersAsync((ushort)m.Address, 1);
|
||||
Dispatcher.Invoke(() => tb.Text = res[0].ToString());
|
||||
if (_plc.IsConnected)
|
||||
{
|
||||
Dispatcher.Invoke(() => tb.Text = res[0].ToString());
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
Dispatcher.Invoke(() => tb.Text = "0"); // 读取失败时显示占位符
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ushort[] res = await _plc.ReadHoldingRegistersAsync((ushort)m.Address, 2);
|
||||
float value = BitConverter.ToSingle(BitConverter.GetBytes((uint)(res[0] << 16 | res[1])), 0);
|
||||
Dispatcher.Invoke(() => tb.Text = value.ToString("F2"));
|
||||
|
||||
// 同样增加有效性判断
|
||||
if (_plc.IsConnected)
|
||||
{
|
||||
float value = BitConverter.ToSingle(BitConverter.GetBytes((uint)(res[0] << 16 | res[1])), 0);
|
||||
Dispatcher.Invoke(() => tb.Text = value.ToString("F2"));
|
||||
}
|
||||
else
|
||||
{
|
||||
Dispatcher.Invoke(() => tb.Text = "0"); // 读取失败时显示占位符
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user