Exemplo n.º 1
0
        //开始加载
        private static bool LoadData()
        {
            if (wrapper != null)
            {
                //必须先清理
            }
            //根据配置文件 初始化设备对象
            try
            {
                FileStream txt = File.Open("Device.xml", FileMode.OpenOrCreate);
                System.Xml.Serialization.XmlSerializer serial = new System.Xml.Serialization.XmlSerializer(typeof(Model_Data.DeviceModel));
                dm = (Model_Data.DeviceModel)serial.Deserialize(txt);
            }
            catch (Exception)
            {
            }
            if (dm == null)
            {
                return(false);
            }

            wrapper = PortSetting(dm);
            if (wrapper == null)
            {
                return(false);
            }
            wrapper.CreatCommand();
            return(true);
        }
Exemplo n.º 2
0
        //开始加载
        private static bool LoadData()
        {
            if (wrapper != null)
            {
                //必须先清理----程序正常流程不会发生这种情况
            }
            //根据配置文件 初始化设备对象
            try
            {
                string fileName = string.Empty;
                string culture  = ConfigurationManager.AppSettings["Culture"];
                if (string.IsNullOrEmpty(culture))
                {
                    culture = "EN";
                }
                fileName = System.Windows.Forms.Application.StartupPath + "\\" + string.Format("Device{0}.xml", culture);
                FileStream txt = File.Open(fileName, FileMode.Open);
                System.Xml.Serialization.XmlSerializer serial = new System.Xml.Serialization.XmlSerializer(typeof(Model_Data.DeviceModel));
                dm = (Model_Data.DeviceModel)serial.Deserialize(txt);
                txt.Close();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            if (dm == null)
            {
                return(false);
            }

            wrapper = PortSetting(dm);
            if (wrapper == null)
            {
                return(false);
            }
            wrapper.CreatCommand();
            return(true);
        }