aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/Controls/generated by cgit v1.3.1 (git 2.54.0) at 2026-07-29 07:44:12 +0000
185' href='#n185'>185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
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;
using Tango.BL.Entities;
using Tango.Core.EventArguments;
using Tango.Integration.Operation;
using Tango.PMR.Diagnostics;
using System.Reactive.Concurrency;
using System.Reactive;

namespace Tango.PPC.Technician.Controls
{
    /// <summary>
    /// Interaction logic for DispenserController.xaml
    /// </summary>
    public partial class DispenserController : UserControl
    {
        public IdsPack IdsPack
        {
            get { return (IdsPack)GetValue(IdsPackProperty); }
            set { SetValue(IdsPackProperty, value); }
        }
        public static readonly DependencyProperty IdsPackProperty =
            DependencyProperty.Register("IdsPack", typeof(IdsPack), typeof(DispenserController), new PropertyMetadata(null));

        public IMachineOperator MachineOperator
        {
            get { return (IMachineOperator)GetValue(MachineOperatorProperty); }
            set { SetValue(MachineOperatorProperty, value); }
        }
        public static readonly DependencyProperty MachineOperatorProperty =
            DependencyProperty.Register("MachineOperator", typeof(IMachineOperator), typeof(DispenserController), new PropertyMetadata(null));

        public bool IsHoming
        {
            get { return (bool)GetValue(IsHomingProperty); }
            set { SetValue(IsHomingProperty, value); }
        }
        public static readonly DependencyProperty IsHomingProperty =
            DependencyProperty.Register("IsHoming", typeof(bool), typeof(DispenserController), new PropertyMetadata(false, (d, e) => (d as DispenserController).OnChange()));

        public bool IsPriming
        {
            get { return (bool)GetValue(IsPrimingProperty); }
            set { SetValue(IsPrimingProperty, value); }
        }
        public static readonly DependencyProperty IsPrimingProperty =
            DependencyProperty.Register("IsPriming", typeof(bool), typeof(DispenserController), new PropertyMetadata(false, (d, e) => (d as DispenserController).OnChange()));

        public bool IsBusy
        {
            get { return (bool)GetValue(IsBusyProperty); }
            set { SetValue(IsBusyProperty, value); }
        }
        public static readonly DependencyProperty IsBusyProperty =
            DependencyProperty.Register("IsBusy", typeof(bool), typeof(DispenserController), new PropertyMetadata(false));

        private void OnChange()
        {
            IsBusy = IsPriming || IsHoming;
        }

        public DispenserController()
        {
            InitializeComponent();
        }

        #region Home

        private async void BtnHome_Click(object sender, RoutedEventArgs e)
        {
            if (!IsHoming)
            {
                try
                {
                    IsHoming = true;

                    MachineOperator.StartDispenserHoming(new DispenserHomingRequest()
                    {
                        Index = IdsPack.PackIndex,
                        Speed = numSpeed.Value,
                        Direction = MotorDirection.Forward
                    })
                    .Subscribe((response) =>
                    {



                    }, (ex) =>
                    {

                        InvokeUI(() => IsHoming = false);


                    }, () =>
                    {

                        InvokeUI(() => IsHoming = false);

                    });
                }
                catch
                {
                    IsHoming = false;
                }
            }
            else
            {
                IsHoming = false;

                try
                {
                    await MachineOperator.StopDispenserHoming(new DispenserAbortHomingRequest()
                    {
                        Index = IdsPack.PackIndex,
                    });
                }
                catch { }
            }
        }

        #endregion

        private void InvokeUI(Action action)
        {
            Dispatcher.BeginInvoke(action);
        }

        private void btnPriming_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                IsPriming = true;

                MachineOperator.StartDispenserHoming(new DispenserHomingRequest()
                {
                    Index = IdsPack.PackIndex,
                    Speed = numSpeed.Value,
                    Direction = MotorDirection.Forward
                })
                .Subscribe((response) =>
                {



                }, (ex) =>
                {

                    InvokeUI(() => IsPriming = false);


                }, () =>
                {

                    InvokeUI(() => IsPriming = false);

                });
            }
            catch
            {
                IsPriming = false;
            }
        }

        private void btnHoming_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                IsHoming = true;

                MachineOperator.StartDispenserHoming(new DispenserHomingRequest()
                {
                    Index = IdsPack.PackIndex,
                    Speed = numSpeed.Value,
                    Direction = MotorDirection.Backward
                })
                .Subscribe((response) =>
                {



                }, (ex) =>
                {

                    InvokeUI(() => IsHoming = false);


                }, () =>
                {

                    InvokeUI(() => IsHoming = false);

                });
            }
            catch
            {
                IsHoming = false;
            }
        }

        private async void btnStop_Click(object sender, RoutedEventArgs e)
        {
            IsHoming = false;
            IsPriming = false;

            try
            {
                await MachineOperator.StopDispenserHoming(new DispenserAbortHomingRequest()
                {
                    Index = IdsPack.PackIndex,
                });
            }
            catch { }
        }
    }
}