Bladeren bron

1. 修改一些显示BUG和 更正异步方法的命名。2. 加载物料和配方清单修改为异步调用。

master
Nah 1 jaar geleden
bovenliggende
commit
bd47f4355a
16 gewijzigde bestanden met toevoegingen van 82 en 89 verwijderingen
  1. +3
    -2
      BPA.Model/RecipeInfo.cs
  2. +1
    -0
      BPA.SingleDevice.sln
  3. +4
    -3
      BPA.SingleDevice/App.xaml.cs
  4. +1
    -1
      BPA.SingleDevice/Business/Batcher.cs
  5. +1
    -1
      BPA.SingleDevice/Business/Conveyer.cs
  6. +15
    -60
      BPA.SingleDevice/Business/ProcessControl.cs
  7. +1
    -1
      BPA.SingleDevice/Interface/IBatchcer.cs
  8. +1
    -1
      BPA.SingleDevice/Interface/IConveyer.cs
  9. +1
    -1
      BPA.SingleDevice/Interface/IProcessControl.cs
  10. +2
    -1
      BPA.SingleDevice/View/OrderMainView.xaml
  11. +2
    -2
      BPA.SingleDevice/View/RecipeManagementView.xaml
  12. +3
    -1
      BPA.SingleDevice/View/RecipeManagementView.xaml.cs
  13. +1
    -0
      BPA.SingleDevice/ViewModel/DebugViewModel.cs
  14. +18
    -10
      BPA.SingleDevice/ViewModel/NewRecipeViewModel.cs
  15. +23
    -5
      BPA.SingleDevice/ViewModel/RecipeManagementViewModel.cs
  16. +5
    -0
      README.md

+ 3
- 2
BPA.Model/RecipeInfo.cs Bestand weergeven

@@ -32,10 +32,11 @@ namespace BPA.Model
{
if (_mIsEnable != value)
{
_mIsEnable = value;
OnPropertyChanged();
EnableChange?.Invoke(Id);
}
_mIsEnable = value;
OnPropertyChanged();
}
}
private bool _mIsEnable = true;


+ 1
- 0
BPA.SingleDevice.sln Bestand weergeven

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


+ 4
- 3
BPA.SingleDevice/App.xaml.cs Bestand weergeven

@@ -38,15 +38,15 @@ namespace BPA.SingleDevice

#region 注册调试日志。

ILogService logService = App.Current.Services.GetService<ILogService>();
ILogService logService = App.Current.Services.GetService<ILogService>()!;
MessageLog.GetInstance.NotifyShow = (string str) =>
{
logService.LogDebugInfo(str);
logService?.LogDebugInfo(str);
};

#endregion 注册调试日志。

Current.Services.GetService<IProcessControl>().Inital();
Current.Services.GetService<IProcessControl>()?.InitalAsync();
MainView mv = new MainView();
mv.Show();
}
@@ -67,6 +67,7 @@ namespace BPA.SingleDevice

services.AddTransient<RawMaterialManagementViewModel>();
services.AddTransient<OrderMainViewModel>();
services.AddTransient<RecipeManagementViewModel>();

//services.AddSingleton<ParamsSetViewModel>();
services.AddSingleton<RunLogViewModel>();


+ 1
- 1
BPA.SingleDevice/Business/Batcher.cs Bestand weergeven

@@ -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(() =>
{


+ 1
- 1
BPA.SingleDevice/Business/Conveyer.cs Bestand weergeven

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


+ 15
- 60
BPA.SingleDevice/Business/ProcessControl.cs Bestand weergeven

@@ -29,7 +29,7 @@ namespace BPA.SingleDevice.Business
//CancellationTokenSource cts;

//Task runTask;
public async void Inital()
public async Task InitalAsync()
{
Json<ConnectConfig>.Read();
if (Json<ConnectConfig>.Data.BatcherConfigs.Count == 0)
@@ -42,58 +42,16 @@ namespace BPA.SingleDevice.Business
InitConveyerConfig();
Json<ConnectConfig>.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<ConnectConfig>.Data.BatcherConfigs);

#endregion 实例初始化配料机

//Conveyer.SetCommParam(1, "192.168.6.104", 508);
//Conveyer.SetCommParam(1, "127.0.0.1",510);
//await Conveyer.Initial();

InitalConveyer(Json<ConnectConfig>.Data.ConveyerConfigs);

CurrentRecipes.Clear();
ActionRegister();

await InitalConveyerAsync(Json<ConnectConfig>.Data.ConveyerConfigs);
await InitalBatcherAsync(Json<ConnectConfig>.Data.BatcherConfigs);

TaskManage.GetInstance.StartLong(() =>
{
InterActive();

//ActionManage.GetInstance.Register(new Func<RecipeData,bool>((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

/// <summary>初始化配料机。</summary>
/// <param name="configs"></param>
private async void InitalBatcher(IList<BatcherConfig> configs)
private async Task InitalBatcherAsync(IList<BatcherConfig> configs)
{
if (configs is null || configs.Count == 0)
{
throw new ArgumentNullException("配置数据为Null");
}
List<Task> 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<ConveyerConfig> configs)
private async Task InitalConveyerAsync(IList<ConveyerConfig> 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();
}

}
/// <summary>刷新配方的当前工站。</summary>
private void UpdateRecipe()


+ 1
- 1
BPA.SingleDevice/Interface/IBatchcer.cs Bestand weergeven

@@ -31,6 +31,6 @@
bool ResetCompleted();

/// <summary>设备初始化</summary>
Task Initial();
Task InitialAsync();
}
}

+ 1
- 1
BPA.SingleDevice/Interface/IConveyer.cs Bestand weergeven

@@ -33,7 +33,7 @@
bool AllowMove { get; set; }

/// <summary>设备初始化</summary>
Task Initial();
Task InitialAsync();

/// <summary>设置通讯参数</summary>
void SetCommParam(int id, string ip, int port = 502);


+ 1
- 1
BPA.SingleDevice/Interface/IProcessControl.cs Bestand weergeven

@@ -5,7 +5,7 @@ namespace BPA.SingleDevice.Interface
public interface IProcessControl
{
/// <summary>初始化即开始。</summary>
void Inital();
Task InitalAsync();

ObservableCollection<RecipeData> CurrentRecipes { get; set; }



+ 2
- 1
BPA.SingleDevice/View/OrderMainView.xaml Bestand weergeven

@@ -36,7 +36,8 @@
<RowDefinition />
</Grid.RowDefinitions>
<!-- 图片 -->
<Border Width="120" Background="Gray" />
<!--<Border Width="120" Background="Gray" />-->
<bpa:Icon Type="RestaurantFill" Width="120"/>
<TextBlock
Grid.Row="1"
HorizontalAlignment="Center"


+ 2
- 2
BPA.SingleDevice/View/RecipeManagementView.xaml Bestand weergeven

@@ -11,9 +11,9 @@
d:DesignWidth="800"
mc:Ignorable="d">

<UserControl.DataContext>
<!--<UserControl.DataContext>
<vm:RecipeManagementViewModel />
</UserControl.DataContext>
</UserControl.DataContext>-->

<bpa:DialogContainer>
<Grid Margin="10">


+ 3
- 1
BPA.SingleDevice/View/RecipeManagementView.xaml.cs Bestand weergeven

@@ -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<RecipeManagementViewModel>();
}
}
}

+ 1
- 0
BPA.SingleDevice/ViewModel/DebugViewModel.cs Bestand weergeven

@@ -55,6 +55,7 @@ namespace BPA.SingleDevice.ViewModel
Json<ConnectConfig>.Data.MoveLength = MoveLength;
Json<ConnectConfig>.Data.MoveSpeed = MoveSpeed;
Json<ConnectConfig>.Save();
logService.LogUserInfo("写入流水线参数并保存到文件。");
Message.SuccessGlobal("写入流水线参数并保存到文件成功。");
}
else


+ 18
- 10
BPA.SingleDevice/ViewModel/NewRecipeViewModel.cs Bestand weergeven

@@ -6,18 +6,26 @@ namespace BPA.SingleDevice.ViewModel
{
public NewRecipeViewModel()
{
Task.Run(() =>
//Task.Run(() =>
//{
// SqlHelper.GetInstance.GetListAsync<RawMaterTB>().Result.OnSuccess(s =>
// {
// App.Current.Dispatcher.Invoke(() =>
// {
// s.ForEach(item =>
// {
// NewRecipeModels.Add(new NewRecipeModel() { Name = item.Name, Id = item.Id });

// });
// });
// });
//});

SqlHelper.GetInstance.GetListAsync<RawMaterTB>().Result.OnSuccess(s =>
{
SqlHelper.GetInstance.GetListAsync<RawMaterTB>().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 });
});
});



+ 23
- 5
BPA.SingleDevice/ViewModel/RecipeManagementViewModel.cs Bestand weergeven

@@ -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<RecipeRawMaterTB> rrmtb = new List<RecipeRawMaterTB>();
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<RecipeTB>(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<RecipeInfo> RecipeInfos { get; set; } = new ObservableCollection<RecipeInfo>();


+ 5
- 0
README.md Bestand weergeven

@@ -1,5 +1,10 @@
# BPA.SingleDevice

### 2023.10.25
1. 修改一些显示BUG和 更正异步方法的命名。
2. 加载物料和配方清单修改为异步调用。

### 2023.10.18:

1. 删除配方管理和物料管理的复制按钮。


Laden…
Annuleren
Opslaan