GM_Base.cs 3.43 KB
Newer Older
潘栩锋's avatar
潘栩锋 committed
1 2 3 4 5 6 7 8 9
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

using FlyADBase;
using FLY.Thick.Base.Common;
using FLY.Thick.Base.IService;
10 11
using System.Diagnostics;

潘栩锋's avatar
潘栩锋 committed
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
namespace FLY.Thick.Base.Server
{
    public abstract class GM_Base : IGageMode, INotifyErrorArisen
    {
        /// <summary>
        /// 启动时出错,已经在运行了
        /// </summary>
        public const byte ERRNO_StartUp_IsRunning = 1;
        /// <summary>
        /// 启动时出错,AD卡连接断开
        /// </summary>
        public const byte ERRNO_StartUp_FlyADNoConnected = 2;
        /// <summary>
        /// 参数异常
        /// </summary>
        public const byte ERRNO_StartUp_Param = 3;
        /// <summary>
        /// 参数异常
        /// </summary>
        public const byte ERRNO_Running_Manual = 4;

33

潘栩锋's avatar
潘栩锋 committed
34
        #region IGageMode 接口
35 36 37 38 39 40 41 42

        public CTRL_STATE GMState { get; protected set; }

        /// <summary>
        /// 运行中
        /// </summary>
        public bool IsRunning { get; protected set; }

潘栩锋's avatar
潘栩锋 committed
43 44 45
        public event ErrorArisenEventHander ErrorArisenEvent;
        protected void NotifyError(byte errno) 
        {
46
            ErrorArisenEvent?.Invoke(this, new ErrorArisenEventArgs() { Errno = errno });
潘栩锋's avatar
潘栩锋 committed
47 48 49
        }
        #endregion

50 51 52
        protected FlyAD7 mFlyAD;
        protected FObjBase.PollModule.PollHandler onpoll_func;
        public GM_Base()
潘栩锋's avatar
潘栩锋 committed
53
        {
54 55 56

        }
        public virtual void Init(FlyAD7 flyad) {
潘栩锋's avatar
潘栩锋 committed
57 58 59 60 61 62 63 64 65 66 67
            mFlyAD = flyad;
            onpoll_func = new FObjBase.PollModule.PollHandler(OnPoll);
        }
        protected virtual void OnPoll()
        {
            if (mFlyAD.IsFinish)
            {
                Stop();
            }
        }
        #region IGageMode 接口
68
        public virtual void Start()
潘栩锋's avatar
潘栩锋 committed
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
        {
            if (IsRunning)
            {
                NotifyError(ERRNO_StartUp_IsRunning);
            }
            if (!mFlyAD.IsConnected)
            {
                NotifyError(ERRNO_StartUp_FlyADNoConnected);
            }
            IsRunning = true;
            FObjBase.PollModule.Current.Poll_Config(onpoll_func);
        }
        public virtual void Stop()
        {
            FObjBase.PollModule.Current.Poll_Config(
                FObjBase.PollModule.POLL_CONFIG.REMOVE,
                onpoll_func);

            IsRunning = false;
        }

        #endregion
91
        
潘栩锋's avatar
潘栩锋 committed
92 93 94
        #region IGageMode 接口
        protected void NotifyPropertyChanged(string propertyName)
        {
95
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
潘栩锋's avatar
潘栩锋 committed
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
        }
        public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
        #endregion

        /// <summary>
        /// 等待停止; 
        /// 正常停止返回true,没有停止及异常停止返回false
        /// </summary>
        /// <returns></returns>
        protected bool WaitFinish()
        {
            switch (mFlyAD.DriveStatus)
            {
                case DRIVE_MAN_STATUS.STOP://完成任务
                case DRIVE_MAN_STATUS.LIMIT:
                    {
                        return true;
                    }
                case DRIVE_MAN_STATUS.STOP_MANUAL://异常
                    {
                        NotifyError(ERRNO_Running_Manual);
                        Stop(); return false;
                    }
            }
            return false;
        }
    }







130

潘栩锋's avatar
潘栩锋 committed
131

132

潘栩锋's avatar
潘栩锋 committed
133

134

潘栩锋's avatar
潘栩锋 committed
135 136 137 138 139


    

}