From 4225ba2cde1b0cfdb57196cb832dbec2dfca5707 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Tue, 1 Dec 2020 02:36:51 +0200 Subject: Cleaner dispensing dialog. --- .../Dialogs/CleanerDispensingView.xaml | 49 ++++++++ .../Dialogs/CleanerDispensingView.xaml.cs | 28 +++++ .../Dialogs/CleanerDispensingViewVM.cs | 128 +++++++++++++++++++++ .../Tango.PPC.Maintenance.csproj | 10 +- .../ViewModels/MaintenanceViewVM.cs | 26 +++++ .../Views/MaintenanceView.xaml | 2 + 6 files changed, 242 insertions(+), 1 deletion(-) create mode 100644 Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/Dialogs/CleanerDispensingView.xaml create mode 100644 Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/Dialogs/CleanerDispensingView.xaml.cs create mode 100644 Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/Dialogs/CleanerDispensingViewVM.cs (limited to 'Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance') diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/Dialogs/CleanerDispensingView.xaml b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/Dialogs/CleanerDispensingView.xaml new file mode 100644 index 000000000..5fa737221 --- /dev/null +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/Dialogs/CleanerDispensingView.xaml @@ -0,0 +1,49 @@ + + + + + Dispense Cleaning Liquid + + + + + START + + + + + + + + + + + diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/Dialogs/CleanerDispensingView.xaml.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/Dialogs/CleanerDispensingView.xaml.cs new file mode 100644 index 000000000..6f1ebb4ed --- /dev/null +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/Dialogs/CleanerDispensingView.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 Tango.PPC.Maintenance.Dialogs +{ + /// + /// Interaction logic for PowerUpView.xaml + /// + public partial class CleanerDispensingView : UserControl + { + public CleanerDispensingView() + { + InitializeComponent(); + } + } +} diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/Dialogs/CleanerDispensingViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/Dialogs/CleanerDispensingViewVM.cs new file mode 100644 index 000000000..b84cd83de --- /dev/null +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/Dialogs/CleanerDispensingViewVM.cs @@ -0,0 +1,128 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Timers; +using Tango.BL.Entities; +using Tango.Core.Commands; +using Tango.Core.DI; +using Tango.Integration.Operation; +using Tango.PMR.Printing; +using Tango.PPC.Common; +using Tango.PPC.Common.Connection; +using Tango.PPC.Common.Notifications; +using Tango.Settings; +using Tango.SharedUI; + +namespace Tango.PPC.Maintenance.Dialogs +{ + public class CleanerDispensingViewVM : DialogViewVM + { + private const int JOGGING_TIME_SEC = 10; + private const int JOGGING_SPEED = 400; + + [TangoInject] + private IMachineProvider MachineProvider { get; set; } + + [TangoInject] + private INotificationProvider NotificationProvider { get; set; } + + private bool _isStarted; + public bool IsStarted + { + get { return _isStarted; } + set { _isStarted = value; RaisePropertyChangedAuto(); } + } + + private bool _isCompleted; + public bool IsCompleted + { + get { return _isCompleted; } + set { _isCompleted = value; RaisePropertyChangedAuto(); } + } + + private bool _isFailed; + public bool IsFailed + { + get { return _isFailed; } + set { _isFailed = value; RaisePropertyChangedAuto(); } + } + + private String _status; + public String Status + { + get { return _status; } + set { _status = value; RaisePropertyChangedAuto(); } + } + + public RelayCommand StartCommand { get; set; } + + public CleanerDispensingViewVM() + { + Status = "Ready..."; + CanClose = true; + TangoIOC.Default.Inject(this); + StartCommand = new RelayCommand(Start, () => !IsStarted); + } + + private async void Start() + { + try + { + CanClose = false; + IsStarted = true; + IsCompleted = false; + IsFailed = false; + InvalidateRelayCommands(); + + Status = "Dispensing cleaner liquid..."; + + var cleanerPack = MachineProvider.Machine.Configuration.NoneEmptyIdsPacks.FirstOrDefault(x => x.LiquidType.Type == BL.Enumerations.LiquidTypes.Cleaner); + + if (cleanerPack == null) + { + throw new InvalidOperationException("'Cleaner' liquid type was not found on the machine configuration."); + } + + var cleanerIndex = cleanerPack.PackIndex; + + await MachineProvider.MachineOperator.StartDispenserJogging(new PMR.Diagnostics.DispenserJoggingRequest() + { + Direction = PMR.Diagnostics.MotorDirection.Forward, + Speed = JOGGING_SPEED, + Index = cleanerIndex + }); + + await Task.Delay(TimeSpan.FromSeconds(JOGGING_TIME_SEC)); + + await MachineProvider.MachineOperator.StopDispenserJogging(new PMR.Diagnostics.DispenserAbortJoggingRequest() + { + Index = cleanerIndex + }); + + IsCompleted = true; + Status = "Cleaner liquid dispensing completed."; + } + catch (Exception ex) + { + Status = "Cleaner liquid dispensing failed."; + IsFailed = true; + await NotificationProvider.ShowError($"Error occurred while trying to perform the cleaner liquid dispensing.\n{ex.FlattenMessage()}"); + } + finally + { + CanClose = true; + IsStarted = false; + } + } + + protected override void Cancel() + { + if (CanClose) + { + base.Cancel(); + } + } + } +} diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/Tango.PPC.Maintenance.csproj b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/Tango.PPC.Maintenance.csproj index f334dac5b..9dd45add4 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/Tango.PPC.Maintenance.csproj +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/Tango.PPC.Maintenance.csproj @@ -80,6 +80,10 @@ MSBuild:Compile Designer + + MSBuild:Compile + Designer + MSBuild:Compile Designer @@ -120,9 +124,13 @@ + + CleanerDispensingView.xaml + HeadCleaningView.xaml + @@ -306,7 +314,7 @@ - + \ No newline at end of file diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/ViewModels/MaintenanceViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/ViewModels/MaintenanceViewVM.cs index c8cb4415d..f7269e0b1 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/ViewModels/MaintenanceViewVM.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/ViewModels/MaintenanceViewVM.cs @@ -108,6 +108,8 @@ namespace Tango.PPC.Maintenance.ViewModels public RelayCommand StartThreadBreakCommand { get; set; } + public RelayCommand DispenseCleanerLiquidCommand { get; set; } + public MaintenanceViewVM() { Guides = new ObservableCollection(GuideHelper.CreateAllGuides()); @@ -136,6 +138,20 @@ namespace Tango.PPC.Maintenance.ViewModels MachineProvider.MachineOperator.InkFillingStatusChanged += MachineOperator_InkFillingStatusChanged; MachineProvider.MachineOperator.MachineStatusChanged += MachineOperator_MachineStatusChanged; MachineProvider.MachineOperator.MachineEventsStateProvider.EventsChanged += MachineEventsStateProvider_EventsChanged; + + DispenseCleanerLiquidCommand = new RelayCommand(DispenseCleanerLiquid, () => + { + if (MachineProvider.Machine.MachineHeadType == BL.Enumerations.HeadTypes.Arc) + { + return MachineProvider.MachineOperator.MachineEventsStateProvider.Events.Any(x => x.Type == BL.Enumerations.EventTypes.DYEING_HEAD_ARC_LID_IS_OPEN); + } + else + { + return true; + } + }); + + RaisePropertyChanged(nameof(DispenseCleanerLiquidCommand)); } public override void OnApplicationReady() @@ -152,6 +168,11 @@ namespace Tango.PPC.Maintenance.ViewModels private void MachineEventsStateProvider_EventsChanged(object sender, IEnumerable e) { OpenCloseDyeingHeadCommand.IsEnabled = !e.Any(x => x.Type == BL.Enumerations.EventTypes.DRYER_DOOR_OPEN); + + InvokeUI(() => + { + DispenseCleanerLiquidCommand.RaiseCanExecuteChanged(); + }); } private void MachineOperator_MachineStatusChanged(object sender, MachineStatus status) @@ -294,5 +315,10 @@ namespace Tango.PPC.Maintenance.ViewModels { ThreadLoadingService.StartThreadBreakWizard(); } + + private async void DispenseCleanerLiquid() + { + await NotificationProvider.ShowDialog(); + } } } diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/Views/MaintenanceView.xaml b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/Views/MaintenanceView.xaml index a24d336ee..286485d47 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/Views/MaintenanceView.xaml +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/Views/MaintenanceView.xaml @@ -254,6 +254,8 @@ RUN HEAD CLEANING + DISPENSE CLEANING LIQUID + EXPORT SYSTEM LOGS -- cgit v1.3.1