示例#1
0
        public void Dispose()
        {
            ShutdownMonitorThread();

            if (_focuser == null)
            {
                return;
            }

            try
            {
                _focuser.Link = false;
            }
            catch (Exception e)
            {
                Tracer.TraceException("Trying to unlink from focuser", e);
            }

            if (Marshal.IsComObject(_focuser))
            {
                Marshal.ReleaseComObject(_focuser);
            }
            else if (_focuser is IDisposable)
            {
                (_focuser as IDisposable).Dispose();
            }
            _focuser = null;
        }
示例#2
0
        public FocusAdaptor(string id, string name)
        {
            Tracer.TraceStart(LogLevel.Debug);
            _name = name;

            Tracer.Trace(LogLevel.Info, "Creating ASCOM Focuser of type {0} ('{1}')", id, name);
            object   oFocuser = Activator.CreateInstance(Type.GetTypeFromProgID(id, true));
            IFocuser focuser  = oFocuser as IFocuser ?? new FocuserDispatchProxy(oFocuser);

            _focuser = focuser;

            Tracer.TraceEnd(LogLevel.Debug);
        }
示例#3
0
        public void DisconnectFocuser(CallType callType = CallType.Async, Guid? clientId = null, CallbackAction callback = null, Control callbackUIControl = null)
        {
            IsolatedAction(() =>
            {
                try
                {
                    if (m_ConnectedFocuser != null)
                    {
                        AssertFocuserEngagement(clientId);

                        ASCOMClient.Instance.DisconnectFocuser(m_ConnectedFocuser);
                        m_ConnectedFocuser = null;
                    }
                }
                catch (Exception ex)
                {
                    OnFocuserErrored();
                    Trace.WriteLine(ex.GetFullStackTrace());

                    return ex;
                }

                OnFocuserDisconnected();

                return null;
            },
            callType, callback, callbackUIControl);
        }
示例#4
0
        public void TryConnectFocuser(CallType callType = CallType.Async, Guid? clientId = null, CallbackAction callback = null, Control callbackUIControl = null)
        {
            IsolatedAction(() =>
            {
                try
                {
                    if (m_ConnectedFocuser != null && m_ConnectedFocuser.ProgId != Settings.Default.ASCOMProgIdFocuser)
                    {
                        AssertFocuserEngagement(clientId);

                        ASCOMClient.Instance.DisconnectFocuser(m_ConnectedFocuser);
                        m_ConnectedFocuser = null;
                    }

                    if (m_ConnectedFocuser == null && !string.IsNullOrEmpty(Settings.Default.ASCOMProgIdFocuser))
                    {
                        m_ConnectedFocuser = ASCOMClient.Instance.CreateFocuser(
                            Settings.Default.ASCOMProgIdFocuser,
                            Settings.Default.FocuserLargeStep,
                            Settings.Default.FocuserSmallStep,
                            Settings.Default.FocuserSmallestStep);
                    }

                    if (m_ConnectedFocuser != null)
                    {
                        if (!m_ConnectedFocuser.Connected)
                        {
                            OnFocuserConnecting();
                            m_ConnectedFocuser.Connected = true;
                            OnFocuserConnected();
                        }
                        else
                            OnFocuserConnected();

                        FocuserState state = m_ConnectedFocuser.GetCurrentState();
                        OnFocuserState(state);

                        return state;
                    }

                    return null;
                }
                catch (Exception ex)
                {
                    OnFocuserErrored();
                    Trace.WriteLine(ex.GetFullStackTrace());

                    return ex;
                }

            },
            callType, callback, callbackUIControl);
        }
 public TestableOvershootBacklashCompensationDecorator(IProfileService profileService, IFocuser focuser) : base(profileService, focuser)
 {
 }
示例#6
0
 public FocuserDecorator(IProfileService profileService, IFocuser focuser)
 {
     this.profileService           = profileService;
     this.focuser                  = focuser;
     this.focuser.PropertyChanged += Focuser_PropertyChanged;
 }
 public AbsoluteBacklashCompensationDecorator(IProfileService profileService, IFocuser focuser) : base(profileService, focuser)
 {
 }
示例#8
0
        public void DisconnectFocuser(IFocuser focuser)
        {
            try
            {
                if (TraceSwitchASCOMClient.TraceVerbose)
                    Trace.WriteLine(string.Format("OccuRec: ASCOMClient::DisconnectFocuser('{0}')", focuser.UniqueId));

                if (focuser.Connected)
                    focuser.Connected = false;
            }
            catch (Exception ex)
            {
                if (TraceSwitchASCOMClient.TraceError)
                    Trace.WriteLine(ex);
            }

            ReleaseDevice(focuser);
        }
示例#9
0
        private IFocuser GetBacklashCompensationFocuser(IProfileService profileService, IFocuser focuser)
        {
            switch (profileService.ActiveProfile.FocuserSettings.BacklashCompensationModel)
            {
            case Utility.Enum.BacklashCompensationModel.ABSOLUTE:
                return(new AbsoluteBacklashCompensationDecorator(profileService, focuser));

            case Utility.Enum.BacklashCompensationModel.OVERSHOOT:
                return(new OvershootBacklashCompensationDecorator(profileService, focuser));

            default:
                return(focuser);
            }
        }