Exemple #1
0
        //
        // PUBLIC COM INTERFACE ITelescopeV3 IMPLEMENTATION
        //

        /// <summary>
        ///     ''' Displays the Setup Dialog form.
        ///     ''' If the user clicks the OK button to dismiss the form, then
        ///     ''' the new settings are saved, otherwise the old values are reloaded.
        ///     ''' THIS IS THE ONLY PLACE WHERE SHOWING USER INTERFACE IS ALLOWED!
        ///     ''' </summary>
        public void SetupDialog()
        {
            using (var f = new SetupDialogForm(Profile, this, (s) => this.LogMessage(LoggingFlags.Setup, s)))
            {
                if (f.ShowDialog() == DialogResult.OK)
                {
                    SharedResources.WriteProfile(f.GetProfileData());                     // Persist device configuration values to the ASCOM Profile store
                    SharedResources.SetTraceFlags(Profile.TraceFlags);
                }
            }
        }
Exemple #2
0
        public void CommandBlind(string Command, bool Raw = false)
        {
            _mutexCommand.WaitOne();

            try {
                SharedResources.SendMessageBlind(Command);
                LogMessage("CommandBlind", "Transmitted " + Command);
            }
            catch (Exception ex) {
                LogMessage("CommandBlind(" + Command + ")", "Error : " + ex.Message);
            }
            finally {
                _mutexCommand.ReleaseMutex();
            }
        }
Exemple #3
0
        public void CommandBlind(string command, bool raw)
        {
            SharedResources.OATCommandMutex.WaitOne();

            try
            {
                SharedResources.SendMessage(command);
            }
            catch (Exception ex)
            {
                logMessage(LoggingFlags.Focuser, $"CommandBlind - Exception{ex.Message}");
            }
            finally
            {
                SharedResources.OATCommandMutex.ReleaseMutex();
            }
        }
Exemple #4
0
        //
        // PUBLIC COM INTERFACE IFocuserV3 IMPLEMENTATION
        //

        #region Common properties and methods.

        /// <summary>
        /// Displays the Setup Dialog form.
        /// If the user clicks the OK button to dismiss the form, then
        /// the new settings are saved, otherwise the old values are reloaded.
        /// THIS IS THE ONLY PLACE WHERE SHOWING USER INTERFACE IS ALLOWED!
        /// </summary>
        public void SetupDialog()
        {
            // consider only showing the setup dialog if not connected
            // or call a different dialog if connected
            if (IsConnected)
            {
                MessageBox.Show("OAT is connected, use Telescope driver to control focuser manually.");
            }

            using (var f = new SetupDialogForm(Profile, null, null))
            {
                if (f.ShowDialog() == DialogResult.OK)
                {
                    SharedResources.WriteProfile(f.GetProfileData());                     // Persist device configuration values to the ASCOM Profile store
                }
            }
        }
Exemple #5
0
        //
        // PUBLIC COM INTERFACE ITelescopeV3 IMPLEMENTATION
        //

        /// <summary>
        ///     ''' Displays the Setup Dialog form.
        ///     ''' If the user clicks the OK button to dismiss the form, then
        ///     ''' the new settings are saved, otherwise the old values are reloaded.
        ///     ''' THIS IS THE ONLY PLACE WHERE SHOWING USER INTERFACE IS ALLOWED!
        ///     ''' </summary>
        public void SetupDialog()
        {
            // consider only showing the setup dialog if not connected
            // or call a different dialog if connected
            if (IsConnected)
            {
                MessageBox.Show("Already connected, just press OK");
            }

            using (var f = new SetupDialogForm(Profile)) {
                if (f.ShowDialog() == DialogResult.OK)
                {
                    SharedResources.WriteProfile(f
                                                 .GetProfileData()); // Persist device configuration values to the ASCOM Profile store
                }
            }
        }
Exemple #6
0
        public string CommandString(string Command, bool Raw = false)
        {
            _mutexCommand.WaitOne();

            try {
                var response = SharedResources.SendMessageString(Command);
                LogMessage("CommandString", "Received " + response);
                return(response);
            }
            catch (Exception ex) {
                LogMessage("CommandString(" + Command + ")", ex.Message);
                return("255");
            }
            finally {
                _mutexCommand.ReleaseMutex();
            }
        }
Exemple #7
0
        /// <summary>
        /// Required Interface functions of ITelescopeV3
        /// </summary>
        public void CommandBlind(string Command, bool Raw = false)
        {
            SharedResources.OATCommandMutex.WaitOne();

            try
            {
                SharedResources.SendMessage(Command);
            }
            catch (Exception ex)
            {
                LogMessage(LoggingFlags.Scope, "CommandBlind <! Exception : " + ex.Message);
            }
            finally
            {
                SharedResources.OATCommandMutex.ReleaseMutex();
            }
        }
Exemple #8
0
        public void CommandBlind(string command, bool raw)
        {
            SharedResources.OATCommandMutex.WaitOne();

            try
            {
                LogMessage("Focuser:CommandBlind", "Transmitting - " + command);
                SharedResources.SendMessage(command);
            }
            catch (Exception ex)
            {
                LogMessage("Focuser:CommandBlind(" + command + ")", "Error : " + ex.Message);
            }
            finally
            {
                SharedResources.OATCommandMutex.ReleaseMutex();
            }
        }
Exemple #9
0
        public string CommandString(string command, bool raw)
        {
            SharedResources.OATCommandMutex.WaitOne();

            try
            {
                var response = SharedResources.SendMessage(command);
                return(response);
            }
            catch (Exception ex)
            {
                logMessage(LoggingFlags.Focuser, $"CommandString({command}) => Exception {ex.Message}");
                return("255");
            }
            finally
            {
                SharedResources.OATCommandMutex.ReleaseMutex();
            }
        }
Exemple #10
0
        /// <summary>
        /// Required Interface functions of ITelescopeV3
        /// </summary>
        public string CommandString(string Command, bool raw = false)
        {
            SharedResources.OATCommandMutex.WaitOne();

            try
            {
                var response = SharedResources.SendMessage(Command);
                return(response);
            }
            catch (Exception ex)
            {
                LogMessage(LoggingFlags.Scope, "CommandString <! Exception :" + ex.Message);
                return("255");
            }
            finally
            {
                SharedResources.OATCommandMutex.ReleaseMutex();
            }
        }
Exemple #11
0
        /// <summary>
        /// Required Interface functions of ITelescopeV3
        /// </summary>
        public string CommandString(string Command, bool raw = false)
        {
            SharedResources.OATCommandMutex.WaitOne();

            try
            {
                LogMessage("CommandString", "Transmitting - " + Command);
                var response = SharedResources.SendMessage(Command);
                LogMessage("CommandString", "Received       " + response);
                return(response);
            }
            catch (Exception ex)
            {
                LogMessage("CommandString(" + Command + ")", ex.Message);
                return("255");
            }
            finally
            {
                SharedResources.OATCommandMutex.ReleaseMutex();
            }
        }
Exemple #12
0
        //
        // Constructor - Must be public for COM registration!
        //
        public Telescope()
        {
            _driverId = Marshal.GenerateProgIdForType(this.GetType());

            logMessageFunc = SharedResources.LogMessageCallback;
            SharedResources.SetTraceFlags(Profile.TraceFlags);
            LogMessage(LoggingFlags.Scope, $"Starting initialization - v{Version}");

            // TODO: Implement your additional construction here
            _transform.SetJ2000(_utilities.HMSToHours("02:31:51.12"), _utilities.DMSToDegrees("89:15:51.4"));
            _transform.SiteElevation = SiteElevation;
            _transform.SiteLatitude  = SiteLatitude;
            _transform.SiteLongitude = SiteLongitude;
            PolarisRAJNow            = _transform.RATopocentric;

            _azAltTransform.SiteElevation = SiteElevation;
            _azAltTransform.SiteLatitude  = SiteLatitude;
            _azAltTransform.SiteLongitude = SiteLongitude;

            LogMessage(LoggingFlags.Scope, "Completed initialization");
        }
Exemple #13
0
        public string Action(string ActionName, string ActionParameters)
        {
            if (SupportedActions.Contains(ActionName))
            {
                string retVal = "255";                 // Default error code
                switch (ActionName)
                {
                case "Telescope:getFirmwareVer":
                {
                    retVal = CommandString(":GVP#,#");                                     // Get firmware name
                    retVal = retVal + " " + CommandString(":GVN#,#");                      // Get firmware version number
                    break;
                }

                case "Utility:JNowtoJ2000":
                {
                    _transform.SetTopocentric(System.Convert.ToDouble(ActionParameters.Split(',')[0]),
                                              System.Convert.ToDouble(ActionParameters.Split(',')[1]));
                    retVal = _utilities.HoursToHMS(_transform.RAJ2000, ":", ":", string.Empty) + "&" +
                             DegreesToDmsWithSign(_transform.DecJ2000, "*", ":", string.Empty);
                    break;
                }

                case "Serial:PassThroughCommand":
                {
                    var s = ActionParameters.Split(',');
                    retVal = SharedResources.SendPassThroughCommand(s[0], s[1]);
                    break;
                }
                }

                LogMessage("Action(" + ActionName + ", " + ActionParameters + ")", retVal);
                return(retVal);
            }
            else
            {
                throw new ActionNotImplementedException("Action " + ActionName + " is not supported by this driver");
            }
        }
        private void btnConnect_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;

            if (btnConnect.Text == "Connect")
            {
                lblStatus.Text = "Connecting...";
                lblStatus.Update();

                _profile.ComPort  = (string)ComboBoxComPort.SelectedItem;
                _profile.BaudRate = Convert.ToInt64(comboBoxBaudRate.SelectedItem);
                SharedResources.WriteProfile(GetProfileData());

                txtLat.Text       = _profile.Latitude.ToString();
                txtLong.Text      = _profile.Longitude.ToString();
                txtElevation.Text = _profile.Elevation.ToString();

                try
                {
                    this._oat.Connected = true;
                    string fwVersion = this._oat.Action("Serial:PassThroughCommand", ":GVN#,#");
                    if (string.IsNullOrEmpty(fwVersion))
                    {
                        MessageBox.Show("Unable to communicate with OAT, even though it says we're connected. Exit the app and use Task Manager to kill the ASCOM.OpenAstroTracker process. Then try again.");
                        return;
                    }

                    var versionNumbers = fwVersion.Substring(1).Split(".".ToCharArray());
                    FirmwareVersion = long.Parse(versionNumbers[0]) * 10000L + long.Parse(versionNumbers[1]) * 100L + long.Parse(versionNumbers[2]);

                    lblFirmware.Text = fwVersion;
                    string hardware = this._oat.Action("Serial:PassThroughCommand", ":XGM#,#");
                    var    hwParts  = hardware.Split(',');
                    lblBoard.Text = hwParts[0];
                    string scopeDisplay = "";
                    for (int i = 3; i < hwParts.Length; i++)
                    {
                        if (hwParts[i] == "GPS")
                        {
                            scopeFeatures.Add("GPS");
                        }
                        else if (hwParts[i] == "AUTO_AZ_ALT")
                        {
                            scopeFeatures.Add("AutoPA");
                        }
                        else if (hwParts[i] == "AUTO_ALT")
                        {
                            scopeFeatures.Add("MotorALT");
                        }
                        else if (hwParts[i] == "AUTO_AZ")
                        {
                            scopeFeatures.Add("MotorAZ");
                        }
                        else if (hwParts[i] == "GYRO")
                        {
                            scopeFeatures.Add("Digital Level");
                        }
                        else if (hwParts[i] == "LCD_KEYPAD")
                        {
                            scopeDisplay = "16x2 LCD (w/ buttons) ";
                        }
                        else if (hwParts[i] == "LCD_I2C_MCP23008")
                        {
                            scopeDisplay = "LCD (I2C MCP23008) ";
                        }
                        else if (hwParts[i] == "LCD_I2C_MCP23017")
                        {
                            scopeDisplay = "LCD (I2C MCP23017)";
                        }
                        else if (hwParts[i] == "LCD_JOY_I2C_SSD1306")
                        {
                            scopeDisplay = "Pixel OLED (SSD1306)";
                        }
                        else if (hwParts[i] == "FOC")
                        {
                            scopeFeatures.Add("Focuser");
                        }
                        else if (hwParts[i] == "HSAH")
                        {
                            scopeFeatures.Add("AutoHomeRA");
                        }
                    }

                    if (!scopeFeatures.Any())
                    {
                        lblAddons.Text = "No addons";
                    }
                    else
                    {
                        lblAddons.Text = string.Join(", ", scopeFeatures);
                    }

                    if (string.IsNullOrEmpty(scopeDisplay))
                    {
                        scopeDisplay = "No display";
                    }

                    lblDisplay.Text = scopeDisplay;

                    string steps = _oat.Action("Serial:PassThroughCommand", ":XGR#,#");
                    numRASteps.Value = (Decimal)Math.Max(1, float.Parse(steps, _oatCulture));

                    steps             = _oat.Action("Serial:PassThroughCommand", ":XGD#,#");
                    numDECSteps.Value = (Decimal)Math.Max(1, float.Parse(steps, _oatCulture));

                    string speedFactor = _oat.Action("Serial:PassThroughCommand", ":XGS#,#");
                    numSpeedFactor.Value = (Decimal)float.Parse(speedFactor, _oatCulture);

                    string lst = _oat.Action("Serial:PassThroughCommand", ":XGL#,#");
                    if (lst.Length == 6)
                    {
                        lst = $"{lst.Substring(0, 2)}:{lst.Substring(2, 2)}:{lst.Substring(4)}";
                    }
                    lblLST.Text = lst;

                    string lon = _oat.Action("Serial:PassThroughCommand", ":Gg#,#");
                    double longitude;
                    if (TryParseDec(lon, out longitude))
                    {
                        if (FirmwareVersion < 11105)
                        {
                            longitude = 180 - longitude;
                        }
                        else
                        {
                            longitude = -longitude;
                        }
                    }
                    txtLong.Text       = longitude.ToString("0.00");
                    _profile.Longitude = longitude;

                    string lat = _oat.Action("Serial:PassThroughCommand", ":Gt#,#");
                    double latitude;
                    TryParseDec(lat, out latitude);
                    txtLat.Text       = latitude.ToString("0.00");
                    _profile.Latitude = latitude;

                    btnConnect.Text     = "Disconnect";
                    btnUpdate.Enabled   = false;
                    rdoRateFour.Checked = true;
                    SlewRate            = 4;
                    lblStatus.Text      = "Connected";
                    lblStatus.Update();
                    timerMountUpdate.Start();
                }
                catch (Exception ex)
                {
                    scopeFeatures.Clear();
                    this._oat.Connected = false;
                    btnConnect.Text     = "Connect";
                    lblStatus.Text      = "Connection failed";
                    lblStatus.Update();
                    MessageBox.Show("OATControl was unable to connect to OAT.\n\nMessage: " + ex.Message + "\n\nIf this was the first connection attempt after connecting, please try again.", "Connection failed!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                timerMountUpdate.Stop();
                this._oat.Connected = false;
                lblFirmware.Text    = "-";
                btnConnect.Text     = "Connect";
                lblStatus.Text      = "Disconnected";
            }

            EnableAccordingToConnectState();

            Cursor.Current = Cursors.Arrow;
        }