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 @@