/// Windows C# Sample Console Application: ClosedLoopSlew
    ///
    /// ------------------------------------------------------------------------
    ///
    ///               Author: R.McAlister (2017)
    ///
    /// ------------------------------------------------------------------------
    ///
    /// ClosedLoopSlew:  Find a target (M39 in this case), then execute a closed loop slew to it
    ///
    ///
    public void CLSSample()
    {
              
        ///Set connection to star chart and perform a find on M39
        sky6StarChart tsx_sc = new sky6StarChart();
        tsx_sc.Find("M39");

        ///Create connection to camera and connect
        ccdsoftCamera tsx_cc = new ccdsoftCamera();
        tsx_cc.Connect();

        ///Create closed loop slew object
        ClosedLoopSlew tsx_cls = new ClosedLoopSlew();

        ///Set the exposure, filter to luminance and reduction, set the camera delay to 0 -- backlash
        /// should be picked up in the mount driver
        tsx_cc.ImageReduction = ccdsoftImageReduction.cdAutoDark;
        tsx_cc.FilterIndexZeroBased = 3; ///Luminance
        tsx_cc.ExposureTime = 10;
        tsx_cc.Delay = 0;

       ///Execute
        try {
            int clsstat = tsx_cls.exec();
        }
        catch {
            ///Just close up: TSX will spawn error window
            MessageBox.Show("Closed Loop Slew failure");
        };

        return;
    }
Exemple #2
0
        public static string[] FilterNameSet()
        {
            //Figure out the filter mapping
            //Find the filter name for the filter filter Number
            ccdsoftCamera tsxc = new ccdsoftCamera();

            try { tsxc.Connect(); }
            catch (Exception ex)
            {
                return(null);
            }
            try
            {
                int      filterCount   = tsxc.lNumberFilters;
                string[] TSXFilterList = new string[filterCount];
                for (int f = 0; f < filterCount; f++)
                {
                    TSXFilterList[f] = (tsxc.szFilterName(f));
                }
                return(TSXFilterList);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Exemple #3
0
        public bool CameraStartUp()
        {
            //Method for connecting and initializing the TSX camera
            ccdsoftCamera tsxc = new ccdsoftCamera();

            try { tsxc.Connect(); }
            catch (Exception ex) { return(false); }
            return(true);
        }
        private bool TakeImage()
        {
            ccdsoftCamera tsxc = new ccdsoftCamera()
            {
                Frame        = ccdsoftImageFrame.cdLight,
                Subframe     = 0,
                Delay        = 0,
                AutoSaveOn   = 1,
                ExposureTime = (double)ExposureBox.Value,
                Asynchronous = 1 //asychronous is on
            };

            //try to set filter, if any
            if (FiltersListBox.Text != "")
            {
                tsxc.FilterIndexZeroBased = (int)Filters.LookUpFilterIndex(FiltersListBox.Text);
            }

            if (FullReductionCheckBox.Checked)
            {
                tsxc.ImageReduction = ccdsoftImageReduction.cdBiasDarkFlat;
                string    binning = "1X1";
                Reduction calLib  = new Reduction();
                calLib.SetReductionGroup(tsxc.FilterIndexZeroBased, tsxc.ExposureTime, (int)tsxc.TemperatureSetPoint, binning);
            }
            ImageAbort.BackColor = Color.LightGreen;
            try
            {
                tsxc.Connect();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Camera connect failure: " + ex.Message);
                IsImaging     = true;
                tsxc          = null;
                RepsBox.Value = 1;
                return(false);
            }
            try
            {
                tsxc.TakeImage();
            }
            catch (Exception ex)
            {
                ImageButton.BackColor = Color.Yellow;
                IsImaging             = false;
                UpdateStatusLine("Imaging Error: " + ex.Message);
                RepsBox.Value = 1;
                IsImaging     = true;
                tsxc          = null;
                return(false);
            }
            IsImaging = true;
            tsxc      = null;
            return(true);
        }
Exemple #5
0
        //Autofocus manages the TSX functions to refocus the camera
        // every change of 1 degree in temperature.
        //The first fime autofocus is called, the telescope is slewed to
        // a position with Az = 90, Alt = 80.  Then @Focus2 is called with
        // TSX providing the star to use.  the temperature at that time is recorded.
        //Subsequent calls to autofocus check to see if the current focuser temperature
        //  is more than a degree celsius different from the last @autofocus2 time.
        //  if so, @autofocus2 is called again, although the telescope is not slewed.  And so on.

        public static string Check()
        {
            //check to see if current temperature is a degree different from last temperature
            //  If so, then set up and run @focus2
            //AtFocus2 chooses to use a 15 degree x 15 degree field of view to choose a focus star
            //  If the current position is close to the meridian then a focus star on the other
            //  side of the meridian can be choosen and the mount will flip trying to get to it
            //  and, if using a dome, the slew does not wait for the dome slit to catch up (CLS flaw)
            //  so not only will an exception be thrown (Dome command in progress Error 125) the first image
            //   will be crap and the focus fail (as of DB 11360).  So, this method will point the mount to a
            //  altitude that is no more than 80 degrees at the same azimuth of the current position in order
            //  to avoid a flip and subsequent bullshit happening

            ccdsoftCamera tsxc = new ccdsoftCamera();

            tsxc.Connect();
            double currentTemp = tsxc.focTemperature;

            if (Math.Abs(currentTemp - afLastTemp) > 1)
            {
                //Going to have to refocus.

                //Move to altitude away from meridian, if need be
                sky6RASCOMTele tsxt = new sky6RASCOMTele();
                tsxt.GetAzAlt();
                double tAlt = tsxt.dAlt;
                if (tAlt > 80)
                {
                    double tAz = tsxt.dAz;
                    tAlt = 80.0;
                    //turn off tracking to avoid dome error
                    //DeviceControl dctl = new DeviceControl();
                    //dctl.DomeTrackingOff();
                    tsxt.SlewToAzAlt(tAz, tAlt, "AtFocus2ReadyPosition");
                    //dctl.DomeTrackingOn();
                }

                //reset last temp
                afLastTemp = currentTemp;
                int syncSave = tsxc.Asynchronous;
                tsxc.Asynchronous = 0;
                try
                {
                    int focStat = tsxc.AtFocus2();
                }
                catch (Exception e)
                {
                    tsxc.Asynchronous = syncSave;
                    return("Focus Check: " + e.Message);
                }
                return("Focus Check: Focus successful");
            }
            return("Focus Check: Temperature change less than 1 degree");
        }
Exemple #6
0
            public static List <string> FilterWheelList()
            {
                ccdsoftCamera tsxc = new ccdsoftCamera();

                //Connect the camera, if fails, then just return after clean up
                try
                { tsxc.Connect(); }
                catch
                {
                    return(null);
                }
                List <string> tfwList = new List <string>();

                for (int filterIndex = 0; filterIndex < tsxc.lNumberFilters; filterIndex++)
                {
                    tfwList.Add(tsxc.szFilterName(filterIndex));
                }
                return(tfwList);
            }
Exemple #7
0
        public static string PresetFocus()
        {
            //Sets the focuser to the position set by the StepsPerDegree and StepAtZero (slope and intercept)
            //  as accumulated for the focuser.  If StepsPerDegree is zero, then no movement is made
            Configuration cfg = new Configuration();

            ccdsoftCamera tsxc = new ccdsoftCamera();

            tsxc.Connect();
            double currentTemp     = tsxc.focTemperature;
            int    currentPosition = tsxc.focPosition;
            double stepsPerDegree  = Convert.ToDouble(cfg.StepsPerDegree);
            double positionAtZero  = Convert.ToDouble(cfg.PositionAtZero);
            string logUpdate;

            if (stepsPerDegree != 0.0)
            {
                int newPosition = (int)(currentTemp * stepsPerDegree + positionAtZero);
                int move        = (newPosition - currentPosition);
                logUpdate = "Moving Focuser to initial position @ " + currentTemp.ToString("0.0") + " C => " + newPosition.ToString("0") + " Steps";
                try
                {
                    if (move > 0)
                    {
                        tsxc.focMoveOut(move);
                    }
                    else
                    {
                        tsxc.focMoveIn(-move);
                    }
                }
                catch (Exception ex)
                {
                    logUpdate += " -- FAILED: " + ex.Message;
                }
            }
            else
            {
                logUpdate = "Cannot determine preset position for focuser";
            }
            return(logUpdate);
        }
Exemple #8
0
    /// Windows C# Sample Console Application: Filter
    ///
    /// ------------------------------------------------------------------------
    ///               Vaguely adapted from Filter.vbs  (Visual Basic Script)
    ///               Copyright (C) Software Bisque (2009?)
    ///
    ///				Converted 2017, R.McAlister
    ///
    /// ------------------------------------------------------------------------
    ///
    /// This C# console application demonstrates how to connect, change and disconnect a filter.  Along the way, most o
    ///  Along the way, most of the basic camera operating methods are also demonstrated.
    ///


    public void FilterSample()
    {
        ///Global Parameters
        double dExposure = 10.0; ///seconds
        int    ifilter   = 3;    ///4nd filter slot, probably clear/lumenscent      ///Create camera object and connect

        ccdsoftCamera tsx_cc = new ccdsoftCamera();

        tsx_cc.Connect();

        ///Set exposure length
        tsx_cc.ExposureTime = dExposure;

        ///Set frame type to Light frame
        tsx_cc.Frame = ccdsoftImageFrame.cdLight;

        ///Set filter
        tsx_cc.FilterIndexZeroBased = ifilter;

        ///Set preexposure delay
        tsx_cc.Delay = 5;  ///Possible filter change = 5 sec delay

        ///Set method type to Asynchronous (so we can demo the wait process)
        tsx_cc.Asynchronous = 0;

        ///Set for autodark
        tsx_cc.ImageReduction = ccdsoftImageReduction.cdAutoDark;

        ///Take image
        tsx_cc.TakeImage();

        ///Wait for completion (unnecessary if Asynchronous is set to "False"
        while (tsx_cc.State == ccdsoftCameraState.cdStateTakePicture)
        {
            System.Threading.Thread.Sleep(1000);
        }
        ;

        ///Clean up
        tsx_cc.Disconnect();
        return;
    }
Exemple #9
0
    /// Windows C# Sample Console Application: Cam
    ///
    /// ------------------------------------------------------------------------
    ///               Adapted from Cam.vbs  (Visual Basic Script)
    ///               Copyright (C) Software Bisque (2013)
    ///
    ///				Converted 2017, R.McAlister
    ///
    /// ------------------------------------------------------------------------
    ///
    /// This C# console application demonstrates the key elements of how to take images using the primary camera.

    public void CameraSample()
    {
        int iCamStatus;

        ///Create a TSX camera object
        ccdsoftCamera tsx_cam = new ccdsoftCamera();

        ///Connect TSX to the camera
        try {
            tsx_cam.Connect();
        }
        catch {
            MessageBox.Show("Camera Error");
            return;
        };


        ///Set the exposure time
        tsx_cam.ExposureTime = 15.0;
        ///SEt an exposure delay
        tsx_cam.Delay = 5.0;
        ///Set a frame type
        tsx_cam.Frame = ccdsoftImageFrame.cdLight;
        ///Set for autodark
        tsx_cam.ImageReduction = ccdsoftImageReduction.cdAutoDark;
        ///Set for synchronous imaging (this app will wait until done or error)
        tsx_cam.Asynchronous = 0;
        ///Take image
        iCamStatus = tsx_cam.TakeImage();
        if (iCamStatus != 0)
        {
            MessageBox.Show("Camera Error: " + iCamStatus.ToString());
        }
        ;

        ///Disconnect Camera
        tsx_cam.Disconnect();
    }
Exemple #10
0
    public void AutomatedSearchSample()
    {
        /// ********************************************************************************
        /// *
        /// * Below is the flow of program execution
        /// * See the subroutine TargetLoop to see where the real work is done

        ///Create Objects

        sky6RASCOMTele tsx_tele = new sky6RASCOMTele();
        ccdsoftCamera  tsx_cam  = new ccdsoftCamera();

        ///Connect Objects
        try {
            tsx_tele.Connect();
        }
        catch {
            MessageBox.Show("Telescope Connect Error");
            return;;
        };

        try {
            tsx_cam.Connect();
        }
        catch {
            MessageBox.Show("Camera Connection Error");
            return;;
        }

        ///Run the target loop
        TargetLoop();

        ///Disconnect objects
        tsx_tele.Disconnect();
        tsx_cam.Disconnect();
    }
Exemple #11
0
        //Autofocus manages the TSX functions to refocus the camera
        // every change of 1 degree in temperature.
        //The first fime autofocus is called, the telescope is slewed to
        // a position with Az = 90, Alt = 80.  Then @Focus2 is called with
        // TSX providing the star to use.  the temperature at that time is recorded.
        //Subsequent calls to autofocus check to see if the current focuser temperature
        //  is more than a degree celsius different from the last @autofocus2 time.
        //  if so, @autofocus2 is called again, although the telescope is not slewed.  And so on.

        /// <summary>
        /// Checks temp and runs autofocus 2 or 3 if exceeds one degree
        /// </summary>
        /// <param name="AtFocus2"></param>
        /// <returns></returns>
        public static string Check(bool AtFocus3)
        {
            //check to see if current temperature is a degree different from last temperature
            //  If so, then set up and run @focus2
            //AtFocus2 chooses to use a 15 degree x 15 degree field of view to choose a focus star
            //  If the current position is close to the meridian then a focus star on the other
            //  side of the meridian can be choosen and the mount will flip trying to get to it
            //  and, if using a dome, the slew does not wait for the dome slit to catch up (CLS flaw)
            //  so not only will an exception be thrown (Dome command in progress Error 125) the first image
            //   will be crap and the focus fail (as of DB 11360).  So, this method will point the mount to a
            //  altitude that is no more than 80 degrees at the same azimuth of the current position in order
            //  to avoid a flip and subsequent bullshit happening

            ccdsoftCamera tsxc = new ccdsoftCamera();

            tsxc.Connect();
            double currentTemp = tsxc.focTemperature;

            if (Math.Abs(currentTemp - afLastTemp) > 1)
            {
                //Going to have to refocus.

                ////Move to altitude away from meridian, if need be
                //sky6RASCOMTele tsxt = new sky6RASCOMTele();
                //tsxt.GetAzAlt();
                //double tAlt = tsxt.dAlt;
                //if (tAlt > 80)
                //{
                //    double tAz = tsxt.dAz;
                //    tAlt = 80.0;
                //    tsxt.SlewToAzAlt(tAz, tAlt, "AtFocus2ReadyPosition");
                //}

                //reset last temp
                afLastTemp = currentTemp;
                int syncSave = tsxc.Asynchronous;
                tsxc.Asynchronous = 0;
                if (AtFocus3)
                {
                    //Set the starchart size to 3 degrees so we minimize the chance of finding a star on
                    //  the wrong side of the meridian, if auto-selecting star
                    sky6StarChart tschrt = new sky6StarChart();
                    tschrt.FieldOfView = 3.0;
                    //run either of the focusing routings
                    try
                    {
                        int focStat = tsxc.AtFocus3(3, true);
                    }
                    catch (Exception e)
                    {
                        tsxc.Asynchronous = syncSave;
                        return("Focus Check: " + e.Message);
                    }
                }
                else
                {
                    try
                    {
                        int focStat = tsxc.AtFocus2();
                    }
                    catch (Exception e)
                    {
                        tsxc.Asynchronous = syncSave;
                        return("Focus Check: " + e.Message);
                    }
                    //Throw in a 5 sec wait to see if TSX can't set the telescope crosshairs back to original condition
                    System.Threading.Thread.Sleep(5000);
                }
                return("Focus Check: Focus successful");
            }
            return("Focus Check: Temperature change less than 1 degree");
        }
Exemple #12
0
    /// Windows C# Sample Console Application: ImageAnalysis
    ///
    /// ------------------------------------------------------------------------
    ///
    ///               Author: R.McAlister (2017)
    ///
    /// ------------------------------------------------------------------------
    ///
    /// This application demonstrates some of the functionality of the ccdsoftCamera and Image classes
    ///
    /// The example takes a 60 second exposure then produces a recommendation window to display computed
    ///   optimal exposure length and duration for a one hour shoot, based on average background noise.
    ///
    /// The algorithms are based on work by ...
    ///   John Smith: http://www.hiddenloft.com/notes/SubExposures.pdf
    ///   Charles Anstey: http://www.cloudynights.com/item.php?item_id=1622
    ///   Steve Cannistra: http://www.starrywonders.com/snr.html
    ///
    /// Note:  Where the required parameters like "gain" are not supplied through TSX, they are arbitrarily set for
    ///   an SBIG STF8300
    ///
    public void ImageAnalysisSample()
    {
        ///Open camera control and connect it to hardware
        ccdsoftCamera tsx_cc = new ccdsoftCamera();

        try {
            tsx_cc.Connect();
        }
        catch {
            MessageBox.Show("Camera Connect Error");
        };

        ///turn on autosave
        tsx_cc.AutoSaveOn = 1;
        ///Set for 60 second exposure, light frame with autodark
        tsx_cc.ExposureTime         = 60;
        tsx_cc.Frame                = ccdsoftImageFrame.cdLight;
        tsx_cc.ImageReduction       = ccdsoftImageReduction.cdAutoDark;
        tsx_cc.FilterIndexZeroBased = 3;  ///Assumed Lumescent, but change accordingly
        tsx_cc.Delay                = 5;  ///Possible filter change = 5 sec delay
        tsx_cc.Asynchronous         = 1;  ///Going to do a wait loop
        tsx_cc.TakeImage();
        while (tsx_cc.State == ccdsoftCameraState.cdStateTakePicture)
        {
            System.Threading.Thread.Sleep(1000);
        }
        ;

        ///Create image object
        ccdsoftImage tsx_im = new ccdsoftImage();
        int          imgerr = 0;

        ///Open the active image, if any
        try {
            imgerr = tsx_im.AttachToActive();
        }
        catch {
            MessageBox.Show("No Image Available:  " + imgerr.ToString());
            return;
        };

        const int totalexp = 60; ///Minutes for total exposure sequence

        double dGain     = 0.37; ///electrons per ADU for SBIG STF8000M as spec///d
        int    iPedestal = 0;    ///base pedestal
        double dRnoise   = 9.3;  ///read out noise in electrons
        double dNoiseFac = 0.05; ///maximum tolerable contribution of readout noise
        double dExpFac   = 1;    ///Exposure reduction factor
        double dSLambda  = 15;   ///Faint target ADU minimum
        double dSNRMax   = 0.9;  ///fraction of maximum achievable signal to noise ratio (Cannistra)

        ///Presumably an Image Link has already been performed
        ///Check on this is TBD

        int iPX    = tsx_im.FITSKeyword("NAXIS1");
        int iPY    = tsx_im.FITSKeyword("NAXIS2");
        int iPXBin = tsx_im.FITSKeyword("XBINNING");
        int iPYBin = tsx_im.FITSKeyword("YBINNING");
        ///Dim igain as integer = tsx_im.FITSKeyword("EGAIN");         ///TSX doesn///t pick this up, yet
        double dExpTime = tsx_im.FITSKeyword("EXPTIME");

        iPX = iPX - 1;
        iPY = iPY - 1;

        double dAvgABU = tsx_im.averagePixelValue();
        double dEsky   = ((dAvgABU - iPedestal) * dGain) / dExpTime;
        double dTorn   = (System.Math.Pow(dRnoise, 2) / (((System.Math.Pow((1 + dNoiseFac), 2) - 1) * dEsky)));

        ///Smith algorithm
        int iExp1  = (int)(dTorn / 2);
        int iReps1 = (int)((((totalexp * 60) / dTorn) - 1) * 2);
        ///Anstey algorithm
        int iExp2  = (int)((dSLambda * System.Math.Sqrt(totalexp * 60)) / (2 * System.Math.Sqrt(dAvgABU / dExpTime)));
        int iReps2 = (int)((totalexp * 60) / iExp2);
        ///Cannestr algorithm
        int iExp3  = (int)((System.Math.Pow(dSNRMax, 2) * System.Math.Pow(dRnoise, 2)) / ((dEsky) * (1 - System.Math.Pow(dSNRMax, 2))));
        int iReps3 = (int)((totalexp * 60) / iExp3);

        ///Display Results
        MessageBox.Show("Smith Model (at tolerable noise factor = 0.05):" + "\r\n" +
                        "     " + iExp1.ToString() + " second exposure with" + "\r\n" +
                        "     " + iReps1.ToString() + " repetitions per hour." + "\r\n" + "\r\n" +
                        "Anstey Model (at faint target minimum = 15):" + "\r\n" +
                        "     " + iExp2.ToString() + " second exposure with" + "\r\n" +
                        "     " + iReps2.ToString() + " repetitions per hour." + "\r\n" + "\r\n" +
                        "Cannestra Model (at SNR = 90% of maximum):" + "\r\n" +
                        "     " + iExp3.ToString() + " second exposure with" + "\r\n" +
                        "     " + iReps3.ToString() + " repetitions per hour.");

        return;
    }
    /// Windows C# Sample Console Application: ListSearch
    ///
    /// ------------------------------------------------------------------------
    ///               Vaguely adapted from ErrorHandling.vbs  (Visual Basic Script)
    ///               Copyright (C) Software Bisque (2013)
    ///
    ///				Converted 2015, R.McAlister
    ///
    /// ------------------------------------------------------------------------
    ///
    /// This C# console application demonstrates how to run the telescope through a list of targets as defined
    ///   by a list of names.
    ///
    ///  Note:  The gist of the orginal VBS script was entitled "ErrorHandling.vbs".  However, that
    ///  script, however labeled, performed the functions as adapted to VB herein.
    ///


    public void ListSearchSample()
    {
        ///Set the exposure time for the image
        double dExposure = 1.0;

        ///Target List
        string[] targetlist = new string[] {
            "NGC1348",
            "NGC1491",
            "NGC1708",
            "NGC179",
            "NGC1798",
            "NGC2165",
            "NGC2334",
            "NGC2436",
            "NGC2519",
            "NGC2605",
            "NGC2689",
            "NGC2666",
            "NGC4381",
            "NGC5785",
            "NGC5804",
            "NGC6895",
            "NGC6991",
            "NGC7011",
            "NGC7058",
            "M39",
            "NGC7071",
            "NGC7150",
            "NGC7295",
            "NGC7394",
            "NGC7686",
            "NGC7801"
        };

        ///Create objects

        sky6StarChart         objChrt = new sky6StarChart();
        sky6RASCOMTele        objTele = new sky6RASCOMTele();
        ccdsoftCamera         objCam  = new ccdsoftCamera();
        sky6Utils             objUtil = new sky6Utils();
        sky6ObjectInformation objInfo = new sky6ObjectInformation();

        ///Connect Objects
        objTele.Connect();
        objCam.Connect();

        ///Run loop over array of target names
        double dAlt;
        double dAz;
        bool   iError;

        foreach (string target in targetlist)
        {
            objChrt.Find(target);
            objInfo.Property(Sk6ObjectInformationProperty.sk6ObjInfoProp_ALT);
            dAlt = objInfo.ObjInfoPropOut;
            objInfo.Property(Sk6ObjectInformationProperty.sk6ObjInfoProp_AZM);
            dAz = objInfo.ObjInfoPropOut;

            try
            {
                objTele.SlewToAzAlt(dAz, dAlt, target);
            }
            catch
            {
                MessageBox.Show("An error has occurred running slew");
                return;
            };

            ///Set exposure time and try for image, exit if error
            objCam.ExposureTime = dExposure;
            try
            {
                objCam.TakeImage();
            }
            catch
            {
                MessageBox.Show("An error has occurred running image");
            };
        }

        ///Disconnect telescope and camera
        objTele.Disconnect();
        objCam.Disconnect();
        return;
    }
Exemple #14
0
/// Windows C# Sample Console Application: AutoGuide
///
/// ------------------------------------------------------------------------
///
///               Author: R.McAlister (2017)
///
/// ------------------------------------------------------------------------
///
/// This application performs the following steps:
///   Finds a target, M39 in this case
///   Turns off Autoguiding (if on)
///   Performs a Closed Loop Slew to the target
///   Takes an image with the Autoguide camera
///   Turns on Autoguiding
///
///

    public void AutoGuideSample()
    {
        ///Set connection to star chart and perform a find on M39 -- this will set the target for a CLS
        sky6StarChart tsx_sc = new sky6StarChart();

        tsx_sc.Find("M39");

        ///Create connection to autoguide camera and connect
        ccdsoftCamera tsx_ag = new ccdsoftCamera();

        ///Attach this object to the guider camera
        tsx_ag.Autoguider = 1;
        ///Find out with the guide camera is up to.  Abort if autoguiding or calibrating
        if (tsx_ag.Connect() == 0)
        {
            if ((tsx_ag.State == ccdsoftCameraState.cdStateAutoGuide) | (tsx_ag.State == ccdsoftCameraState.cdStateCalibrate))
            {
                tsx_ag.Abort();
            }
            ;
        }
        ;

        ///Create closed loop slew object
        ClosedLoopSlew tsx_cls = new ClosedLoopSlew();

        ///Set the exposure, filter to luminance and reduction, set the camera delay to 0 -- backlash
        /// should be picked up in the mount driver
        ccdsoftCamera tsx_cc = new ccdsoftCamera();

        tsx_cc.ImageReduction       = ccdsoftImageReduction.cdAutoDark;
        tsx_cc.FilterIndexZeroBased = 3; ///Luminance
        tsx_cc.ExposureTime         = 10;
        tsx_cc.Delay = 0;

        ///run CLS synchronously
        ///tsx_cls.Asynchronous = False  ///-- this setting doesn///t appear to work (member not found) as of DB8458

        ///Execute
        try
        {
            int clsstat = tsx_cls.exec();
        }
        catch
        {    ///Just close up: TSX will spawn error window
            MessageBox.Show("Closed Loop Slew error");
            return;
            ///Let it go for demo purposes
        };

        ///Connect AutoGuide camera in case it isn///t
        try
        {
            tsx_ag.Connect();
        }
        catch
        {
            MessageBox.Show("Guide camera connect error");
            return;
        };
        ///Take an image to use for Autoguiding, run the function synchronously
        tsx_ag.ExposureTime = 2;
        tsx_ag.Asynchronous = 0;
        tsx_ag.Subframe     = 0;
        var tstat = tsx_ag.TakeImage(); ///Just assume it works

        ///Turn asynchronous back on to get out of this
        tsx_ag.Asynchronous = 1;
        ///Fire off Autoguiding
        tsx_ag.Autoguide();
        return;
    }
/// Windows C# Sample Console Application: AutoFocus
///
/// ------------------------------------------------------------------------
///
///               Author: R.McAlister (2017)
///
/// ------------------------------------------------------------------------
///
/// This application performs the following steps:
///   Saves the current target and imaging parameters
///   Turns off Autoguiding (if on)
///   Turns on AutoFocus
///   Returns to the current target

/// Note that "Automatically slew telescope to nearest appropriate focus star" must be checked in the @Focus2 start-up window.
///

    public void AutoFocusSample()
    {
        int iFilter = 3; ///Luminescent, I hope

        ///Connect the telescope for some slewing
        sky6RASCOMTele tsx_tt = new sky6RASCOMTele();

        tsx_tt.Connect();

        ///Work around and Run @Focus2
        ///   Save current target name so it can be found again
        ///   Run @Focus2 (which preempts the observating list and object)
        ///   Restore current target, using Name with Find method
        ///   ClosedLoopSlew back to target

        ccdsoftCamera tsx_cc = new ccdsoftCamera();

        tsx_cc.Connect();
        tsx_cc.focConnect();

        ///Get current target name so we can return after running @focus2
        sky6ObjectInformation tsx_oi = new sky6ObjectInformation();

        tsx_oi.Property(Sk6ObjectInformationProperty.sk6ObjInfoProp_NAME1);
        string sTargetName = tsx_oi.ObjInfoPropOut;

        ///TBD: Set up parameters for @Focus2, if necessary
        ///
        ///Run Autofocus
        ///   Create a camera object
        ///   Launch the autofocus watching out for an exception -- which will be posted in TSX

        ///Save current camera delay, exposure and filter
        /// then set the camera delay = 0
        /// set the delay back when done with focusing

        tsx_cc.AutoSaveFocusImages = 0;
        var dCamDelay     = tsx_cc.Delay;
        var iCamReduction = tsx_cc.ImageReduction;
        var iCamFilter    = tsx_cc.FilterIndexZeroBased;
        var dCamExp       = tsx_cc.ExposureTime;
        var iFocStatus    = 0;

        tsx_cc.ImageReduction       = ccdsoftImageReduction.cdAutoDark;
        tsx_cc.FilterIndexZeroBased = 3; ///Luminance
        tsx_cc.ExposureTime         = 10;
        tsx_cc.Delay = 0;
        tsx_cc.FilterIndexZeroBased = iFilter;

        iFocStatus = tsx_cc.AtFocus2();

        ///Restore the current target and slew back to it
        ///   Run a Find on the target -- which makes it the "observation"
        ///   Perform Closed Loop Slew to the target

        sky6StarChart tsx_sc = new sky6StarChart();

        tsx_sc.Find(sTargetName);
        ///Run a Closed Loop Slew to return
        ClosedLoopSlew tsx_cls = new ClosedLoopSlew();

        ///Set the exposure, filter to luminance and reduction, set the camera delay to 0 -- any backlash
        /// should be picked up in the mount driver
        tsx_cc.ImageReduction       = ccdsoftImageReduction.cdAutoDark;
        tsx_cc.FilterIndexZeroBased = iFilter; ///Luminance, probably
        tsx_cc.ExposureTime         = 10;
        tsx_cc.Delay = 0;
        try
        {
            var clsstat = tsx_cls.exec();
        }
        catch
        {
            ///Just close up: TSX will spawn error window
            ///System.Windows.Forms.Show("AutoFocus return failure")
        };
        ///Put back the orginal settings

        tsx_cc.ImageReduction       = iCamReduction;
        tsx_cc.FilterIndexZeroBased = iCamFilter;
        tsx_cc.ExposureTime         = dCamExp;
        tsx_cc.Delay = dCamDelay;

        return;
    }