Example #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="filename"></param>
        public void LoadFromFile(string filename)
        {
            XmlDocument doc = new XmlDocument();

            doc.Load(filename);

            // 2010-09-10
            //
            // device defines node is null, file is not devicedefine file
            //
            XmlNode deviceDefinesNode = doc.SelectSingleNode(DeviceDefineNodeNames.DeviceDefineCollection);

            if (deviceDefinesNode == null)
            {
                logger.Error("load " + filename + " fail");
                return;
            }

            foreach (XmlNode deviceDefineNode in deviceDefinesNode.ChildNodes)
            {
                if (deviceDefineNode.Name == DeviceDefineNodeNames.DeviceDefine)
                {
                    string deviceType = XmlHelper.GetAttribute((XmlElement)deviceDefineNode,
                                                               DeviceDefineNodeNames.DeviceType);
                    string deviceText = XmlHelper.GetAttribute((XmlElement)deviceDefineNode,
                                                               DeviceDefineNodeNames.DeviceText);

                    // TODO: remove xmlOperaFactory DeviceDefineCollection
                    //
                    // TODO: 2010-07-28 add device parameter define
                    //
                    DeviceDefine dd = new DeviceDefine(deviceType, deviceText);

                    dd.DevcieDefineNode = deviceDefineNode;

                    XmlNode paramDefinesNode = deviceDefineNode.SelectSingleNode(ParameterNodeNames.ParameterDefineCollection);
                    if (paramDefinesNode != null)
                    {
                        ParameterDefineCollection paramDefines = XmlModbusParameterDefineBuilder.BuildParameterDefineCollection(paramDefinesNode);
                        dd.ParameterDefineCollection = paramDefines;
                    }

                    this.DeviceDefineCollection.Add(dd);

                    //this.CommuniSoft.DeviceDefineCollection.Add(dd);
                }
            }
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="node"></param>
        public XmlOperaFactory(CommuniSoft communiSoft, XmlNode deviceDefinesNode)
            : base(communiSoft)
        {
            if (deviceDefinesNode == null)
            {
                throw new ArgumentNullException("node");
            }
            this._deviceDefinesNode = deviceDefinesNode;

            foreach (XmlNode deviceDefineNode in deviceDefinesNode.ChildNodes)
            {
                if (deviceDefineNode.Name == DeviceDefineNodeNames.DeviceDefine)
                {
                    string deviceType = GetAttribute((XmlElement)deviceDefineNode,
                                                     DeviceDefineNodeNames.DeviceType);
                    string deviceText = GetAttribute((XmlElement)deviceDefineNode,
                                                     DeviceDefineNodeNames.DeviceText);

                    // TODO: remove xmlOperaFactory DeviceDefineCollection
                    //
                    // TODO: 2010-07-28 add device parameter define
                    //
                    DeviceDefine dd = new DeviceDefine(deviceType, deviceText);

                    XmlNode paramDefinesNode = deviceDefineNode.SelectSingleNode(ParameterNodeNames.ParameterDefineCollection);
                    if (paramDefinesNode != null)
                    {
                        ParameterDefineCollection paramDefines = XmlModbusParameterDefineBuilder.BuildParameterDefineCollection(paramDefinesNode);
                        dd.ParameterDefineCollection = paramDefines;
                    }

                    this.DeviceDefineCollection.Add(dd);

                    //this.CommuniSoft.DeviceDefineCollection.Add(dd);
                }
            }
        }