public Boolean Save() { Boolean Saved = true; try { XmlNode Node; m_Doc.RemoveAll(); Node = m_Doc.CreateXmlDeclaration("1.0", "utf-8", String.Empty); m_Doc.AppendChild(Node); Node = m_Doc.CreateComment(String.Format(" ScpControl Configuration Data. {0} ", DateTime.Now)); m_Doc.AppendChild(Node); Node = m_Doc.CreateWhitespace("\r\n"); m_Doc.AppendChild(Node); Node = m_Doc.CreateNode(XmlNodeType.Element, "ScpControl", null); { CreateTextNode(Node, "Idle", Idle.ToString()); CreateTextNode(Node, "LX", LX.ToString()); CreateTextNode(Node, "LY", LY.ToString()); CreateTextNode(Node, "RX", RX.ToString()); CreateTextNode(Node, "RY", RY.ToString()); CreateTextNode(Node, "LED", LED.ToString()); CreateTextNode(Node, "Rumble", Rumble.ToString()); CreateTextNode(Node, "Triggers", Triggers.ToString()); CreateTextNode(Node, "Latency", Latency.ToString()); CreateTextNode(Node, "DeadL", DeadL.ToString()); CreateTextNode(Node, "DeadR", DeadR.ToString()); CreateTextNode(Node, "Native", Native.ToString()); CreateTextNode(Node, "SSP", SSP.ToString()); CreateTextNode(Node, "Brightness", Brightness.ToString()); CreateTextNode(Node, "Bus", Bus.ToString()); CreateTextNode(Node, "Force", Repair.ToString()); } m_Doc.AppendChild(Node); m_Doc.Save(m_File); } catch { Saved = false; } return(Saved); }
private void UpdateSerialPortUI() { SerialPort P = GetSerialPort(comboBox1.Text); if (P == null) { label1.Enabled = false; comboBox2.Enabled = false; label2.Enabled = false; comboBox3.Enabled = false; label3.Enabled = false; comboBox4.Enabled = false; label4.Enabled = false; comboBox5.Enabled = false; checkBox1.Enabled = false; return; } Boolean wasOpen = P.IsOpen; PCF dwProvCapabilities = 0; SP dwSettableParams = 0; BAUD dwSettableBaud = 0; DATABITS wSettableData = 0; SSP wSettableStopParity = 0; try { if (!wasOpen) { P.Open(); } Object o = P.BaseStream.GetType().GetField("commProp", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(P.BaseStream); dwProvCapabilities = (PCF)(o.GetType().GetField("dwProvCapabilities", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public).GetValue(o)); dwSettableParams = (SP)(o.GetType().GetField("dwSettableParams", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public).GetValue(o)); dwSettableBaud = (BAUD)(o.GetType().GetField("dwSettableBaud", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public).GetValue(o)); wSettableData = (DATABITS)(o.GetType().GetField("wSettableData", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public).GetValue(o)); wSettableStopParity = (SSP)(o.GetType().GetField("wSettableStopParity", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public).GetValue(o)); } catch (Exception ex) { String buf = "Exception\r\n"; while (ex != null) { buf = String.Concat(buf, "\r\n", ex.Message, " [", ex.Source, "]\r\n", ex.StackTrace); ex = ex.InnerException; } MessageBox.Show(buf, "UpdateSerialPortUI()"); } if ((!wasOpen) && (P.IsOpen)) { P.Close(); } if (((dwSettableParams & SP.BAUD) == 0) || (dwSettableBaud == 0)) { label1.Enabled = false; comboBox2.Enabled = false; } else { label1.Enabled = true; comboBox2.Enabled = true; String s = comboBox2.Text; if ((s == null) || (s.Length == 0)) { s = "9600"; } comboBox2.Items.Clear(); if ((dwSettableBaud & BAUD._075) != 0) { comboBox2.Items.Add("75"); } if ((dwSettableBaud & BAUD._110) != 0) { comboBox2.Items.Add("110"); } if ((dwSettableBaud & BAUD._134_5) != 0) { comboBox2.Items.Add("134.5"); } if ((dwSettableBaud & BAUD._150) != 0) { comboBox2.Items.Add("150"); } if ((dwSettableBaud & BAUD._300) != 0) { comboBox2.Items.Add("300"); } if ((dwSettableBaud & BAUD._600) != 0) { comboBox2.Items.Add("600"); } if ((dwSettableBaud & BAUD._1200) != 0) { comboBox2.Items.Add("1200"); } if ((dwSettableBaud & BAUD._1800) != 0) { comboBox2.Items.Add("1800"); } if ((dwSettableBaud & BAUD._2400) != 0) { comboBox2.Items.Add("2400"); } if ((dwSettableBaud & BAUD._4800) != 0) { comboBox2.Items.Add("4800"); } if ((dwSettableBaud & BAUD._7200) != 0) { comboBox2.Items.Add("7200"); } if ((dwSettableBaud & BAUD._9600) != 0) { comboBox2.Items.Add("9600"); } if ((dwSettableBaud & BAUD._14400) != 0) { comboBox2.Items.Add("14400"); } if ((dwSettableBaud & BAUD._19200) != 0) { comboBox2.Items.Add("19200"); } if ((dwSettableBaud & BAUD._38400) != 0) { comboBox2.Items.Add("38400"); } if ((dwSettableBaud & BAUD._56K) != 0) { comboBox2.Items.Add("56000"); } if ((dwSettableBaud & BAUD._57600) != 0) { comboBox2.Items.Add("57600"); } if ((dwSettableBaud & BAUD._115200) != 0) { comboBox2.Items.Add("115200"); } if ((dwSettableBaud & BAUD._128K) != 0) { comboBox2.Items.Add("128000"); } comboBox2.DropDownStyle = ((dwSettableBaud & BAUD.USER) != 0) ? ComboBoxStyle.DropDown : ComboBoxStyle.DropDownList; if ((s != null) && (s.Length != 0)) { Boolean f = false; for (Int32 i = 0; i < comboBox2.Items.Count; i++) { if (String.Compare(s, comboBox2.Items[i] as String, StringComparison.OrdinalIgnoreCase) == 0) { comboBox2.SelectedIndex = i; f = true; break; } } if (!f) { if ((dwSettableBaud & BAUD.USER) != 0) { comboBox2.Text = s; } else { comboBox2.SelectedIndex = 0; } } } else { comboBox2.SelectedIndex = 0; } } if (((dwSettableParams & SP.DATABITS) == 0) || (wSettableData == 0)) { label2.Enabled = false; comboBox3.Enabled = false; } else { label2.Enabled = true; comboBox3.Enabled = true; String s = comboBox3.Text; if ((s == null) || (s.Length == 0)) { s = "8"; } comboBox3.Items.Clear(); if ((wSettableData & DATABITS._5) != 0) { comboBox3.Items.Add("5"); } if ((wSettableData & DATABITS._6) != 0) { comboBox3.Items.Add("6"); } if ((wSettableData & DATABITS._7) != 0) { comboBox3.Items.Add("7"); } if ((wSettableData & DATABITS._8) != 0) { comboBox3.Items.Add("8"); } if ((wSettableData & DATABITS._16) != 0) { comboBox3.Items.Add("16"); } if ((s != null) && (s.Length != 0)) { Boolean f = false; for (Int32 i = 0; i < comboBox3.Items.Count; i++) { if (String.Compare(s, comboBox3.Items[i] as String, StringComparison.OrdinalIgnoreCase) == 0) { comboBox3.SelectedIndex = i; f = true; break; } } if (!f) { comboBox3.SelectedIndex = 0; } } else { comboBox3.SelectedIndex = 0; } } if (((dwSettableParams & SP.PARITY) == 0) || ((wSettableStopParity & SSP.PARITY_MASK) == 0)) { label3.Enabled = false; comboBox4.Enabled = false; } else { label3.Enabled = true; comboBox4.Enabled = true; String s = comboBox4.Text; if ((s == null) || (s.Length == 0)) { s = "None"; } comboBox4.Items.Clear(); if ((wSettableStopParity & SSP.PARITY_NONE) != 0) { comboBox4.Items.Add("None"); } if ((wSettableStopParity & SSP.PARITY_EVEN) != 0) { comboBox4.Items.Add("Even"); } if ((wSettableStopParity & SSP.PARITY_ODD) != 0) { comboBox4.Items.Add("Odd"); } if ((wSettableStopParity & SSP.PARITY_MARK) != 0) { comboBox4.Items.Add("Mark"); } if ((wSettableStopParity & SSP.PARITY_SPACE) != 0) { comboBox4.Items.Add("Space"); } if ((s != null) && (s.Length != 0)) { Boolean f = false; for (Int32 i = 0; i < comboBox4.Items.Count; i++) { if (String.Compare(s, comboBox4.Items[i] as String, StringComparison.OrdinalIgnoreCase) == 0) { comboBox4.SelectedIndex = i; f = true; break; } } if (!f) { comboBox4.SelectedIndex = 0; } } else { comboBox4.SelectedIndex = 0; } } if (((dwSettableParams & SP.STOPBITS) == 0) || ((wSettableStopParity & SSP.STOPBITS_MASK) == 0)) { label4.Enabled = false; comboBox5.Enabled = false; } else { label4.Enabled = true; comboBox5.Enabled = true; String s = comboBox5.Text; if ((s == null) || (s.Length == 0)) { s = "1"; } comboBox5.Items.Clear(); if ((wSettableStopParity & SSP.STOPBITS_10) != 0) { comboBox5.Items.Add("1"); } if ((wSettableStopParity & SSP.STOPBITS_15) != 0) { comboBox5.Items.Add("1.5"); } if ((wSettableStopParity & SSP.STOPBITS_20) != 0) { comboBox5.Items.Add("2"); } if ((s != null) && (s.Length != 0)) { Boolean f = false; for (Int32 i = 0; i < comboBox5.Items.Count; i++) { if (String.Compare(s, comboBox5.Items[i] as String, StringComparison.OrdinalIgnoreCase) == 0) { comboBox5.SelectedIndex = i; f = true; break; } } if (!f) { comboBox5.SelectedIndex = 0; } } else { comboBox5.SelectedIndex = 0; } } if (((dwSettableParams & SP.HANDSHAKING) == 0) || ((dwProvCapabilities & PCF.RTSCTS) == 0)) { checkBox1.Enabled = false; } else { checkBox1.Enabled = true; } }