页面逻辑修改
This commit is contained in:
@@ -172,7 +172,15 @@ namespace 头罩视野.Views
|
||||
// 返回 RecordDate 实例
|
||||
return frame?.Content as RecordDate;
|
||||
}
|
||||
//停止btn
|
||||
private void Button_Click_Stop(object sender, RoutedEventArgs e)
|
||||
{
|
||||
ma.BtnClickFunction(Function.ButtonType.复归型, 103);
|
||||
ButtonTest.Content = "测试";
|
||||
testTimer.Stop();
|
||||
|
||||
|
||||
}
|
||||
//测试btn 测试按钮:读取数据,存入共享列表
|
||||
private void Button_Click_Test(object sender, RoutedEventArgs e)
|
||||
|
||||
@@ -238,14 +246,39 @@ namespace 头罩视野.Views
|
||||
sybhl.Text = binocularRate.ToString("0.00"); // 视野保存率
|
||||
}
|
||||
}
|
||||
//停止btn
|
||||
private void Button_Click_Stop(object sender, RoutedEventArgs e)
|
||||
{
|
||||
ma.BtnClickFunction(Function.ButtonType.复归型, 103);
|
||||
ButtonTest.Content = "测试";
|
||||
testTimer.Stop();
|
||||
|
||||
|
||||
//读取灯泡的数据
|
||||
|
||||
private async Task ReadLightBarData()
|
||||
{
|
||||
// 无连接直接返回
|
||||
if (_modbusMaster == null || !ModbusHelper.TcpClient.Connected)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
// 读取灯条寄存器(地址350,长度15)
|
||||
ushort[] registers = await _modbusMaster.ReadHoldingRegistersAsync(1, 350, 15);
|
||||
|
||||
// 每个 ushort 是16位,低位在前
|
||||
foreach (ushort reg in registers)
|
||||
{
|
||||
for (int bit = 0; bit < 16; bit++)
|
||||
{
|
||||
// 取第bit位的值:0或1
|
||||
int lightBit = (reg & (1 << bit)) != 0 ? 1 : 0;
|
||||
DataList.Add(lightBit);
|
||||
}
|
||||
}
|
||||
|
||||
// 调试:打印转换后的数据长度
|
||||
System.Diagnostics.Debug.WriteLine($"灯条二进制数据总长度:{DataList.Count}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"灯条数据读取失败:{ex.Message}");
|
||||
//DataList.Clear(); // 出错时清空数据
|
||||
}
|
||||
}
|
||||
private async void Timer_Tick(object sender, EventArgs e)
|
||||
|
||||
@@ -463,7 +496,6 @@ namespace 头罩视野.Views
|
||||
zdangle.Focus();
|
||||
}
|
||||
|
||||
|
||||
//错误信息提示
|
||||
private void ShowError(string msg) => MessageBox.Show(msg, "错误", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
private void GoHome(object s, RoutedEventArgs e) => NavigationService.Content = null;
|
||||
@@ -503,43 +535,7 @@ namespace 头罩视野.Views
|
||||
|
||||
|
||||
|
||||
//读取灯泡的数据
|
||||
|
||||
/// <summary>
|
||||
/// 读取灯条PLC数据 → 自动存入 DataList
|
||||
/// 可直接放入 Task 列表等待
|
||||
/// </summary>
|
||||
private async Task ReadLightBarData()
|
||||
{
|
||||
// 无连接直接返回
|
||||
if (_modbusMaster == null || !ModbusHelper.TcpClient.Connected)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
// 读取灯条寄存器(地址350,长度15)
|
||||
ushort[] registers = await _modbusMaster.ReadHoldingRegistersAsync(1, 350, 15);
|
||||
|
||||
// 每个 ushort 是16位,低位在前
|
||||
foreach (ushort reg in registers)
|
||||
{
|
||||
for (int bit = 0; bit < 16; bit++)
|
||||
{
|
||||
// 取第bit位的值:0或1
|
||||
int lightBit = (reg & (1 << bit)) != 0 ? 1 : 0;
|
||||
DataList.Add(lightBit);
|
||||
}
|
||||
}
|
||||
|
||||
// 调试:打印转换后的数据长度
|
||||
System.Diagnostics.Debug.WriteLine($"灯条二进制数据总长度:{DataList.Count}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"灯条数据读取失败:{ex.Message}");
|
||||
//DataList.Clear(); // 出错时清空数据
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user