PgFlyAd.xaml.cs 5 KB
Newer Older
潘栩锋's avatar
潘栩锋 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
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 FLY.Thick.Base.UI.Converter;
using System.Net;

using FLY.Thick.Base.Client;
using FLY.Thick.Base.Common;
using Unity;
using FLY.Thick.Base.IService;
using System.ComponentModel;
using GalaSoft.MvvmLight.Command;

namespace FLY.Thick.Base.UI
{
    /// <summary>
    /// Page_FlyAD.xaml 的交互逻辑
    /// </summary>
    public partial class PgFlyAd : Page
    {
        PgFlyAdVm viewModel;
        public PgFlyAd()
        {
            InitializeComponent();
        }

        [InjectionMethod]
        public void Init(
            IUnityContainer container,
            IFlyADService flyAdService,
            ITDGageService gageService) 
        {
            viewModel = new PgFlyAdVm();
            viewModel.Init(flyAdService, gageService);
            this.DataContext = viewModel;
            container.BuildUp(mircoGage);
        }


    }
    public class PgFlyAdVm : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;
        #region 参数
        public bool HasCRC { get; set; }
        public IPEndPoint EP { get; set; }
        public int PosOfGrid { get; set; }
        public MOTORTYPE MotorType { set; get; }
        public UInt16 Ratio01 { get; set; }
        public UInt16 Ratio02 { get; set; }
        public Int16 PosOffset { set; get; }//脉冲平移
        public UInt32 JogVelocity { set; get; }
        public int GridSmooth { get; set; }
64
        public bool IsCalSpeed { get; set; }
潘栩锋's avatar
潘栩锋 committed
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
        #endregion

        public int TargetPos { get; set; }

        #region Command
        public RelayCommand ApplyCmd { get; }
        public RelayCommand RunToCmd { get; }
        public RelayCommand BackwCmd { get; }
        public RelayCommand ForwCmd { get; }
        public RelayCommand OrgCmd { get; }
        public RelayCommand StopCmd { get; }
        #endregion

        IFlyADService flyAdService;
        ITDGageService gageService;

        public PgFlyAdVm() 
        {
            ApplyCmd = new RelayCommand(Apply);
            RunToCmd = new RelayCommand(RunTo);
            BackwCmd = new RelayCommand(Backw);
            ForwCmd = new RelayCommand(Forw);
            OrgCmd = new RelayCommand(Org);
            StopCmd = new RelayCommand(Stop);
        }

        public void Init(
            IFlyADService flyAdService,
            ITDGageService gageService)
        {
            this.flyAdService = flyAdService;
            this.gageService = gageService;

            Misc.BindingOperations.SetBinding(this.flyAdService, "HasCRC", this, "HasCRC");
            Misc.BindingOperations.SetBinding(this.flyAdService, "EP", this, "EP");
            Misc.BindingOperations.SetBinding(this.flyAdService, "PosOfGrid", this, "PosOfGrid");
            Misc.BindingOperations.SetBinding(this.flyAdService, "MotorType", this, "MotorType");
            Misc.BindingOperations.SetBinding(this.flyAdService, "Ratio01", this, "Ratio01");
            Misc.BindingOperations.SetBinding(this.flyAdService, "Ratio02", this, "Ratio02");
            Misc.BindingOperations.SetBinding(this.flyAdService, "PosOffset", this, "PosOffset");
            Misc.BindingOperations.SetBinding(this.flyAdService, "JogVelocity", this, "JogVelocity");
            Misc.BindingOperations.SetBinding(this.flyAdService, "GridSmooth", this, "GridSmooth");
107
            Misc.BindingOperations.SetBinding(this.flyAdService, "IsCalSpeed", this, "IsCalSpeed");
潘栩锋's avatar
潘栩锋 committed
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
        }
        private void Apply()
        {
            if (!WdPassword.Authorize("FlyAd"))
                return;

            flyAdService.HasCRC=this.HasCRC;
            flyAdService.EP=this.EP;
            flyAdService.PosOfGrid=this.PosOfGrid;
            flyAdService.MotorType=this.MotorType;
            flyAdService.Ratio01=this.Ratio01;
            flyAdService.Ratio02=this.Ratio02;
            flyAdService.PosOffset=this.PosOffset;
            flyAdService.JogVelocity=this.JogVelocity;
            flyAdService.GridSmooth = this.GridSmooth;
123
            flyAdService.IsCalSpeed = this.IsCalSpeed;
潘栩锋's avatar
潘栩锋 committed
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
            flyAdService.Apply();
            FLY.ControlLibrary.Window_Tip.Show("应用成功",
                null,
                TimeSpan.FromSeconds(2));
            
        }
        private void RunTo()
        {
            gageService.StartP2(STARTP2_MODE.RUNTO, TargetPos);
        }
        private void Stop()
        {
            gageService.StartP2(STARTP2_MODE.STOP);
        }
        private void Org()
        {
            gageService.StartP2(STARTP2_MODE.ORG);
        }
        private void Forw()
        {
            gageService.StartP2(STARTP2_MODE.FORW_UNTIL_STOP);
        }
        private void Backw()
        {
            gageService.StartP2(STARTP2_MODE.BACKW_UNTIL_STOP);
        }
    }
}