/// <summary>
        /// The user has selected a different Focuser.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cmbxModel_SelectedIndexChanged(object sender, EventArgs e)
        {
            // Focuser model and indexer.
            Focuser.ModelNumberEnum ModelNumber = (Focuser.ModelNumberEnum)cmbxModel.SelectedItem;
            Properties.Settings.Default.FocuserModel = ModelNumber.ToString();

            Focuser.FocuserDataType model;
            if (m_Focuser.m_FocuserTypes.TryGetValue(ModelNumber, out model))
            {
                SetFocuserParameters();
            }
        }
        /// <summary>
        /// Sets various parameters based on user input.
        /// </summary>
        void SetFocuserParameters()
        {
            // Load Step Resolution
            string strStepResolution;

            if (rbtnCoarseResolution.Checked)
            {
                strStepResolution = "Coarse";
            }
            else if (rbtnMediumResolution.Checked)
            {
                strStepResolution = "Medium";
            }
            else
            {
                strStepResolution = "Fine";
            }

            Focuser.ModelNumberEnum modelEnum = (Focuser.ModelNumberEnum)cmbxModel.SelectedItem;

            m_Focuser.DetermineFocuserLength(modelEnum);
            m_Focuser.DetermineStepResolution(strStepResolution);

            tbxStepSizeMicrons.ReadOnly = true;
            Focuser.FocuserDataType model = m_Focuser.FocuserModels[modelEnum];
            tbxStepSizeMicrons.Text = (model.MicronsPerStep * m_Focuser.StepResolution).ToString();
            nudMaxTravel.Text       = (model.StepCount / m_Focuser.StepResolution).ToString();
            nudMaxIncrement.Value   = Convert.ToInt32(nudMaxTravel.Text);

            // TODO:  Some sort of UI that needs to be implement?
            // TODO:  Calibrate Zero?
            //cmdCalibrate.Visible = false;
            //cmdCalibrate.Enabled = false;
            //cmdInit.Visible = false;
            //cmdInit2.Visible = true;

            switch (modelEnum)
            {
            case Focuser.ModelNumberEnum.FTF2008BCR:
            case Focuser.ModelNumberEnum.FTF2008:
                break;

            case Focuser.ModelNumberEnum.FTF2015:
            case Focuser.ModelNumberEnum.FTF2020:
            case Focuser.ModelNumberEnum.FTF2025:
            case Focuser.ModelNumberEnum.FTF3545:
            case Focuser.ModelNumberEnum.AP27FTMU:
            case Focuser.ModelNumberEnum.AP4FOC3E:
            case Focuser.ModelNumberEnum.AP27FOC3E:
                if (Convert.ToInt32(nudMaxTravel.Text) <= UInt16.MaxValue)
                {
                    nudMaxIncrement.Value = Convert.ToDecimal(nudMaxTravel.Text);
                }
                else
                {
                    nudMaxIncrement.Value = UInt16.MaxValue;
                }

                break;

            case Focuser.ModelNumberEnum.Other:
                tbxStepSizeMicrons.Text = "6.4";
                nudMaxTravel.Text       = Properties.Settings.Default.MaxStep.ToString();
                nudMaxIncrement.Text    = Properties.Settings.Default.MaxIncrement.ToString();

                tbxStepSizeMicrons.ReadOnly = false;
                //cmdCalibrate.Visible = true;
                //cmdCalibrate.Enabled = true;
                //cmdInit2.Visible = false;
                //cmdInit.Visible = true;

                break;
            }
        }
Exemple #3
0
        /// <summary>
        /// Port of VB Let Link property.
        /// </summary>
        /// <param name=" bConnect "></param>
        void LetLink(bool bConnect)
        {
            int lPos;

            LogMessage("Focuser.LetLink", "arg is {0}", bConnect);

            if (bConnect == g_bFocuserConnected)
            {
                return;                 // Nothing to do.
            }

            if (!bConnect)
            {
                g_bUseCachedPosition = false;
                lPos = GetPosition();

                if (lPos > 99900)
                {
                    lPos = 0;
                }
                if (lPos > MaxStepNumber)
                {
                    lPos = MaxStepNumber;
                }

                SaveFocuserPosition(lPos);

                CloseConnection();

                return;                 // Exit Property
            }

            // Load the maximum step number
            MaxStepNumber = Properties.Settings.Default.MaxStep;

            // Load the last saved focus position for restoration and protect against it being out of range.
            int lastSavedPosition = Properties.Settings.Default.LastFocusPosition;

            if (lastSavedPosition > 99900)
            {
                lastSavedPosition = 0;
            }
            if (lastSavedPosition > MaxStepNumber)
            {
                lastSavedPosition = MaxStepNumber;
            }

            if (lastSavedPosition != Properties.Settings.Default.LastFocusPosition)
            {
                Properties.Settings.Default.LastFocusPosition = lastSavedPosition;
                Properties.Settings.Default.Save();
            }

            // Compute steps/degree for temperature compensation.
            if (Properties.Settings.Default.DeltaT != 0)
            {
                m_dStepsPerDegree = Properties.Settings.Default.DeltaSteps / Properties.Settings.Default.DeltaT;
            }
            else
            {
                m_dStepsPerDegree = 0;
            }

            // Temperature compensation IN or OUT?
            m_TempCompIn = Properties.Settings.Default.BacklashFinalDirectionIsOut;

            // Load Step Resolution
            Focuser.ModelNumberEnum modelEnum = (Focuser.ModelNumberEnum)Properties.Settings.Default.FocuserModelIndex;
            LogMessage("Focuser.LetLink", "Focuser model index is {0}", modelEnum);
            LogMessage("Focuser.LetLink", "Focuser step resolution is {0}", Properties.Settings.Default.StepResolution);

            // Determine if focuser is short or long body based on model number.
            DetermineFocuserLength(modelEnum);

            // Determine the number of steps based on the user selected coarseness.
            DetermineStepResolution(Properties.Settings.Default.StepResolution);

            OpenConnection();

            // This is also done in the power-up code.
            SetSpeed((byte)Properties.Settings.Default.FocusSpeed, m_StepResolution);
            SaveDataToFirmware();

            return;
        }