增加ControlNo展示

This commit is contained in:
anerx 2025-03-17 02:37:39 +08:00
parent 886a385ddf
commit d1631df129
8 changed files with 88 additions and 18 deletions

View File

@ -4,6 +4,7 @@ namespace Seyounth.Hyosung.Data.Models;
public class Variety
{
public int ControlNo { get; set; }
public string Name => $"{Id} - {Code} - {StackingLayers}";
public int Id { get; set; }

View File

@ -1,4 +1,5 @@
using System.Collections.Concurrent;
using System.Collections.ObjectModel;
using Microsoft.Extensions.Logging;
using Seyounth.Hyosung.Core.Agv;
using Seyounth.Hyosung.Core.Plc;
@ -8,6 +9,7 @@ using Seyounth.Hyosung.Data.Models;
using Seyounth.Hyosung.Data.Models.Plc;
using Seyounth.Hyosung.Data.Services;
using Seyounth.Hyosung.Data.Services.Hyosung;
using Seyounth.Hyosung.Runtime.Models;
namespace Seyounth.Hyosung.Runtime;
@ -22,11 +24,13 @@ public class HyosungRuntime(
IHyosungAgvService hyosungAgvService,
IHyosungWmsService hyosungWmsService) : IHyosungRuntime
{
public StackStationModel Stack1 { get; private set; } = new();
public StackStationModel Stack2 { get; private set; } = new();
public async Task StartAsync(CancellationToken token)
{
//启动扫码服务
await hyosungScannerService.StartAsync(token);
await printer.StartAsync(token);
//最后启动PLC服务
hyosungPlcService.OnPlcRequestScanProduct += OnPlcRequestScanProduct;
hyosungPlcService.OnPlcRequestScanFixture += OnPlcRequestScanFixture;
@ -41,7 +45,7 @@ public class HyosungRuntime(
public async Task StopAsync(CancellationToken token)
{
//先停止扫码服务
// await hyosungScannerService.StopAsync(token);
// await hyosungScannerService.StopAsync(token);
await printer.StopAsync(token);
//先停止PLC服务
//解绑相关事件
@ -126,6 +130,23 @@ public class HyosungRuntime(
private async Task OnPlcNeedNewTrayCode(int index, int varietyId)
{
var tray = await trayService.GeneraNewTray(varietyId);
var variety = await varietyService.GetById(varietyId);
var stackModel = new StackStationModel();
stackModel.TrayCode = tray.TrayCode;
stackModel.VarietyCode = variety.Code;
stackModel.Layers = variety.StackingLayers;
stackModel.TotalCount = variety.TotalCount;
stackModel.CurrentCount = 0;
stackModel.Yarns = new ObservableCollection<Yarn>();
if (index == 1)
{
Stack1 = stackModel;
}
else
{
Stack2 = stackModel;
}
await hyosungPlcService.WriteTrayCodeAsync(index, tray.TrayCode);
}
@ -137,6 +158,23 @@ public class HyosungRuntime(
/// <exception cref="NotImplementedException"></exception>
private async Task OnPlcPutCompleted(PlcStackingInfo arg)
{
if (arg.TrayCode == Stack1.TrayCode)
{
Stack1.CurrentCount += arg.YarnCode.Count;
foreach (var yarnCode in arg.YarnCode)
{
Stack1.Yarns.Add(await yarnService.GetYarnByCodeAsync(yarnCode));
}
}
else if (arg.TrayCode == Stack2.TrayCode)
{
Stack2.CurrentCount += arg.YarnCode.Count;
foreach (var yarnCode in arg.YarnCode)
{
Stack2.Yarns.Add(await yarnService.GetYarnByCodeAsync(yarnCode));
}
}
foreach (var yarnCode in arg.YarnCode)
{
await yarnService.BindTrayAsync(yarnCode, await trayService.GetIdByCode(arg.TrayCode));

View File

@ -1,10 +1,14 @@
using System.Collections.Concurrent;
using Seyounth.Hyosung.Data.Models;
using Seyounth.Hyosung.Runtime.Models;
namespace Seyounth.Hyosung.Runtime;
public interface IHyosungRuntime
{
StackStationModel Stack1 { get; }
StackStationModel Stack2 { get; }
/// <summary>
/// 启动运行

View File

@ -1,9 +1,9 @@
using System.Collections.ObjectModel;
using Seyounth.Hyosung.Data.Models;
namespace Seyounth.Hyosung.Models;
namespace Seyounth.Hyosung.Runtime.Models;
public class StackModel
public class StackStationModel
{
public string TrayCode { get; set; } = "NoData";

View File

@ -32,4 +32,8 @@
</Page>
</ItemGroup>
<ItemGroup>
<Folder Include="Models\" />
</ItemGroup>
</Project>

View File

@ -2,26 +2,30 @@ using System.Collections.ObjectModel;
using CommunityToolkit.Mvvm.ComponentModel;
using Seyounth.Hyosung.Data.Models;
using Seyounth.Hyosung.Data.Services;
using Seyounth.Hyosung.Models;
using Seyounth.Hyosung.Runtime;
using Seyounth.Hyosung.Runtime.Models;
namespace Seyounth.Hyosung.ViewModels;
public partial class HomeViewModel : ObservableObject
{
[ObservableProperty] private StackModel _stack1;
[ObservableProperty] private StackStationModel _stack1;
[ObservableProperty] private StackModel _stack2;
[ObservableProperty] private StackStationModel _stack2;
[ObservableProperty] private ObservableCollection<Variety> _varieties;
[ObservableProperty] private List<string> _yarnCarTypes;
[ObservableProperty] private Variety _selectedVariety;
public HomeViewModel(IVarietyService varietyService)
private readonly IHyosungRuntime _runtime;
public HomeViewModel(IVarietyService varietyService, IHyosungRuntime runtime)
{
_stack1 = new StackModel();
_stack2 = new StackModel();
_runtime = runtime;
_stack1 = _runtime.Stack1;
_stack2 = _runtime.Stack2;
_yarnCarTypes = new List<string>();
_yarnCarTypes.Add("A");
_yarnCarTypes.Add("B");

View File

@ -163,6 +163,7 @@
Foreground="White" Grid.Row="0" Text="品类:" />
<ComboBox x:Name="VarietyComboBox" Grid.Column="1" Margin="10" Grid.Row="0"
Foreground="White"
SelectionChanged="VarietyComboBox_OnSelectionChanged"
ItemsSource="{Binding ViewModel.Varieties}"
SelectedItem="{Binding ViewModel.SelectedVariety, Mode=TwoWay}"
DisplayMemberPath="Name" />
@ -181,6 +182,7 @@
<TextBox Grid.Column="1" Margin="10" Grid.Row="3" IsEnabled="False"
Foreground="White"
Text="{Binding ViewModel.SelectedVariety.TotalCount}" />
<TextBlock Grid.Row="4" Foreground="White" Grid.Column="0" Text="{Binding ViewModel.SelectedVariety.ControlNo,StringFormat='控制号: {0}'}" VerticalAlignment="Center" Margin="10"/>
<Button x:Name="ChangeVarietyButton"
materialDesign:ButtonProgressAssist.IsIndeterminate="True"
Click="ChangeVarietyButton_OnClick"

View File

@ -2,6 +2,7 @@
using System.Windows.Controls;
using MaterialDesignThemes.Wpf;
using Seyounth.Hyosung.Data.Models;
using Seyounth.Hyosung.Data.Services.Hyosung;
using Seyounth.Hyosung.Runtime;
using Seyounth.Hyosung.ViewModels;
@ -16,8 +17,11 @@ namespace Seyounth.Hyosung.Views.Pages
private readonly IHyosungRuntime _runtime;
public HomeViewPage(HomeViewModel viewModel, IHyosungRuntime runtime)
private readonly IHyosungWmsService _wmsService;
public HomeViewPage(HomeViewModel viewModel, IHyosungRuntime runtime, IHyosungWmsService wmsService)
{
_wmsService = wmsService;
_runtime = runtime;
ViewModel = viewModel;
DataContext = this;
@ -42,17 +46,30 @@ namespace Seyounth.Hyosung.Views.Pages
_runtime.SendVarietyToPlcAsync(variety)
.ContinueWith(task =>
{
if (task.IsCompletedSuccessfully)
Dispatcher.Invoke(() =>
{
if (!task.IsCompletedSuccessfully)
{
MessageBox.Show(task.Exception?.Message, "切换失败");
}
ChangeVarietyButton.Content = "切换";
ButtonProgressAssist.SetIsIndicatorVisible(ChangeVarietyButton, false);
ChangeVarietyButton.IsEnabled = true;
}
else
{
MessageBox.Show(task.Exception?.Message, "切换失败");
}
});
});
}
private async void VarietyComboBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
var selectedItem = VarietyComboBox.SelectedItem;
if (selectedItem != null)
{
var variety = selectedItem as Variety;
var info = await _wmsService.GetItemInfoByItemCode(variety.Code);
var controlNo = await _wmsService.GetControlNo(variety, info.GRADE);
variety.ControlNo = controlNo;
}
}
}
}