private void LoadSwitches() { this.switchIds.Items.Clear(); string switchDriverId = settings.Get("switchDriverId"); if (switchDriverId.Length == 0) { return; } using (ASCOM.DriverAccess.Switch sw = new ASCOM.DriverAccess.Switch(switchDriverId)) { sw.Connected = true; for (short n = 0; n < sw.MaxSwitch; n++) { string name = sw.GetSwitchName(n); this.switchIds.Items.Add(name); } } short switchId = 0; Int16.TryParse(settings.Get("switchId", "0"), out switchId); this.switchIds.SelectedIndex = switchId; }
private string GetSwitchStatus() { string st = ""; try { for (short i = 0; i < objSwitch.MaxSwitch; i++) { st = objSwitch.GetSwitchName(i).ToString() + "=" + objSwitch.GetSwitch(i).ToString(); txtInfo.Text += st + Environment.NewLine; } } catch (Exception Ex) { txtInfo.Text += Ex.ToString() + Environment.NewLine; } return st; }
/// <summary> /// Update fields /// </summary> private void UpdateFields() { if (IsConnected) { DriverName.Text = driver.Name; DriverInfo.Text = driver.DriverInfo; DriverVersion.Text = driver.DriverVersion; DriverDescription.Text = driver.Description; txtNumberOfSwitches.Text = driver.MaxSwitch.ToString(); txtIPaddr.Text = driver.Action("IPAddress", ""); txtCacheConnection.Text = driver.Action("GetCacheParameter", "CacheCheckConnection"); txtCacheSensorData.Text = driver.Action("GetCacheParameter", "CacheSensorState"); txtTimeout.Text = driver.Action("GetTimeout", ""); string stro = ""; for (int i = 1; i <= driver.MaxSwitch; i++) { try { //((TextBox)this.Controls.Find("txtOutput" + i, true)[0]).Text = driver.GetSwitch((short)(i - 1)).ToString(); ((TextBox)this.Controls.Find("txtOutName" + i, true)[0]).Text = driver.GetSwitchName((short)(i - 1)).ToString(); ((TextBox)this.Controls.Find("txtOutDesc" + i, true)[0]).Text = driver.GetSwitchDescription((short)(i - 1)).ToString(); stro = driver.Action("GetSwitchROFlag", (i - 1).ToString()).ToString(); ((TextBox)this.Controls.Find("txtOutput" + i, true)[0]).Text = stro; ((CheckBox)this.Controls.Find("chkOut" + i, true)[0]).Text = driver.GetSwitchName((short)(i - 1)).ToString(); ((CheckBox)this.Controls.Find("chkOut" + i, true)[0]).Checked = driver.GetSwitch((short)(i - 1)); toolTip1.SetToolTip(((CheckBox)this.Controls.Find("chkOut" + i, true)[0]), driver.GetSwitchDescription((short)(i - 1))); } catch (ASCOM.NotConnectedException ex) { txtLog.AppendText(Environment.NewLine); txtLog.AppendText("Oops, error. Press ok and we will try to reconnect" + Environment.NewLine + ex.ToString()); txtLog.AppendText(Environment.NewLine); //MessageBox.Show("Oops, error. Press ok and we will try to reconnect" + Environment.NewLine + ex.ToString()); toolStripStatusLabel1.Text = "try to reconnect" + " at " + DateTime.Now; txtLog.AppendText("try to reconnect" + " at " + DateTime.Now); txtLog.AppendText(Environment.NewLine); try { Connect(); } catch { toolStripStatusLabel1.Text = "Couldn't reconnect" + " at " + DateTime.Now; txtLog.AppendText("Couldn't reconnect" + " at " + DateTime.Now); txtLog.AppendText(Environment.NewLine); return; } } catch (Exception ex) { txtLog.AppendText(Environment.NewLine); txtLog.AppendText("Unknown exception" + Environment.NewLine + ex.ToString()); txtLog.AppendText(Environment.NewLine); MessageBox.Show("Unknown exception [" + i + "][" + stro + "]" + Environment.NewLine + ex.ToString()); } } } }