From 9085c9b17862e95b9afc0b4a21a94bfcafd570fc Mon Sep 17 00:00:00 2001
From: tfarcraw <123211521@163.com>
Date: Fri, 16 Oct 2026 03:25:14 +0800
Subject: [PATCH] =?UTF-8?q?=E6=8E=A7=E5=88=B6=E5=99=A8=EF=BC=9A=E5=9E=8B?=
=?UTF-8?q?=E5=8F=B7=E9=80=89=E5=AE=9A=E5=90=8E=E4=B8=8B=E6=8B=89=E6=A1=86?=
=?UTF-8?q?=E5=8F=AA=E8=AF=BB=EF=BC=8C=E6=96=B0=E5=A2=9E=E5=88=A0=E9=99=A4?=
=?UTF-8?q?=E6=8C=89=E9=92=AE?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
- Controllers.xaml: 型号 ComboBox 默认禁用,仅 Type=Undefined 时可选;新增删除按钮
- Controller: Type setter 允许重置为 Undefined;后台循环加 SDK null 保护;新增 Reset()(停轴→关SDK→置null→清Axes/DI/DQ→复位状态)
- ControllersModel: ControllerManage 新增 Delete 命令(确认框→Reset→清运行时集合与DB全部相关表→型号重置为Undefined)
---
.../VVMs/MotionController/Controller.cs | 34 +++++++++++++++++
.../VVMs/MotionController/Controllers.xaml | 14 ++++++-
.../VVMs/MotionController/ControllersModel.cs | 38 +++++++++++++++++++
3 files changed, 85 insertions(+), 1 deletion(-)
diff --git a/PLCSharpWpf/VVMs/MotionController/Controller.cs b/PLCSharpWpf/VVMs/MotionController/Controller.cs
index 02bf15d..f023970 100644
--- a/PLCSharpWpf/VVMs/MotionController/Controller.cs
+++ b/PLCSharpWpf/VVMs/MotionController/Controller.cs
@@ -54,6 +54,11 @@ namespace PLCSharp.VVMs.MotionController
SetProperty(ref _Type, value);
}
}
+ else if (value == ControllerType.Undefined)
+ {
+ // 允许重置为Undefined(删除控制器)
+ SetProperty(ref _Type, value);
+ }
else if (_Type != value)
{
MessageBox.Show("选定型号后不可改变!");
@@ -147,6 +152,12 @@ namespace PLCSharp.VVMs.MotionController
}
}
+ if (SDK == null)
+ {
+ Thread.Sleep(1000);
+ continue;
+ }
+
if (Connected == false)
{
Thread.Sleep(1000);
@@ -469,6 +480,29 @@ namespace PLCSharp.VVMs.MotionController
SDK?.Close();
}
+ ///
+ /// 删除控制器:停轴、关闭SDK、复位型号为Undefined并清空运行时数据
+ ///
+ public void Reset()
+ {
+ foreach (var axis in Axes)
+ {
+ axis.Stop();
+ }
+ Thread.Sleep(100);
+
+ Type = ControllerType.Undefined;
+ Close();
+ SDK = null;
+ Connected = false;
+ Online = false;
+ Prompt = "";
+
+ Axes.Clear();
+ DI.Clear();
+ DQ.Clear();
+ }
+
///
/// 初始化
///
diff --git a/PLCSharpWpf/VVMs/MotionController/Controllers.xaml b/PLCSharpWpf/VVMs/MotionController/Controllers.xaml
index 63472f1..9678bd7 100644
--- a/PLCSharpWpf/VVMs/MotionController/Controllers.xaml
+++ b/PLCSharpWpf/VVMs/MotionController/Controllers.xaml
@@ -55,7 +55,18 @@
+ SelectedItem="{Binding ControllerModel.Controller.Type, UpdateSourceTrigger=PropertyChanged}">
+
+
+
+
@@ -67,6 +78,7 @@
+
diff --git a/PLCSharpWpf/VVMs/MotionController/ControllersModel.cs b/PLCSharpWpf/VVMs/MotionController/ControllersModel.cs
index 1f23b79..1594901 100644
--- a/PLCSharpWpf/VVMs/MotionController/ControllersModel.cs
+++ b/PLCSharpWpf/VVMs/MotionController/ControllersModel.cs
@@ -433,6 +433,44 @@ namespace PLCSharp.VVMs.MotionController
{
switch (cmd)
{
+ case "Delete":
+ if (Controller == null || Controller.Type == ControllerType.Undefined)
+ {
+ SendInfoDialog("当前没有已配置的控制器");
+ break;
+ }
+ if (System.Windows.MessageBox.Show("确认删除当前控制器?\n将同时删除所有轴、IO、点位、矩阵和插补配置!", "确认删除", System.Windows.MessageBoxButton.YesNo, System.Windows.MessageBoxImage.Warning) != System.Windows.MessageBoxResult.Yes)
+ break;
+
+ Controller.Reset();
+
+ // 清理运行时集合
+ Axes.Clear();
+ DI.Clear();
+ DQ.Clear();
+ AxisPoints.Clear();
+ Matrices.Clear();
+ InterpolationGroups.Clear();
+ SelectedAxis = null;
+ SelectedAxisPoint = null;
+ SelectedMatrix = null;
+ SelectedInterpolationGroup = null;
+ ControllerConfig = null;
+ AxisConfig = null;
+
+ // 清理数据库
+ _DatasContext.Controllers.RemoveRange(_DatasContext.Controllers.ToList());
+ _DatasContext.Axes.RemoveRange(_DatasContext.Axes.ToList());
+ _DatasContext.DI.RemoveRange(_DatasContext.DI.ToList());
+ _DatasContext.DQ.RemoveRange(_DatasContext.DQ.ToList());
+ _DatasContext.AxisPoints.RemoveRange(_DatasContext.AxisPoints.ToList());
+ _DatasContext.Matrices.RemoveRange(_DatasContext.Matrices.ToList());
+ _DatasContext.InterpolationGroups.RemoveRange(_DatasContext.InterpolationGroups.ToList());
+ _DatasContext.Save();
+
+ SendInfoDialog("控制器已删除,型号已重置为Undefined");
+ break;
+
case "Save":
if (!_DatasContext.Controllers.Any(h => h.ID == Controller.ID))
{