@wang_qi0307 5 years ago
parent
commit
d4e9cf77d9

+ 0 - 12
FileManager/Class1.cs

@@ -1,12 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace FileManager
-{
-    public class Class1
-    {
-    }
-}

+ 1 - 1
FileManager/FileManager.csproj

@@ -42,7 +42,7 @@
     <Reference Include="System.Xml" />
   </ItemGroup>
   <ItemGroup>
-    <Compile Include="Class1.cs" />
+    <Compile Include="XmlManager.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
   </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

+ 97 - 0
FileManager/XmlManager.cs

@@ -0,0 +1,97 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+using System.Xml;
+using System.IO;
+
+namespace FileManager
+{
+    public class XmlManager
+    {
+        #region 创建Xml文件,并创建根节点和属性
+        /// <summary>
+        /// 创建Xml文件,并创建根节点和属性
+        /// </summary>
+        /// <param name="xmlfullname">Xml文件的全路径</param>
+        /// <param name="rootnode">根节点名</param>
+        /// <param name="list_attributes">根节点的属性键值对</param>
+        /// <returns></returns>
+        public Boolean CreateXmlFile(String xmlfullname,String rootnode,List<KeyValuePair<String,String>> list_attributes)
+        {
+            XmlDocument xmlDoc = new XmlDocument();
+            //创建类型声明节点  
+            XmlNode node = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", "");
+            xmlDoc.AppendChild(node);
+            //创建根节点  
+            XmlNode root = xmlDoc.CreateElement(rootnode);
+            xmlDoc.AppendChild(root);
+            //为根节点增加属性
+            for (int i = 0; i < list_attributes.Count; i++)
+            {
+                XmlNode attribute = xmlDoc.CreateNode(XmlNodeType.Attribute, list_attributes[i].Key, null);
+                attribute.Value = list_attributes[i].Value;
+                root.Attributes.SetNamedItem(attribute);
+            }
+            try
+            {
+                xmlDoc.Save(xmlfullname);
+                return true;
+            }
+            catch (Exception e)
+            {
+                //显示错误信息  
+                Console.WriteLine(e.Message);
+                return false;
+            }
+        }
+        #endregion
+
+        #region 创建节点或子节点
+        /// <summary>    
+        /// 创建节点或子节点  
+        /// </summary>    
+        /// <param name="xmldoc">xml文档</param>    
+        /// <param name="parentnode">父节点</param>    
+        /// <param name="name">节点名</param>  
+        /// <param name="value">节点值</param>  
+        /// <param name="list_attributes">节点属性</param>
+        public Boolean CreateNode(String xmlfullname, String parentNode, string name, string value, List<KeyValuePair<String, String>> list_attributes)
+        {
+            if(!File.Exists(xmlfullname) || name.Trim()=="" || parentNode.Trim()=="")
+            {
+                return false;
+            }
+            XmlDocument xmlDoc = new XmlDocument();
+            try
+            {
+                xmlDoc.Load(xmlfullname);
+               
+                XmlNode root = xmlDoc.SelectSingleNode(parentNode);
+                XmlNode node = xmlDoc.CreateNode(XmlNodeType.Element, name, null);
+                //为根节点增加属性
+                for (int i = 0; i < list_attributes.Count; i++)
+                {
+                    XmlNode attribute = xmlDoc.CreateNode(XmlNodeType.Attribute, list_attributes[i].Key, null);
+                    attribute.Value = list_attributes[i].Value;
+                    node.Attributes.SetNamedItem(attribute);
+                }
+                if (value.Trim() != "")
+                {
+                    node.InnerText = value;
+                }
+                root.AppendChild(node);
+                
+                xmlDoc.Save(xmlfullname);
+                return true;
+            }
+            catch(Exception e)
+            {
+                return false;
+            }
+        }
+        #endregion
+    }
+}

File diff suppressed because it is too large
+ 200 - 227
HOZProject/FormUnitControl.Designer.cs


+ 25 - 0
HOZProject/FormUnitControl.cs

@@ -16,6 +16,7 @@ using System.Windows.Forms;
 
 using System.IO;
 using SmartSEMControl;
+using FileManager;
 
 namespace HOZProject
 {
@@ -25,6 +26,8 @@ namespace HOZProject
         static FactoryHardware factorySEM = FactoryHardware.Instance;
         ISEMControl iSEM = factorySEM.ISEM;
 
+        public XmlManager xmg = new XmlManager();
+
         #region 系统参数
         private String path = Directory.GetCurrentDirectory();
         #endregion
@@ -665,5 +668,27 @@ namespace HOZProject
         {
             iSEM.CMDMCFFilename("OPTON");
         }
+
+        private void btnCreatXml_Click(object sender, EventArgs e)
+        {
+            SaveFileDialog sfd = new SaveFileDialog();
+            sfd.Title = "生成Xml文件位置:";
+            sfd.FileName = "test.xml";
+            sfd.Filter = "XML文件|*.xml";
+            if (sfd.ShowDialog() == DialogResult.OK)
+            {
+                string fn = sfd.FileName;
+                List<KeyValuePair<String, String>> lkvp = new List<KeyValuePair<string, string>>();
+                lkvp.Add(new KeyValuePair<string, string>("key1","value1"));
+                lkvp.Add(new KeyValuePair<string, string>("key2", "value2"));
+                xmg.CreateXmlFile(fn,"XMLData",lkvp);
+
+                lkvp.Clear();
+                lkvp.Add(new KeyValuePair<string, string>("key3", "value3"));
+                lkvp.Add(new KeyValuePair<string, string>("key4", "value4"));
+                xmg.CreateNode(fn, "XMLData", "子节点", "", lkvp);
+                xmg.CreateNode(fn, "子节点", "子bb节点", "", lkvp);
+            }
+        }
     }
 }

+ 4 - 0
HOZProject/UnitControl.csproj

@@ -34,6 +34,10 @@
     <WarningLevel>4</WarningLevel>
   </PropertyGroup>
   <ItemGroup>
+    <Reference Include="FileManager, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>..\bin\Debug\FileManager.dll</HintPath>
+    </Reference>
     <Reference Include="System" />
     <Reference Include="System.Core" />
     <Reference Include="System.Xml.Linq" />

+ 4 - 0
SmartSEMControl/HardwareInterface.cs

@@ -52,6 +52,10 @@ namespace SmartSEMControl
         float GetWorkingDistance();
         Boolean SetWorkingDistance(float set);
 
+        //自动对焦
+        Boolean CmdAutoFocusCoarse();
+        Boolean CmdAutoFocusFine();
+
         //亮度
         float GetBrightness();
         Boolean SetBrightness(float set);

Some files were not shown because too many files changed in this diff