From a0c24a82fb55443f6b8fbc7df6bfa4a15953a692 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A6=82=E6=84=8F=20=E5=BD=AD?= <2417589739@qq.com> Date: Wed, 26 Oct 2022 13:22:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9F=94=E6=80=A7=E5=91=B3=E9=AD=94=E6=96=B9?= =?UTF-8?q?=E4=B8=9A=E5=8A=A1=E6=B5=81=E7=A8=8B=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BPASmart.ConfigurationSoftware.csproj | 2 +- BPASmart.PageLoad/BPASmart.PageLoad.csproj | 2 +- BPASmart.Server/BPASmart.Server.csproj | 2 +- .../BPASmart.VariableManager.csproj | 2 +- .../BPASmartClient.CustomResource.csproj | 2 +- BPASmartClient.Helper/ThreadManage.cs | 122 ++++++++-------- BPASmartClient.S7Net/SiemensHelper.cs | 8 +- .../BPASmartClient.SmallBatchingSystem.csproj | 2 +- ComputerTestDemo/ComputerTestDemo.csproj | 2 +- DosingSystem/App.xaml.cs | 12 +- .../BPASmartClient.DosingSystem.csproj | 2 +- DosingSystem/Model/ConveyerBeltModel.cs | 30 +++- DosingSystem/Model/GlobalDevice.cs | 15 ++ DosingSystem/Model/par/BasePar.cs | 40 +++--- DosingSystem/Service/SiemensDevice.cs | 8 ++ DosingSystem/View/CommParSetView.xaml | 5 +- DosingSystem/View/ConveyerBeltManualView.xaml | 132 ++++++++++++++++++ .../View/ConveyerBeltManualView.xaml.cs | 28 ++++ DosingSystem/View/HardwareStatusView.xaml | 6 +- DosingSystem/ViewModel/CommparSetViewModel.cs | 15 +- .../ViewModel/ConveyerBeltManualViewModel.cs | 29 ++++ .../ViewModel/HardwareStatusViewModel.cs | 33 ++--- .../ViewModel/RecipeControlViewModel.cs | 7 +- 23 files changed, 373 insertions(+), 133 deletions(-) create mode 100644 DosingSystem/View/ConveyerBeltManualView.xaml create mode 100644 DosingSystem/View/ConveyerBeltManualView.xaml.cs create mode 100644 DosingSystem/ViewModel/ConveyerBeltManualViewModel.cs diff --git a/BPASmart.ConfigurationSoftware/BPASmart.ConfigurationSoftware.csproj b/BPASmart.ConfigurationSoftware/BPASmart.ConfigurationSoftware.csproj index 382433bf..6f6fc9e1 100644 --- a/BPASmart.ConfigurationSoftware/BPASmart.ConfigurationSoftware.csproj +++ b/BPASmart.ConfigurationSoftware/BPASmart.ConfigurationSoftware.csproj @@ -20,7 +20,7 @@ - + diff --git a/BPASmart.PageLoad/BPASmart.PageLoad.csproj b/BPASmart.PageLoad/BPASmart.PageLoad.csproj index 115cd404..be4c76b2 100644 --- a/BPASmart.PageLoad/BPASmart.PageLoad.csproj +++ b/BPASmart.PageLoad/BPASmart.PageLoad.csproj @@ -8,7 +8,7 @@ - + diff --git a/BPASmart.Server/BPASmart.Server.csproj b/BPASmart.Server/BPASmart.Server.csproj index 6a75087c..f8531a3c 100644 --- a/BPASmart.Server/BPASmart.Server.csproj +++ b/BPASmart.Server/BPASmart.Server.csproj @@ -9,7 +9,7 @@ - + diff --git a/BPASmart.VariableManager/BPASmart.VariableManager.csproj b/BPASmart.VariableManager/BPASmart.VariableManager.csproj index 252e006a..5a7c760a 100644 --- a/BPASmart.VariableManager/BPASmart.VariableManager.csproj +++ b/BPASmart.VariableManager/BPASmart.VariableManager.csproj @@ -30,7 +30,7 @@ - + diff --git a/BPASmartClient.CustomResource/BPASmartClient.CustomResource.csproj b/BPASmartClient.CustomResource/BPASmartClient.CustomResource.csproj index 84783f76..2a67b414 100644 --- a/BPASmartClient.CustomResource/BPASmartClient.CustomResource.csproj +++ b/BPASmartClient.CustomResource/BPASmartClient.CustomResource.csproj @@ -409,7 +409,7 @@ - + diff --git a/BPASmartClient.Helper/ThreadManage.cs b/BPASmartClient.Helper/ThreadManage.cs index 479efa1a..8ba59126 100644 --- a/BPASmartClient.Helper/ThreadManage.cs +++ b/BPASmartClient.Helper/ThreadManage.cs @@ -47,41 +47,44 @@ namespace BPASmartClient.Helper /// public void StartLong(Action action, string key, bool IsRestart = false, Action RunComplete = null) { - CancellationTokenSources.TryAdd(guid + key, new CancellationTokenSource()); - bool result = Threads.TryAdd(guid + key, Task.Factory.StartNew(new Action(() => - { - Thread.CurrentThread.Name = key; - ReStart: - try - { - while (!CancellationTokenSources[guid + key].IsCancellationRequested) - { - if (action != null) action(); - } - } - catch (Exception ex) - { - MessageLog.GetInstance.ShowEx(ex.ToString()); - if (IsRestart) - { - Thread.Sleep(2000); - MessageLog.GetInstance.Show($"线程 【{key}】运行发生异常,已重启"); - goto ReStart; - } - else - { - CancellationTokenSources.TryRemove(guid + key, out CancellationTokenSource temp); - Threads.TryRemove(guid + key, out Task temp1); - MessageLog.GetInstance.Show($"线程 【{key}】运行发生异常,已退出"); - } - } - }), CancellationTokenSources[guid + key].Token).ContinueWith(new Action((t, o) => - { - ThreadStatus(t, o.ToString()); - if (RunComplete != null) RunComplete(); - }), guid + key)); - MessageLog.GetInstance.Show($"启动线程 【{key}】"); - if (!result) MessageLog.GetInstance.Show($"【{key}】任务已存在,请检查 TaskName"); + if (!Threads.ContainsKey(guid + key)) + { + CancellationTokenSources.TryAdd(guid + key, new CancellationTokenSource()); + bool result = Threads.TryAdd(guid + key, Task.Factory.StartNew(new Action(() => + { + Thread.CurrentThread.Name = key; + MessageLog.GetInstance.Show($"启动线程 【{key}】"); + ReStart: + try + { + while (!CancellationTokenSources[guid + key].IsCancellationRequested) + { + if (action != null) action(); + } + } + catch (Exception ex) + { + MessageLog.GetInstance.ShowEx(ex.ToString()); + if (IsRestart) + { + Thread.Sleep(2000); + MessageLog.GetInstance.Show($"线程 【{key}】运行发生异常,已重启"); + goto ReStart; + } + else + { + CancellationTokenSources.TryRemove(guid + key, out CancellationTokenSource temp); + Threads.TryRemove(guid + key, out Task temp1); + MessageLog.GetInstance.Show($"线程 【{key}】运行发生异常,已退出"); + } + } + }), CancellationTokenSources[guid + key].Token).ContinueWith(new Action((t, o) => + { + ThreadStatus(t, o.ToString()); + if (RunComplete != null) RunComplete(); + }), guid + key)); + } + else MessageLog.GetInstance.Show($"【{key}】任务已存在,请检查 TaskName"); } @@ -93,35 +96,38 @@ namespace BPASmartClient.Helper /// public void Start(Action action, string key, bool isRestart = false) { - CancellationTokenSources.TryAdd(guid + key, new CancellationTokenSource()); - bool result = Threads.TryAdd(guid + key, Task.Factory.StartNew(new Action(() => + if (!Threads.ContainsKey(guid + key)) { - Thread.CurrentThread.Name = key; - try - { - if (action != null) action(); - } - catch (Exception ex) + CancellationTokenSources.TryAdd(guid + key, new CancellationTokenSource()); + bool result = Threads.TryAdd(guid + key, Task.Factory.StartNew(new Action(() => { - MessageLog.GetInstance.ShowEx(ex.ToString()); - if (isRestart) + Thread.CurrentThread.Name = key; + MessageLog.GetInstance.Show($"启动线程 【{key}】"); + try { - MessageLog.GetInstance.Show($"线程 【{key}】正在重启"); - CancellationTokenSources.TryRemove(guid + key, out CancellationTokenSource item1); - Threads.TryRemove(guid + key, out Task item2); - Start(action, key, isRestart); + if (action != null) action(); } - else + catch (Exception ex) { - MessageLog.GetInstance.Show($"线程 【{key}】运行发生异常"); + MessageLog.GetInstance.ShowEx(ex.ToString()); + if (isRestart) + { + MessageLog.GetInstance.Show($"线程 【{key}】正在重启"); + CancellationTokenSources.TryRemove(guid + key, out CancellationTokenSource item1); + Threads.TryRemove(guid + key, out Task item2); + Start(action, key, isRestart); + } + else + { + MessageLog.GetInstance.Show($"线程 【{key}】运行发生异常"); + } } - } - }), CancellationTokenSources[guid + key].Token).ContinueWith(new Action((t, o) => - { - ThreadStatus(t, o.ToString()); - }), guid + key)); - MessageLog.GetInstance.Show($"启动线程 【{key}】"); - if (!result) MessageLog.GetInstance.Show($"【{key}】任务已存在,请检查 TaskName"); + }), CancellationTokenSources[guid + key].Token).ContinueWith(new Action((t, o) => + { + ThreadStatus(t, o.ToString()); + }), guid + key)); + } + else MessageLog.GetInstance.Show($"【{key}】任务已存在,请检查 TaskName"); } private void ThreadStatus(Task task, string key) diff --git a/BPASmartClient.S7Net/SiemensHelper.cs b/BPASmartClient.S7Net/SiemensHelper.cs index ae03de2b..4eef585d 100644 --- a/BPASmartClient.S7Net/SiemensHelper.cs +++ b/BPASmartClient.S7Net/SiemensHelper.cs @@ -52,13 +52,13 @@ namespace BPASmartClient.S7Net return default; } - private object Read(DataType dataType, int db, int address, VarType varType, int count) + public object Read(DataType dataType, int db, int address, VarType varType, int count) { if (!IsConnected) return default; return myPlc?.Read(dataType, db, address, varType, count); } - public string Write(string address, TValue value,int Retries = 1) + public string Write(string address, TValue value, int Retries = 1) { if (IsConnected) { @@ -68,7 +68,7 @@ namespace BPASmartClient.S7Net myPlc?.Write(address, value); return $"成功,地址:{address},值:{value}"; } - else + else { while (count < Retries) { @@ -83,7 +83,7 @@ namespace BPASmartClient.S7Net return $"成功,发送了{count}次,地址:{address},值:{value}"; } } - else + else { return $"失败,地址:{address},值:{value},断开连接"; } diff --git a/BPASmartClient.SmallBatchingSystem/BPASmartClient.SmallBatchingSystem.csproj b/BPASmartClient.SmallBatchingSystem/BPASmartClient.SmallBatchingSystem.csproj index b40e4922..d60d6756 100644 --- a/BPASmartClient.SmallBatchingSystem/BPASmartClient.SmallBatchingSystem.csproj +++ b/BPASmartClient.SmallBatchingSystem/BPASmartClient.SmallBatchingSystem.csproj @@ -22,7 +22,7 @@ - + diff --git a/ComputerTestDemo/ComputerTestDemo.csproj b/ComputerTestDemo/ComputerTestDemo.csproj index 26fa79a7..ae6b26da 100644 --- a/ComputerTestDemo/ComputerTestDemo.csproj +++ b/ComputerTestDemo/ComputerTestDemo.csproj @@ -10,7 +10,7 @@ - + diff --git a/DosingSystem/App.xaml.cs b/DosingSystem/App.xaml.cs index cebb3189..91056dfb 100644 --- a/DosingSystem/App.xaml.cs +++ b/DosingSystem/App.xaml.cs @@ -96,7 +96,7 @@ namespace BPASmartClient.DosingSystem ParSet.Add(new SubMenumodel() { - SubMenuName = "通讯参数设置", + SubMenuName = "设备控制参数设置", SubMenuPermission = new Permission[] { Permission.管理员 }, AssemblyName = "BPASmartClient.DosingSystem", ToggleWindowPath = "View.CommParSetView" @@ -123,11 +123,19 @@ namespace BPASmartClient.DosingSystem ObservableCollection ManualControl = new ObservableCollection(); ManualControl.Add(new SubMenumodel() { - SubMenuName = "手动控制", + SubMenuName = "气缸手动控制", SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.技术员 }, AssemblyName = "BPASmartClient.DosingSystem", ToggleWindowPath = "View.ManualControlView" }); + + ManualControl.Add(new SubMenumodel() + { + SubMenuName = "输送带手动控制", + SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.技术员 }, + AssemblyName = "BPASmartClient.DosingSystem", + ToggleWindowPath = "View.ConveyerBeltManualView" + }); //ManualControl.Add(new SubMenumodel() //{ // SubMenuName = "料仓控制", diff --git a/DosingSystem/BPASmartClient.DosingSystem.csproj b/DosingSystem/BPASmartClient.DosingSystem.csproj index df8df978..15315834 100644 --- a/DosingSystem/BPASmartClient.DosingSystem.csproj +++ b/DosingSystem/BPASmartClient.DosingSystem.csproj @@ -16,7 +16,7 @@ - + diff --git a/DosingSystem/Model/ConveyerBeltModel.cs b/DosingSystem/Model/ConveyerBeltModel.cs index 9b875670..f56dd3f8 100644 --- a/DosingSystem/Model/ConveyerBeltModel.cs +++ b/DosingSystem/Model/ConveyerBeltModel.cs @@ -15,10 +15,36 @@ namespace BPASmartClient.DosingSystem public int Num { get { return _mNum; } set { _mNum = value; OnPropertyChanged(); } } private int _mNum; - - public int Speed { get { return _mSpeed; } set { _mSpeed = value; OnPropertyChanged(); } } + public int Speed + { + get { return _mSpeed; } + set + { + _mSpeed = value; + if (Num >= 1 && Num <= 32) + { + SiemensDevice.GetInstance.MySiemens.Write($"DB4.DBW{Num * 2 + 132}", value); + } + OnPropertyChanged(); + } + } private int _mSpeed; + public bool ConveyerBeltWork + { + get { return _mConveyerBeltWork; } + set + { + _mConveyerBeltWork = value; + if (Num >= 1 && Num <= 32) + { + var add = SiemensDevice.GetInstance.GetSiemensBitSingleAdd("DB5.DBX", Num, 6); + SiemensDevice.GetInstance.MySiemens.Write(add, !value); + } + OnPropertyChanged(); + } + } + private bool _mConveyerBeltWork; public bool Control { get; set; } diff --git a/DosingSystem/Model/GlobalDevice.cs b/DosingSystem/Model/GlobalDevice.cs index 56e3f7fd..bbc78b27 100644 --- a/DosingSystem/Model/GlobalDevice.cs +++ b/DosingSystem/Model/GlobalDevice.cs @@ -13,5 +13,20 @@ namespace BPASmartClient.DosingSystem /// public static PlcToComputer PlcData { get; set; } = new PlcToComputer(); + /// + /// 电机速度 + /// + public static ushort[] MotorSpeed { get; set; } = new ushort[32]; + + /// + /// 输送带控制 + /// + public static uint MotorControl { get; set; } + + /// + /// 输送带控制反馈 + /// + public static uint MotorControlFeedback { get; set; } + } } diff --git a/DosingSystem/Model/par/BasePar.cs b/DosingSystem/Model/par/BasePar.cs index 0594f626..fb9f0b57 100644 --- a/DosingSystem/Model/par/BasePar.cs +++ b/DosingSystem/Model/par/BasePar.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -34,29 +35,20 @@ namespace BPASmartClient.DosingSystem set { _mConveyerBeltCount = value; - if (value == 0) App.Current.Dispatcher.Invoke(() => { ConveyerBeltModels.Clear(); }); - if (value > 0 && ConveyerBeltModels.Count <= 0) - { - for (int i = 0; i < value; i++) - { - App.Current.Dispatcher.Invoke(() => { ConveyerBeltModels.Add(new ConveyerBeltModel() { Name = $"输送带{i + 1}速度", Num = i + 1, Speed = 0 }); }); - } - } - if (value > ConveyerBeltModels.Count) - { - for (int i = value - ConveyerBeltModels.Count; i < value; i++) - { - App.Current.Dispatcher.Invoke(() => { ConveyerBeltModels.Add(new ConveyerBeltModel() { Name = $"输送带{i + 1}速度", Num = i + 1, Speed = 0 }); }); - } - } - if (value < ConveyerBeltModels.Count) - { - for (int i = value - 1; i < ConveyerBeltModels.Count; i++) - { - int index = ConveyerBeltModels.Count - 1; - if (index >= 0) App.Current.Dispatcher.Invoke(new Action(() => { ConveyerBeltModels.RemoveAt(index); })); - } - } + //var temp = ConveyerBeltModels; + //App.Current.Dispatcher.Invoke(() => { ConveyerBeltModels.Clear(); }); + //for (int i = 0; i < value; i++) + //{ + // App.Current.Dispatcher.Invoke(() => + // { + // ConveyerBeltModels.Add(new ConveyerBeltModel() + // { + // Name = $"输送带{i + 1}速度", + // Num = i + 1, + // Speed = (i >= 0 && i < temp.Count) ? temp.ElementAt(i).Speed : 0 + // }); + // }); + //} OnPropertyChanged(); } } @@ -80,7 +72,7 @@ namespace BPASmartClient.DosingSystem public int PalletCylinderCount { get { return _mPalletCylinderCount; } set { _mPalletCylinderCount = value; OnPropertyChanged(); } } private int _mPalletCylinderCount = 0; - public ObservableCollection ConveyerBeltModels { get; set; } = new ObservableCollection(); + //public ObservableCollection ConveyerBeltModels { get; set; } = new ObservableCollection(); } } diff --git a/DosingSystem/Service/SiemensDevice.cs b/DosingSystem/Service/SiemensDevice.cs index 533d2760..3187285d 100644 --- a/DosingSystem/Service/SiemensDevice.cs +++ b/DosingSystem/Service/SiemensDevice.cs @@ -6,6 +6,7 @@ using System.Threading; using System.Threading.Tasks; using BPASmartClient.S7Net; using BPA.Helper; +using S7.Net; namespace BPASmartClient.DosingSystem { @@ -38,6 +39,13 @@ namespace BPASmartClient.DosingSystem ThreadManage.GetInstance().StartLong(new Action(() => { GlobalDevice.PlcData = MySiemens.ReadClass(3);//获取PLC到上位机的数据 + var res = MySiemens.Read(DataType.DataBlock, 4, 134, VarType.Word, 32); + if (res != null && res is ushort[] ushorts && ushorts.Length == 32) + { + GlobalDevice.MotorSpeed = ushorts; + } + GlobalDevice.MotorControl = MySiemens.Read("DB5.DBD6");//获取输送带控制信号 + //GlobalDevice.MotorControlFeedback = MySiemens.Read("DB3.DBD0");//获取当前输送带运行状态 Thread.Sleep(50); }), "读取输送线设备数据", true); diff --git a/DosingSystem/View/CommParSetView.xaml b/DosingSystem/View/CommParSetView.xaml index 76c65b25..e12528e4 100644 --- a/DosingSystem/View/CommParSetView.xaml +++ b/DosingSystem/View/CommParSetView.xaml @@ -18,7 +18,6 @@ - @@ -170,7 +169,7 @@ - + diff --git a/DosingSystem/View/ConveyerBeltManualView.xaml b/DosingSystem/View/ConveyerBeltManualView.xaml new file mode 100644 index 00000000..baedb810 --- /dev/null +++ b/DosingSystem/View/ConveyerBeltManualView.xaml @@ -0,0 +1,132 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/DosingSystem/View/ConveyerBeltManualView.xaml.cs b/DosingSystem/View/ConveyerBeltManualView.xaml.cs new file mode 100644 index 00000000..181758ba --- /dev/null +++ b/DosingSystem/View/ConveyerBeltManualView.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace BPASmartClient.DosingSystem.View +{ + /// + /// ConveyerBeltManualView.xaml 的交互逻辑 + /// + public partial class ConveyerBeltManualView : UserControl + { + public ConveyerBeltManualView() + { + InitializeComponent(); + } + } +} diff --git a/DosingSystem/View/HardwareStatusView.xaml b/DosingSystem/View/HardwareStatusView.xaml index 761a2af9..2f1b7472 100644 --- a/DosingSystem/View/HardwareStatusView.xaml +++ b/DosingSystem/View/HardwareStatusView.xaml @@ -290,9 +290,9 @@ BeltDashThickess="50" BeltHeight="{Binding ElementName=gr, Path=ActualHeight}" BeltWidth="{Binding ElementName=gr, Path=ActualWidth}" - IsRun="{Binding ConveyerBeltWork}" /> + IsRun="{Binding ConveyerBeltStatus}" /> - - + --> diff --git a/DosingSystem/ViewModel/CommparSetViewModel.cs b/DosingSystem/ViewModel/CommparSetViewModel.cs index d7922267..805171cb 100644 --- a/DosingSystem/ViewModel/CommparSetViewModel.cs +++ b/DosingSystem/ViewModel/CommparSetViewModel.cs @@ -21,27 +21,22 @@ namespace BPASmartClient.DosingSystem.ViewModel var res = CommBaseParModel.NetworkSegAddress.Split("."); if (res != null) { - StringBuilder sb = new StringBuilder(); if (res.Length >= 3) { - for (int i = 0; i < 3; i++) - { - sb.Append($"{res[i]}."); - } + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < 3; i++) sb.Append($"{res[i]}."); Json.Data.BaseParModel.NetworkSegAddress = sb.ToString(); Json.Save(); NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"参数保存成功!"); } } + } }); - CommBaseParModel = Json.Data.BaseParModel; } - public BasePar CommBaseParModel { get { return _mCommBaseParModel; } set { _mCommBaseParModel = value; OnPropertyChanged(); } } - private BasePar _mCommBaseParModel; - - //public ObservableCollection ConveyerBeltModels { get; set; } = new ObservableCollection(); + public BasePar CommBaseParModel { get { return Json.Data.BaseParModel; } set { Json.Data.BaseParModel = value; OnPropertyChanged(); } } + //private BasePar _mCommBaseParModel; public RelayCommand SaveCommand { get; set; } diff --git a/DosingSystem/ViewModel/ConveyerBeltManualViewModel.cs b/DosingSystem/ViewModel/ConveyerBeltManualViewModel.cs new file mode 100644 index 00000000..a6bdf645 --- /dev/null +++ b/DosingSystem/ViewModel/ConveyerBeltManualViewModel.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using BPA.Helper; + +namespace BPASmartClient.DosingSystem.ViewModel +{ + public class ConveyerBeltManualViewModel : NotifyBase + { + public ConveyerBeltManualViewModel() + { + for (int i = 0; i < Json.Data.BaseParModel.ConveyerBeltCount; i++) + { + ConveyerBeltModels.Add(new ConveyerBeltModel() + { + Name = $"输送带{i + 1}控制", + Num = i + 1, + Speed = GlobalDevice.MotorSpeed[i], + ConveyerBeltWork = GlobalDevice.MotorControl.GetBitValue((byte)(i + 1)) + }); + } + } + + public ObservableCollection ConveyerBeltModels { get; set; } = new ObservableCollection(); + } +} diff --git a/DosingSystem/ViewModel/HardwareStatusViewModel.cs b/DosingSystem/ViewModel/HardwareStatusViewModel.cs index 83eb6f02..1460524f 100644 --- a/DosingSystem/ViewModel/HardwareStatusViewModel.cs +++ b/DosingSystem/ViewModel/HardwareStatusViewModel.cs @@ -18,23 +18,23 @@ namespace BPASmartClient.DosingSystem.ViewModel TopDeviceCurrentStatuses = DeviceInquire.GetInstance.TopDeviceCurrentStatuses; BottomDeviceCurrentStatuses = DeviceInquire.GetInstance.BottomDeviceCurrentStatuses; - for (int i = 0; i < Json.Data.BaseParModel.ConveyerBeltCount; i++) - { - ConveyerBeltModels.Add(new ConveyerBeltModel() { Name = $"输送带{i}", Num = i++ }); - } + //for (int i = 0; i < Json.Data.BaseParModel.ConveyerBeltCount; i++) + //{ + // ConveyerBeltModels.Add(new ConveyerBeltModel() { Name = $"输送带{i}", Num = i++ }); + //} - ConveyerBeltControlCommand = new RelayCommand(o => - { - if (o != null && o is int tempCount) - { - string add = SiemensDevice.GetInstance.GetSiemensBitSingleAdd("DB5.DBX", tempCount, 6); - int index = ConveyerBeltModels.ToList().FindIndex(p => p.Num == tempCount); - if (index >= 0 && index < ConveyerBeltModels.Count) - { - SiemensDevice.GetInstance.MySiemens.Write(add, !ConveyerBeltModels.ElementAt(index).Control); - } - } - }); + //ConveyerBeltControlCommand = new RelayCommand(o => + //{ + // if (o != null && o is int tempCount) + // { + // string add = SiemensDevice.GetInstance.GetSiemensBitSingleAdd("DB5.DBX", tempCount, 6); + // int index = ConveyerBeltModels.ToList().FindIndex(p => p.Num == tempCount); + // if (index >= 0 && index < ConveyerBeltModels.Count) + // { + // SiemensDevice.GetInstance.MySiemens.Write(add, !ConveyerBeltModels.ElementAt(index).Control); + // } + // } + //}); ThreadManage.GetInstance().StartLong(new Action(() => { for (int i = 0; i < Json.Data.OutletInfoModels.Count; i++) @@ -56,6 +56,7 @@ namespace BPASmartClient.DosingSystem.ViewModel } OnDetection = GlobalDevice.PlcData.OnDetection; UnderDetection = GlobalDevice.PlcData.UnderDetection; + ConveyerBeltStatus = GlobalDevice.MotorControlFeedback > 0; Thread.Sleep(100); }), "输送带料仓状态监控"); } diff --git a/DosingSystem/ViewModel/RecipeControlViewModel.cs b/DosingSystem/ViewModel/RecipeControlViewModel.cs index e20ca786..c9bb2756 100644 --- a/DosingSystem/ViewModel/RecipeControlViewModel.cs +++ b/DosingSystem/ViewModel/RecipeControlViewModel.cs @@ -200,10 +200,11 @@ namespace BPASmartClient.DosingSystem.ViewModel int index = recipeProcesses.ElementAt(recIndex).RawMaterials.ToList().FindIndex(p => p.RawMaterialName == tempRawMaterialName); if (index >= 0 && index < recipeProcesses.ElementAt(recIndex).RawMaterials.Count) { - App.Current.Dispatcher.Invoke(new Action(() => { recipeProcesses.ElementAt(recIndex).RawMaterials.ElementAt(index).RecipeStatus = RunStatus; })); + recipeProcesses.ElementAt(recIndex).RawMaterials.ElementAt(index).RecipeStatus = RunStatus; + //App.Current?.Dispatcher?.Invoke(new Action(() => { recipeProcesses.ElementAt(recIndex).RawMaterials.ElementAt(index).RecipeStatus = RunStatus; })); } //App.Current.Dispatcher.Invoke(new Action(() => { recipeProcesses.ElementAt(index).RecipeStatus = RunStatus; })); - for (int j = 0; j < GlobalDevice.PlcData.IsAllowIngredients.Length; j++) + for (int j = 0; j < GlobalDevice.PlcData.IsAllowIngredients.Length; j++) { if (GlobalDevice.PlcData.IsAllowIngredients[j]) { @@ -229,7 +230,7 @@ namespace BPASmartClient.DosingSystem.ViewModel } } } - if (RawMaterialNameFinish.Count>= Recipes.ElementAt(i).RawMaterials.Count) //配方配料完成 + if (RawMaterialNameFinish.Count >= Recipes.ElementAt(i).RawMaterials.Count) //配方配料完成 { RawMaterialNameFinish.Clear(); int recipIndex = Array.FindIndex(Recipes.ToArray(), p => p.RecipeName == CurrentRecipeName);