From 4cac1b533e133fdc8b3def90a0f998820f51907a Mon Sep 17 00:00:00 2001
From: alielie <alielie@git.com>
Date: 星期三, 26 三月 2025 17:57:59 +0800
Subject: [PATCH] 优化UI,新增日志自动删除;
---
Plugin.ServoManage/ServoManage.xaml.cs | 107 +++++++++++++++++++++++++++++++++++++----------------
1 files changed, 74 insertions(+), 33 deletions(-)
diff --git a/Plugin.ServoManage/ServoManage.xaml.cs b/Plugin.ServoManage/ServoManage.xaml.cs
index 76a460e..39c557b 100644
--- a/Plugin.ServoManage/ServoManage.xaml.cs
+++ b/Plugin.ServoManage/ServoManage.xaml.cs
@@ -1,8 +1,9 @@
锘縰sing HMI.Base;
+using HMI.Core.Entity;
+using HMI.Core.Manager;
using HMI.Core.Setting;
using HMI.Core.Util;
-using HMI.ParameterManage.Entity;
-using HMI.ParameterManage.Util;
+using HMI.UI;
using HMI.UI.Util;
using Plugin.ServoManage.Entity;
using System;
@@ -15,6 +16,7 @@
using System.Timers;
using System.Windows;
using System.Windows.Controls;
+using System.Windows.Threading;
namespace Plugin.ServoManage
{
@@ -93,6 +95,7 @@
private bool isActived = false;
private System.Timers.Timer motorMonitorTimer;
+ #region ServoData
private string enable;
[IsStatus]
public string Enable
@@ -345,28 +348,20 @@
Set(ref posCode, value);
}
}
+ #endregion
public ServoManage()
{
DataContext = this;
motorMonitorTimer = new System.Timers.Timer();
motorMonitorTimer.Elapsed += MotorMonitorTimer_Elapsed;
+ motorMonitorTimer.Interval = 100;
InitializeComponent();
}
private void MotorMonitorTimer_Elapsed(object sender, ElapsedEventArgs e)
{
- this.motorMonitorTimer.Enabled = false;
- try
- {
- RefreshServoStatus();
- this.motorMonitorTimer.Enabled = true;
- }
- catch (Exception ex)
- {
- this.motorMonitorTimer.Enabled = true;
- return;
- }
+ RefreshServoStatus();
}
public override void SetBaseFolder(string folder)
@@ -387,8 +382,7 @@
{
if (lTSCADAApi.Connect2("127.0.0.1", 6543, 18888, out string errMsg))
{
- this.motorMonitorTimer.Interval = 100;
- this.motorMonitorTimer.Start();
+ motorMonitorTimer.Enabled = true;
isActived = true;
}
else
@@ -408,6 +402,15 @@
MsgBoxHelper2.Error(ex.Message);
}
}
+ else {
+ motorMonitorTimer.Enabled = true;
+ }
+ }
+
+ public override void DeActive()
+ {
+ motorMonitorTimer.Enabled = false;
+ base.DeActive();
}
private void UserControl_Loaded(object sender, RoutedEventArgs e)
@@ -435,7 +438,6 @@
case "rfhServoBtn":
LoadData();
break;
-
case "addProductBtn":
OpenProductModal(null);
break;
@@ -515,12 +517,12 @@
public ObservableCollection<ServoProductData> ReadCommonProducts()
{
ObservableCollection<ServoProductData> datas = new ObservableCollection<ServoProductData>();
- List<ProductData> products = ParameterManager.GetProducts<List<ProductData>>();
+ List<ProductData> products = ProductManager.GetProducts<List<ProductData>>();
if (products != null && products.Count > 0)
{
foreach (var product in products)
{
- var parameter = ParameterManager.GetParametersByProductName(product.Name)
+ var parameter = ProductManager.GetParametersByProductName(product.Name)
?.FirstOrDefault(p => p.Name == "ProgramCode");
if (parameter != null)
{
@@ -580,7 +582,8 @@
private void RefreshServoStatus()
{
- Dispatcher.Invoke(() =>
+ this.motorMonitorTimer.Enabled = false;
+ try
{
if (SelectedServo == null) return;
PropertyInfo[] properties = this.GetType().GetProperties();
@@ -590,19 +593,29 @@
{
continue;
}
-
- if (prop.Name == "SelectedProduct")
+ Dispatcher.InvokeAsync(new Action(() =>
{
- var data = GetBitValue($"{SelectedServo.Name}_sRecipeCode");
- SelectedProduct = data;
- }
- else
- {
- var data = GetBitValue($"{SelectedServo.Name}_{prop.Name}");
- prop.SetValue(this, data);
- }
+ if (prop.Name == "SelectedProduct")
+ {
+ var data = GetBitValue($"{SelectedServo.Name}_sRecipeCode");
+ SelectedProduct = data;
+ }
+ else
+ {
+ var data = GetBitValue($"{SelectedServo.Name}_{prop.Name}");
+ prop.SetValue(this, data);
+ }
+ }), DispatcherPriority.SystemIdle);
}
- });
+ }
+ catch (Exception ex)
+ {
+
+ }
+ finally
+ {
+ this.motorMonitorTimer.Enabled = true;
+ }
}
/// <summary>
@@ -647,7 +660,6 @@
Button btn = sender as Button;
try
{
- motorMonitorTimer.Enabled = false;
switch (btn.Tag)
{
case "Enable":
@@ -657,7 +669,7 @@
EnableDoClick(btn.Tag.ToString());
break;
default:
- DoSignClick(btn.Tag?.ToString());
+ //DoSignClick(btn.Tag?.ToString());
break;
}
}
@@ -668,7 +680,6 @@
}
finally
{
- motorMonitorTimer.Enabled = true;
}
}
@@ -720,5 +731,35 @@
SetBitValue($"{SelectedServo?.Name}_{tag}", np.Data?.ToString());
}
}
+
+ private void Button_PreviewMouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
+ {
+ Button btn = sender as Button;
+ var tag = btn.Tag.ToString();
+ try
+ {
+ motorMonitorTimer.Enabled = false;
+ SetBitValue($"{SelectedServo?.Name}_{tag}", "true");
+ }
+ finally
+ {
+ motorMonitorTimer.Enabled = true;
+ }
+ }
+
+ private void Button_PreviewMouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
+ {
+ Button btn = sender as Button;
+ var tag = btn.Tag.ToString();
+ try
+ {
+ motorMonitorTimer.Enabled = false;
+ SetBitValue($"{SelectedServo?.Name}_{tag}", "false");
+ }
+ finally
+ {
+ motorMonitorTimer.Enabled = true;
+ }
+ }
}
}
--
Gitblit v1.9.1