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; using System.Diagnostics; namespace FLY.Thick.Base.Server { public abstract class GM_Base : IGageMode, INotifyErrorArisen { /// /// 启动时出错,已经在运行了 /// public const byte ERRNO_StartUp_IsRunning = 1; /// /// 启动时出错,AD卡连接断开 /// public const byte ERRNO_StartUp_FlyADNoConnected = 2; /// /// 参数异常 /// public const byte ERRNO_StartUp_Param = 3; /// /// 参数异常 /// public const byte ERRNO_Running_Manual = 4; #region IGageMode 接口 public CTRL_STATE GMState { get; protected set; } /// /// 运行中 /// public bool IsRunning { get; protected set; } public event ErrorArisenEventHander ErrorArisenEvent; protected void NotifyError(byte errno) { ErrorArisenEvent?.Invoke(this, new ErrorArisenEventArgs() { Errno = errno }); } #endregion protected IFlyADClientAdv mFlyAD; protected FObjBase.PollModule.PollHandler onpoll_func; public GM_Base() { } public virtual void Init(IFlyADClientAdv flyad) { mFlyAD = flyad; onpoll_func = new FObjBase.PollModule.PollHandler(OnPoll); } protected virtual void OnPoll() { if (mFlyAD.IsFinish) { Stop(); } } #region IGageMode 接口 public virtual void Start() { 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 #region IGageMode 接口 protected void NotifyPropertyChanged(string propertyName) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged; #endregion /// /// 等待停止; /// 正常停止返回true,没有停止及异常停止返回false /// /// 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; } } }