Exemplo n.º 1
0
        public override Boolean ExportSetting(XmlDocument xmlDoc, XmlNode xmlRoot)
        {
            //! check parameter
            if ((null == xmlDoc) || (null == xmlRoot))
            {
                return(false);
            }



            try
            {
                //! get root node

                XmlNode AdapterNode = null;
                //! find parameter group set from root node
                if (xmlRoot.Name != "AdapterSetting")
                {
                    AdapterNode = xmlRoot.SelectSingleNode("AdapterSetting");
                }
                else
                {
                    AdapterNode = xmlRoot;
                }

                if (null == AdapterNode)
                {
                    //! no parameter group set, so create a function set node
                    AdapterNode = xmlDoc.CreateNode(XmlNodeType.Element, "AdapterSetting", null);
                    xmlRoot.AppendChild(AdapterNode);
                }
                else
                {
                    //! try to find parameter group set
                    foreach (XmlNode enumNode in AdapterNode.ChildNodes)
                    {
                        //! find a specified parameter group set
                        if (enumNode.Name == "TelegraphHIDAdapter")
                        {
                            //! we find the parameter group set, remove this child
                            xmlRoot.RemoveChild(enumNode);
                            break;
                        }
                    }
                }

                //! create a new setting
                XmlElement newAdapterSetting = xmlDoc.CreateElement("TelegraphHIDAdapter");

                //! adapter setting
                do
                {
                    XmlElement xmlAdapterSetting = xmlDoc.CreateElement("Setting");
                    xmlAdapterSetting.InnerText = Settings;
                    newAdapterSetting.AppendChild(xmlAdapterSetting);
                }while (false);

                //! USB
                do
                {
                    XmlElement xmlUSBSetting = xmlDoc.CreateElement("USB");

                    xmlUSBSetting.SetAttribute("VID", m_VID.ToString("X4"));
                    xmlUSBSetting.SetAttribute("PID", m_PID.ToString("X4"));

                    newAdapterSetting.AppendChild(xmlUSBSetting);
                }while (false);


                AdapterNode.AppendChild(newAdapterSetting);
            }
            catch (Exception Err)
            {
                Err.ToString();
            }

            return(true);
        }
Exemplo n.º 2
0
        public override Boolean ExportDefaultSetting(XmlDocument xmlDoc, XmlNode xmlRoot)
        {
            //! check parameter
            if ((null == xmlDoc) || (null == xmlRoot))
            {
                return(false);
            }

            try
            {
                //! get root node

                XmlNode AdapterNode = null;
                //! find parameter group set from root node
                if (xmlRoot.Name != "AdapterDefaultSetting")
                {
                    AdapterNode = xmlRoot.SelectSingleNode("AdapterDefaultSetting");
                }
                else
                {
                    AdapterNode = xmlRoot;
                }

                if (null == AdapterNode)
                {
                    //! no parameter group set, so create a function set node
                    AdapterNode = xmlDoc.CreateNode(XmlNodeType.Element, "AdapterDefaultSetting", null);
                    xmlRoot.AppendChild(AdapterNode);
                }
                else
                {
                    //! try to find parameter group set
                    foreach (XmlNode enumNode in AdapterNode.ChildNodes)
                    {
                        //! find a specified parameter group set
                        if (enumNode.Name == "TelegraphSerialPortAdapter")
                        {
                            //! we find the parameter group set, remove this child
                            xmlRoot.RemoveChild(enumNode);
                            break;
                        }
                    }
                }

                //! create a new setting
                XmlElement newAdapterSetting = xmlDoc.CreateElement("TelegraphSerialPortAdapter");

                /*
                 * //! port
                 * do
                 * {
                 *  XmlElement xmlPort = xmlDoc.CreateElement("Port");
                 *  xmlPort.InnerText = m_strSerialPortSetting;
                 *  newAdapterSetting.AppendChild(xmlPort);
                 * }
                 * while (false);
                 */
                //! baudrate
                do
                {
                    XmlElement xmlBaudrate = xmlDoc.CreateElement("Baudrate");
                    xmlBaudrate.InnerText = m_SerialPort.Baudrate.ToString();
                    newAdapterSetting.AppendChild(xmlBaudrate);
                }while (false);

                //! databit
                do
                {
                    XmlElement xmlDatabits = xmlDoc.CreateElement("DataBits");
                    xmlDatabits.InnerText = m_SerialPort.DataBits.ToString();
                    newAdapterSetting.AppendChild(xmlDatabits);
                }while (false);

                //! stopbits
                do
                {
                    XmlElement xmlStopbits = xmlDoc.CreateElement("StopBits");
                    xmlStopbits.InnerText = m_SerialPort.StopBits.ToString();
                    newAdapterSetting.AppendChild(xmlStopbits);
                }while (false);

                //! parity
                do
                {
                    XmlElement xmlParity = xmlDoc.CreateElement("Parity");
                    xmlParity.InnerText = m_SerialPort.Parity.ToString();
                    newAdapterSetting.AppendChild(xmlParity);
                }while (false);

                AdapterNode.AppendChild(newAdapterSetting);
            }
            catch (Exception Err)
            {
                Err.ToString();
            }

            return(true);
        }