diff --git a/BPA.Model/RecipeInfo.cs b/BPA.Model/RecipeInfo.cs index d3a4052..62a34e2 100644 --- a/BPA.Model/RecipeInfo.cs +++ b/BPA.Model/RecipeInfo.cs @@ -32,10 +32,11 @@ namespace BPA.Model { if (_mIsEnable != value) { + _mIsEnable = value; + OnPropertyChanged(); EnableChange?.Invoke(Id); } - _mIsEnable = value; - OnPropertyChanged(); + } } private bool _mIsEnable = true; diff --git a/BPA.SingleDevice.sln b/BPA.SingleDevice.sln index 68dd91c..dcdfc24 100644 --- a/BPA.SingleDevice.sln +++ b/BPA.SingleDevice.sln @@ -12,6 +12,7 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{1C56EB4D-1297-4B33-9408-FAB3D8EBCACF}" ProjectSection(SolutionItems) = preProject .editorconfig = .editorconfig + README.md = README.md EndProjectSection EndProject Global diff --git a/BPA.SingleDevice/App.xaml.cs b/BPA.SingleDevice/App.xaml.cs index d83f37d..5e6289b 100644 --- a/BPA.SingleDevice/App.xaml.cs +++ b/BPA.SingleDevice/App.xaml.cs @@ -38,15 +38,15 @@ namespace BPA.SingleDevice #region 注册调试日志。 - ILogService logService = App.Current.Services.GetService(); + ILogService logService = App.Current.Services.GetService()!; MessageLog.GetInstance.NotifyShow = (string str) => { - logService.LogDebugInfo(str); + logService?.LogDebugInfo(str); }; #endregion 注册调试日志。 - Current.Services.GetService().Inital(); + Current.Services.GetService()?.InitalAsync(); MainView mv = new MainView(); mv.Show(); } @@ -67,6 +67,7 @@ namespace BPA.SingleDevice services.AddTransient(); services.AddTransient(); + services.AddTransient(); //services.AddSingleton(); services.AddSingleton(); diff --git a/BPA.SingleDevice/Business/Batcher.cs b/BPA.SingleDevice/Business/Batcher.cs index b9c4abd..2487a33 100644 --- a/BPA.SingleDevice/Business/Batcher.cs +++ b/BPA.SingleDevice/Business/Batcher.cs @@ -14,7 +14,7 @@ namespace BPA.SingleDevice.Business private int port = 502; private ModbusTcp modbus = new(); - public async Task Initial() + public async Task InitialAsync() { await Task.Run(() => { diff --git a/BPA.SingleDevice/Business/Conveyer.cs b/BPA.SingleDevice/Business/Conveyer.cs index 3036aee..5a8d7df 100644 --- a/BPA.SingleDevice/Business/Conveyer.cs +++ b/BPA.SingleDevice/Business/Conveyer.cs @@ -24,7 +24,7 @@ namespace BPA.SingleDevice.Business private int port = 508; private ModbusTcp modbus = new(); - public async Task Initial() + public async Task InitialAsync() { //因为设备中间有个空位。虽然是4台设备,但是需要设置5个位置。 HaveVessel = new bool[5]; diff --git a/BPA.SingleDevice/Business/ProcessControl.cs b/BPA.SingleDevice/Business/ProcessControl.cs index 8315490..3c037bb 100644 --- a/BPA.SingleDevice/Business/ProcessControl.cs +++ b/BPA.SingleDevice/Business/ProcessControl.cs @@ -29,7 +29,7 @@ namespace BPA.SingleDevice.Business //CancellationTokenSource cts; //Task runTask; - public async void Inital() + public async Task InitalAsync() { Json.Read(); if (Json.Data.BatcherConfigs.Count == 0) @@ -42,58 +42,16 @@ namespace BPA.SingleDevice.Business InitConveyerConfig(); Json.Save(); } - - #region 实例初始化配料机 - - //Batchers.TryAdd(1, new Batcher()); - //Batchers.TryAdd(2, new Batcher()); - //Batchers.TryAdd(4, new Batcher()); - //Batchers.TryAdd(5, new Batcher()); - - //SetBatcherComm(1, "192.168.6.100"); - //SetBatcherComm(2, "192.168.6.101"); - //SetBatcherComm(4, "192.168.6.102"); - //SetBatcherComm(5, "192.168.6.103"); - - //SetBatcherComm(1, "127.0.0.1", 503); - //SetBatcherComm(2, "127.0.0.1", 504); - //SetBatcherComm(4, "127.0.0.1", 505); - //SetBatcherComm(5, "127.0.0.1", 506); - //foreach (var batcher in Batchers.Values) - //{ - // await batcher.Initial(); - //} - - InitalBatcher(Json.Data.BatcherConfigs); - - #endregion 实例初始化配料机 - - //Conveyer.SetCommParam(1, "192.168.6.104", 508); - //Conveyer.SetCommParam(1, "127.0.0.1",510); - //await Conveyer.Initial(); - - InitalConveyer(Json.Data.ConveyerConfigs); - CurrentRecipes.Clear(); ActionRegister(); + await InitalConveyerAsync(Json.Data.ConveyerConfigs); + await InitalBatcherAsync(Json.Data.BatcherConfigs); + TaskManage.GetInstance.StartLong(() => { InterActive(); - //ActionManage.GetInstance.Register(new Func((RecipeData recipe) => - //{ - // if (CurrentRecipes.Contains(recipe)) - // { - // CurrentRecipes.Remove(recipe); - // return true; - // } - // else - // { - // return false; - // } - //}), "RemoveRecipe", true); - #region 移除配方 for (int i = 0; i < CurrentRecipes.Count; i++) @@ -294,8 +252,8 @@ namespace BPA.SingleDevice.Business case MoveConveyerStep.Moveing: if (moveCompleteTrig) { - logService.LogRunInfo($"控制传送带移动结束,复位传送带移动指令,开始更新配方工位。"); Conveyer.InitalMoveParam(); + logService.LogRunInfo($"控制传送带移动结束,复位传送带移动指令和移动结束信号,开始更新配方工位。"); global.MoveConveyerStep = MoveConveyerStep.MoveComplete; } break; @@ -426,39 +384,36 @@ namespace BPA.SingleDevice.Business /// 初始化配料机。 /// - private async void InitalBatcher(IList configs) + private async Task InitalBatcherAsync(IList configs) { if (configs is null || configs.Count == 0) { throw new ArgumentNullException("配置数据为Null"); } + List tasks = new(); foreach (var item in configs) { if (item.IsConnect) { Batchers.TryAdd(item.StationID, new Batcher()); SetBatcherComm(item.StationID, item.IP, item.Port); + tasks.Add(Batchers[item.StationID].InitialAsync()); } } - foreach (var batcher in Batchers.Values) - { - await batcher.Initial(); - } } - private async void InitalConveyer(IList configs) + private async Task InitalConveyerAsync(IList configs) { - if (configs is null || configs.Count==0) + if (configs is null || configs.Count == 0) { throw new ArgumentNullException("配置数据为Null"); } - foreach (var item in configs) + var item = configs.ElementAt(0); + if (item is not null && item.IsConnect) { - if (item.IsConnect) - { - Conveyer.SetCommParam(item.ID, item.IP, item.Port); - await Conveyer.Initial(); - } + Conveyer.SetCommParam(item.ID, item.IP, item.Port); + await Conveyer.InitialAsync(); } + } /// 刷新配方的当前工站。 private void UpdateRecipe() diff --git a/BPA.SingleDevice/Interface/IBatchcer.cs b/BPA.SingleDevice/Interface/IBatchcer.cs index ed53016..60f571a 100644 --- a/BPA.SingleDevice/Interface/IBatchcer.cs +++ b/BPA.SingleDevice/Interface/IBatchcer.cs @@ -31,6 +31,6 @@ bool ResetCompleted(); /// 设备初始化 - Task Initial(); + Task InitialAsync(); } } \ No newline at end of file diff --git a/BPA.SingleDevice/Interface/IConveyer.cs b/BPA.SingleDevice/Interface/IConveyer.cs index 3e3a2c4..1932f80 100644 --- a/BPA.SingleDevice/Interface/IConveyer.cs +++ b/BPA.SingleDevice/Interface/IConveyer.cs @@ -33,7 +33,7 @@ bool AllowMove { get; set; } /// 设备初始化 - Task Initial(); + Task InitialAsync(); /// 设置通讯参数 void SetCommParam(int id, string ip, int port = 502); diff --git a/BPA.SingleDevice/Interface/IProcessControl.cs b/BPA.SingleDevice/Interface/IProcessControl.cs index 8f6969a..cb4656f 100644 --- a/BPA.SingleDevice/Interface/IProcessControl.cs +++ b/BPA.SingleDevice/Interface/IProcessControl.cs @@ -5,7 +5,7 @@ namespace BPA.SingleDevice.Interface public interface IProcessControl { /// 初始化即开始。 - void Inital(); + Task InitalAsync(); ObservableCollection CurrentRecipes { get; set; } diff --git a/BPA.SingleDevice/View/OrderMainView.xaml b/BPA.SingleDevice/View/OrderMainView.xaml index 9b6c25a..4816aea 100644 --- a/BPA.SingleDevice/View/OrderMainView.xaml +++ b/BPA.SingleDevice/View/OrderMainView.xaml @@ -36,7 +36,8 @@ - + + - + diff --git a/BPA.SingleDevice/View/RecipeManagementView.xaml.cs b/BPA.SingleDevice/View/RecipeManagementView.xaml.cs index aa92c1e..7d85f66 100644 --- a/BPA.SingleDevice/View/RecipeManagementView.xaml.cs +++ b/BPA.SingleDevice/View/RecipeManagementView.xaml.cs @@ -1,4 +1,5 @@ -using System.Windows.Controls; +using Microsoft.Extensions.DependencyInjection; +using System.Windows.Controls; namespace BPA.SingleDevice.View { @@ -8,6 +9,7 @@ namespace BPA.SingleDevice.View public RecipeManagementView() { InitializeComponent(); + this.DataContext = App.Current.Services.GetService(); } } } \ No newline at end of file diff --git a/BPA.SingleDevice/ViewModel/DebugViewModel.cs b/BPA.SingleDevice/ViewModel/DebugViewModel.cs index b356975..a415cf7 100644 --- a/BPA.SingleDevice/ViewModel/DebugViewModel.cs +++ b/BPA.SingleDevice/ViewModel/DebugViewModel.cs @@ -55,6 +55,7 @@ namespace BPA.SingleDevice.ViewModel Json.Data.MoveLength = MoveLength; Json.Data.MoveSpeed = MoveSpeed; Json.Save(); + logService.LogUserInfo("写入流水线参数并保存到文件。"); Message.SuccessGlobal("写入流水线参数并保存到文件成功。"); } else diff --git a/BPA.SingleDevice/ViewModel/NewRecipeViewModel.cs b/BPA.SingleDevice/ViewModel/NewRecipeViewModel.cs index 2e52083..53a17dc 100644 --- a/BPA.SingleDevice/ViewModel/NewRecipeViewModel.cs +++ b/BPA.SingleDevice/ViewModel/NewRecipeViewModel.cs @@ -6,18 +6,26 @@ namespace BPA.SingleDevice.ViewModel { public NewRecipeViewModel() { - Task.Run(() => + //Task.Run(() => + //{ + // SqlHelper.GetInstance.GetListAsync().Result.OnSuccess(s => + // { + // App.Current.Dispatcher.Invoke(() => + // { + // s.ForEach(item => + // { + // NewRecipeModels.Add(new NewRecipeModel() { Name = item.Name, Id = item.Id }); + + // }); + // }); + // }); + //}); + + SqlHelper.GetInstance.GetListAsync().Result.OnSuccess(s => { - SqlHelper.GetInstance.GetListAsync().Result.OnSuccess(s => + s.ForEach(item => { - App.Current.Dispatcher.Invoke(() => - { - s.ForEach(item => - { - NewRecipeModels.Add(new NewRecipeModel() { Name = item.Name, Id = item.Id }); - - }); - }); + NewRecipeModels.Add(new NewRecipeModel() { Name = item.Name, Id = item.Id }); }); }); diff --git a/BPA.SingleDevice/ViewModel/RecipeManagementViewModel.cs b/BPA.SingleDevice/ViewModel/RecipeManagementViewModel.cs index 911351a..cc0aaae 100644 --- a/BPA.SingleDevice/ViewModel/RecipeManagementViewModel.cs +++ b/BPA.SingleDevice/ViewModel/RecipeManagementViewModel.cs @@ -1,8 +1,13 @@ -namespace BPA.SingleDevice.ViewModel +using BPA.SingleDevice.Services; +using System.Xml.Linq; + +namespace BPA.SingleDevice.ViewModel { public class RecipeManagementViewModel : NotifyBase { - public RecipeManagementViewModel() + private readonly ILogService logService; + + public RecipeManagementViewModel(ILogService logService) { Task.Run(() => { @@ -40,6 +45,7 @@ IsEnable = true, }).Result.OnSuccess(() => { + logService.LogUserInfo($"新增配方【{name}】成功。"); List rrmtb = new List(); rms.ForEach(item => { @@ -48,8 +54,17 @@ SqlHelper.GetInstance.AddAsync(rrmtb).Result.OnSuccess(() => { RecipeInfos.Add(new RecipeInfo() { Id = id, IsEnable = true, LastModified = time, Name = name }); - }).OnFail(s => { Message.Error("RecipeManagementView", $"添加失败:{s}"); }); - }).OnFail(s => { Message.Error("RecipeManagementView", $"添加失败:{s}"); }); + logService.LogUserInfo($"新增配方【{name}】的物料信息成功。"); + }).OnFail(s => + { + Message.Error("RecipeManagementView", $"添加失败:{s}"); + logService.LogDebugInfo($"新增配方【{name}】的物料信息失败,信息:【{s}】。"); + }); + }).OnFail(s => + { + Message.Error("RecipeManagementView", $"添加失败:{s}"); + logService.LogDebugInfo($"新增配方【{name}】失败,信息:【{s}】。"); + }); } } }); @@ -101,6 +116,7 @@ { RecipeInfos[index].Name = name; RecipeInfos[index].LastModified = time; + logService.LogUserInfo($"修改配方【{name}】成功。"); }).OnFail(s => { Message.Error("RecipeManagementView", $"更新添加失败:{s}"); }); }).OnFail(s => { Message.Error("RecipeManagementView", $"更新时删除失败:{s}"); }); }).OnFail(s => { Message.Error("RecipeManagementView", $"更新失败:{s}"); }); @@ -118,7 +134,7 @@ var index = RecipeInfos.ToList().FindIndex(p => p.Id == o.ToString()); if (index >= 0) { - var result = await MessageBoxR.Confirm("是否删除改数据?"); + var result = await MessageBoxR.Confirm("是否删除该数据?"); if (result == System.Windows.MessageBoxResult.Yes) { SqlHelper.GetInstance.DeleteAsync(o.ToString()).OnSuccess(() => @@ -126,6 +142,7 @@ SqlHelper.GetInstance.DeleteRawMaterAsync(o.ToString()).OnSuccess(() => { RecipeInfos.RemoveAt(index); + logService.LogUserInfo($"删除配方【{o.ToString()}】成功。"); }).OnFail(s => { Message.Error("RawMaterialManagementView", $"删除失败:{s}"); }); }).OnFail(s => { Message.Error("RawMaterialManagementView", $"删除失败:{s}"); }); } @@ -151,6 +168,7 @@ }).OnFail(s => { Message.Error("RecipeManagementView", $"更新失败:{s}"); }); } }); + this.logService = logService; } public ObservableCollection RecipeInfos { get; set; } = new ObservableCollection(); diff --git a/README.md b/README.md index d66b3e2..30ac7d8 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,10 @@ # BPA.SingleDevice +### 2023.10.25 +1. 修改一些显示BUG和 更正异步方法的命名。 +2. 加载物料和配方清单修改为异步调用。 + ### 2023.10.18: 1. 删除配方管理和物料管理的复制按钮。 +