// // 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); } } }
// // 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 } } }
// // 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 } } }
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; }