Prechádzať zdrojové kódy

plc的ip信息源修改

yc_t 7 rokov pred
rodič
commit
df23d66646

+ 18 - 12
parkMonitor/App.config

@@ -16,38 +16,44 @@
   </Equipments>
   <appSettings>
     <!--数据库连接配置文件-->
-    <!--<add key="SqlConnectionStr" value="Data Source=127.0.0.1;port=3306;uid=root;pooling=true;pwd=yct;database=zxpark;CharSet=utf8;Allow Zero Datetime=true;" />-->
-    <add key="SqlConnectionStr" value="Data Source=13.229.217.199;port=3306;uid=Ubuntu;pooling=true;pwd=12345678;database=zxpark;CharSet=utf8;Allow Zero Datetime=true;" />
+    <add key="SqlConnectionStr" value="Data Source=127.0.0.1;port=3306;uid=root;pooling=true;pwd=yct;database=zxpark;CharSet=utf8;Allow Zero Datetime=true;" />
+    <!--<add key="SqlConnectionStr" value="Data Source=13.229.217.199;port=3306;uid=Ubuntu;pooling=true;pwd=12345678;database=zxpark;CharSet=utf8;Allow Zero Datetime=true;" />-->
     <!--<add key="SqlConnectionStr" value="Data Source=192.168.0.55;port=3306;uid=root;pooling=true;pwd=x5;database=zxpark;CharSet=utf8;Allow Zero Datetime=true;" />-->
+    
     <!--日志写入地址配置文件-->
     <add key="LogPath" value="E:\\c#workspace\\LogDemo\\LoggerTest" />
-    <!--测量数据误差-->
+    <!--测量数据误差-->
     <add key="length" value="50" />
     <add key="width" value="50" />
     <add key="height" value="50" />
     <add key="wheelbase" value="50" />
     <!---->
     <add key="ClientSettingsProvider.ServiceUri" value="" />
-    <!--PLC通用配置-->
+    <!--PLC基本配置-->
+    <add key="PLC_ip_address" value="127.0.0.1"/>
+    <add key="PLC_port" value="127.0.0.1"/>
+    <add key="PLC_station" value="127.0.0.1"/>
+    <add key="PLC_start_address" value="127.0.0.1"/>
+    <add key="PLC_address_length" value="127.0.0.1"/>
+    
+    <!--PLC停取车地址配置-->
     <add key="fetch_completed_address" value="9"/>
     <add key="park_command_address" value="0"/>
     <add key="park_completed_address" value="8"/>
     <add key="laser_countdown" value="100"/>
-    <!--激光数据地址-->
-    <!--<add key="vehicleTypeLength_address" value="1"/>
-    <add key="vehicleTypeWidth_address" value="1"/>
-    <add key="vehicleTypeHeight_address" value="1"/>
-    <add key="vehicleTypeWheelbase_address" value="1"/>-->
     <!--一号激光设备配置-->
     <add key="laser1_status_address" value="1"/>
     <!--二号激光设备配置-->
     <add key="laser2_status_address" value=""/>
     <!--激光重测次数-->
     <add key="laser_rescan_count" value="3"/>
+    
     <!--停取车比例-->
     <add key="fetch_store_ratio" value="3"/>
-    <!--上位机(中控端)IP地址及配置serverScoket的端口-->
-    <add key ="WebConfig" value="192.168.111.8:9000"/>
+    
+    <!--上位机(Web线程)IP地址及配置serverScoket的端口-->
+    <!--<add key ="WebConfig" value="192.168.111.8:9000"/>-->
+    <add key ="WebConfig" value="127.0.0.1:9000"/>
     <!--PLC总控状态-->
     <add key="equipmentStatus_address" value="28"/>
     <!--取车写入PLC-->
@@ -63,7 +69,7 @@
     <add key="parkingEntX" value="24"/>
     <add key="parkingEntY" value="25"/>
     <add key="parkingEntZ" value="26"/>
-    <!--队时间限制-->
+    <!--队时间限制-->
     <add key="licenseTime" value="30"/>
     <add key="userTime" value="5"/>
   </appSettings>

+ 15 - 0
parkMonitor/bll/MainBll.cs

@@ -34,6 +34,21 @@ namespace parkMonitor.bll {
             }
 
             //数据库测试
+            //IDBOperator oper = new Operator();
+            //string sql = "insert into zxpark.vehicle value('京PH33X4','3','','','1','1','','1','','11')";
+            //MySqlConnection con = oper.getConn();
+            //try
+            //{
+            //    con.Open();
+            //}
+            //catch (Exception ex)
+            //{
+            //    Console.WriteLine(ex.Message);
+            //}
+            //MySqlCommand cmd = oper.getComm(sql, con);
+            //oper.getInsert(cmd);
+            //con.Close();
+
             //var dbt = new DBTest();
             //dbt.TestMethod();
             //DBOperation o = new DBOperation();

+ 3 - 3
parkMonitor/server/CoreThread/CoreThreadTest.cs

@@ -220,7 +220,7 @@ namespace parkMonitor.server.CoreThread
                     PLC.SetMessage(pm);
                     Console.WriteLine("停车,开激光:" + queueCmd.LicenseNum);
                     Log.WriteLog("停车,开激光:" + queueCmd.LicenseNum);
-                    UILogServer.ins.error("停车,开激光:" + queueCmd.LicenseNum);
+                    UILogServer.ins.info("停车,开激光:" + queueCmd.LicenseNum);
                     c.parkingEntX = parkingEntX;
                     c.parkingEntY = parkingEntY;
                     c.parkingEntZ = parkingEntZ;
@@ -289,7 +289,7 @@ namespace parkMonitor.server.CoreThread
 
                     Console.WriteLine("停车,抓车:" + queueCmd.LicenseNum);
                     Log.WriteLog("停车,抓车:" + queueCmd.LicenseNum);
-                    UILogServer.ins.error("停车,抓车:" + queueCmd.LicenseNum);
+                    UILogServer.ins.info("停车,抓车:" + queueCmd.LicenseNum);
                     Task storeSignal = Task.Factory.StartNew(() =>
                     {
                         while (true)
@@ -310,7 +310,7 @@ namespace parkMonitor.server.CoreThread
                     PLC.SetMessage(pm);
                     Console.WriteLine("停车完成,状态复位");
                     Log.WriteLog("停车完成,状态复位");
-                    UILogServer.ins.error("停车完成,状态复位");
+                    UILogServer.ins.info("停车完成,状态复位");
                     //根据号牌查找车型
                     int vehicleTypeID = oper.getVehicleTypeID(numberPlate);
                     //判断测量数据是否准确

+ 15 - 5
parkMonitor/server/PLCLinker/PLCLinker.cs

@@ -15,6 +15,7 @@ using parkMonitor.entity;
 using parkMonitor.model;
 using System.Diagnostics;
 using System.Configuration;
+using parkMonitor.server.uiLogServer;
 
 namespace parkMonitor.server
 {
@@ -717,11 +718,20 @@ namespace parkMonitor.server
             laser1CountDown = laser_countdown;
             laser2CountDown = laser_countdown;
             linkCount = 0;
-            ipString = MainModel.ins.xmlConfig.value("parkMonitor.config.PLC.ip", "127.0.0.1");
-            port = MainModel.ins.xmlConfig.valueInt("parkMonitor.config.PLC.port", 502);
-            station = (byte)MainModel.ins.xmlConfig.valueInt("parkMonitor.config.PLC.station", 1);
-            startAddr = MainModel.ins.xmlConfig.valueInt("parkMonitor.config.PLC.startAddress", 0);
-            addrLength = MainModel.ins.xmlConfig.valueInt("parkMonitor.config.PLC.addressLength", 50);
+            //ipString = MainModel.ins.xmlConfig.value("parkMonitor.config.PLC.ip", "127.0.0.1");
+            //port = MainModel.ins.xmlConfig.valueInt("parkMonitor.config.PLC.port", 502);
+            //station = (byte)MainModel.ins.xmlConfig.valueInt("parkMonitor.config.PLC.station", 1);
+            //startAddr = MainModel.ins.xmlConfig.valueInt("parkMonitor.config.PLC.startAddress", 0);
+            //addrLength = MainModel.ins.xmlConfig.valueInt("parkMonitor.config.PLC.addressLength", 50);
+            try
+            {
+                ipString = ConfigurationManager.AppSettings.Get("PLC_ip_address");
+                port = Int32.Parse(ConfigurationManager.AppSettings.Get("PLC_port"));
+                station = (byte)Int32.Parse(ConfigurationManager.AppSettings.Get("PLC_station"));
+                startAddr = Int32.Parse(ConfigurationManager.AppSettings.Get("PLC_start_address"));
+                addrLength = Int32.Parse(ConfigurationManager.AppSettings.Get("PLC_address_length"));
+            }
+            catch (Exception) { UILogServer.ins.info("PLC配置文件异常"); }
             LinkStart();
             //});
         }

+ 353 - 304
parkMonitor/view/mainWin/MainWindow.xaml.cs

@@ -31,308 +31,357 @@ using System.Windows.Media.Imaging;
 using System.Windows.Navigation;
 using System.Windows.Shapes;
 
-namespace parkMonitor {
-	/// <summary>
-	/// MainWindow.xaml 的交互逻辑
-	/// </summary>
-	public partial class MainWindow : Window {
-		List<ObjectTreeRootVM> lstObjectTree = new List<ObjectTreeRootVM>();
-
-		public MainWinVM winVM = new MainWinVM();
-
-		//List<PcStatusPanelVM> lstCentralVM = new List<PcStatusPanelVM>();
-
-		MainBll bll = new MainBll();
-
-		//NumMachineDetailVMCtl numMachineDetailVMCtl = new NumMachineDetailVMCtl();
-		//Dictionary<DeviceType, ObjectTreeRootVM> mapTree = new Dictionary<DeviceType, ObjectTreeRootVM>();
-
-		//PcStatusVMCtl centralPanelVMCtl = new PcStatusVMCtl();
-		//UIExample example = new UIExample();
-		ObjectVM selectedTreeVM = null;
-		ObservableCollection<DevDetailItemVM> selectedDetailItemVM = null;
-		XmlCtl xmlConfig = new XmlCtl();
-		private bool isScrollLogBox = true;
-
-		public MainWindow() {
-			InitializeComponent();
-
-			//winform 样式
-			System.Windows.Forms.Application.EnableVisualStyles();
-			System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false);
-
-			MainModel.ins.mainWin = this;
-			MainModel.ins.xmlConfig = xmlConfig;
-			loadConfig();
-
-			DataContext = winVM;
-			clearLogText();
-
-			//initTestData();
-
-			//initVM();
-			//winVM.panel.pcStatusCtl.cpu.Num = 50;
-
-			bll.init();
-
-			//example
-			//UIExample.ins.init();
-
-			//测试-模拟异步操作
-			//Task.Run(() => {
-			//	try {
-			//		Thread.Sleep(1500);
-
-			//		//UIExample.ins.changeNumMachine("001");
-			//		//UIExample.ins.removeNumMachine("002");
-			//		//UIExample.ins.changeLogInfo(">web server losed");
-			//		//UIExample.ins.changeLogInfo(">tcp connect refused");
-			//	} catch(Exception ex) {
-			//		Debug.WriteLine(ex.ToString());
-			//	}
-			//});
-		}
-
-		/// <summary>init ViewModel</summary>
-		//private void initVM() {
-
-		//}
-
-		private void loadConfig() {
-			try {
-				MainModel md = MainModel.ins;
-				PLCConfigMd plc = md.plcConfigMd;
-
-				xmlConfig.load(SysConst.configPath() + "config.xml");
-
-				//debug
-				bool isDebug = xmlConfig.attrBool("parkMonitor.win.debug", false);
-				if(isDebug) {
-					win.WindowState = WindowState.Normal;
-					win.WindowStyle = WindowStyle.SingleBorderWindow;
-				}
-
-				//plc
-				var xmlPLC = xmlConfig.child("parkMonitor.config.PLC");
-				plc.timeGap = xmlPLC.valueInt("timeGap", 2000);
-				//plc.strIp = xmlPLC.value("ip", "192.168.0.10");
-				//plc.strPort = xmlPLC.value("port", "502");
-				//plc.strStation = xmlPLC.value("station", "1");
-
-			} catch(Exception) {
-
-			}
-		}
-
-		/// <summary>测试数据</summary>
-		private void initTestData() {
-			DataContext = winVM = new DesignMainWinVM();
-		}
-
-		//树形菜单-选中item事件
-		private void treeObjectInfo_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e) {
-			try {
-				ObjectVM data = e.NewValue as ObjectVM;
-				//非叶子节点
-				if(data == null) {
-					return;
-				}
-
-				selectedTreeVM = null;
-				btnReset.Visibility = Visibility.Collapsed;
-
-				//test
-				//Debug.WriteLine(data.Pkey);
-				MonitorServer monitor = EquipmentSimpleFactory.ins.FindEquipment(EquipmentName.Monitor) as MonitorServer;
-				var detailVM = monitor.getSelectedDetailViewModel(data);
-				if(detailVM == null) {
-					//UIExample.ins.clickTree(data);
-					winVM.DevInfoDetail = null;
-					selectedTreeVM = null;
-					selectedDetailItemVM = null;
-					return;
-				} else {
-					winVM.DevInfoDetail = detailVM;
-
-					selectedTreeVM = data;
-					selectedDetailItemVM = detailVM;
-
-					//if(data.CanReset) {
-					//	btnReset.Visibility = Visibility.Visible;
-					//}
-				}
-			} catch(Exception) {
-
-			}
-
-			//Debug.WriteLine("设备名  :" + data.Name);
-			//Debug.WriteLine("设备类型:" + data.DevType);
-			//Debug.WriteLine("主键    :" + data.Pkey);
-			//winVM.DevInfoDetail[0].Data = (new Random()).Next(100).ToString();
-			//winVM.DevInfoDetail = new System.Collections.ObjectModel.ObservableCollection<DevDetailItemVM>();
-			//winVM.DevInfoDetail.Add(new DevDetailItemVM() { Name = "aaaa", Data = "111" });
-			//winVM.DevInfoDetail.Add(new DevDetailItemVM() { Name = "bbbbb", Data = "221" });
-		}
-
-		private void txtLog_PreviewKeyDown(object sender, KeyEventArgs e) {
-			e.Handled = true;
-		}
-
-		public void clearLogText() {
-			//logTextLen = 0;
-			rtxtLog.Document.Blocks.Clear();
-			rtxtLog.Document.LineHeight = 2;
-			//TextRange tr = new TextRange(rtxtLog.Document.ContentEnd, rtxtLog.Document.ContentEnd);
-			//tr.Text = "\r\n";
-			removeFirstLog();
-		}
-
-		public void removeFirstLog() {
-			Block block = rtxtLog.Document.Blocks.FirstOrDefault();
-			if(block != null) {
-				rtxtLog.Document.Blocks.Remove(block);
-			}
-		}
-
-		//int logTextLen = 0;
-		private void addLogText(string text, Brush color) {
-			rtxtLog.Document.Blocks.Add(new Paragraph(new Run(text) { Foreground = color }) { LineHeight = 1 });
-			//TextRange tr = new TextRange(rtxtLog.Document.ContentEnd, rtxtLog.Document.ContentEnd);
-			//tr.Text = text;
-			//tr.ApplyPropertyValue(TextElement.ForegroundProperty, color);
-		}
-
-		public void addLogText(UILogModel data) {
-			bool isScrollLogBox = IsScrolledToEnd(rtxtLog);
-			addLogText(data.info, data.color);
-			if(isScrollLogBox) {
-				scrollLogToEnd();
-			}
-		}
-
-		public void setLogText(List<UILogModel> data) {
-			bool isScrollLogBox = IsScrolledToEnd(rtxtLog);
-			//var startPos = rtxtLog.Selection.Start;
-			//var endPos = rtxtLog.Selection.End;
-
-			clearLogText();
-			for(int i = 0; i < data.Count; ++i) {
-				addLogText(data[i].info, data[i].color);
-			}
-			
-			//rtxtLog.Selection.Select(startPos, endPos);
-
-			if(isScrollLogBox) {
-				scrollLogToEnd();
-			}
-		}
-
-		/// <summary>设置日志信息</summary>
-		//public void setLogText(string text) {
-		//	bool isScrollLogBox = (txtLog.SelectionStart == txtLog.Text.Length);
-		//	int idx = txtLog.SelectionStart;
-		//	winVM.LogInfo = text;
-		//	txtLog.SelectionStart = idx;
-
-		//	if(isScrollLogBox) {
-		//		scrollLogToEnd();
-		//	}
-		//}
-
-		private bool IsScrolledToEnd(RichTextBox textBox) {
-			return textBox.VerticalOffset + textBox.ViewportHeight >= textBox.ExtentHeight;
-		}
-
-		/// <summary>滚动日志框到底部</summary>
-		private void scrollLogToEnd() {
-			//txtLog.SelectionStart = txtLog.Text.Length;
-			//txtLog.SelectionLength = 0;
-			//txtLog.ScrollToEnd();
-
-			rtxtLog.ScrollToEnd();
-		}
-
-		//点击关闭按钮事件
-		private void btnClose_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) {
-			OkBoxWin win = new OkBoxWin();
-			language.Language lng = language.Language.ins;
-			
-			win.show(this, lng.exit, lng.sureExit);
-
-			if(win.isOk) {
-				Close();
-			}
-		}
-
-		private void grdDevTreeType_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) {
-			winVM.IsDevTreeShowList = !winVM.IsDevTreeShowList;
-		}
-
-		private void win_Closed(object sender, EventArgs e) {
-			CmdServer.ins.send(CmdType.MainWinClosed);
-
-			xmlConfig.save();
-		}
-
-		/// <summary>点击复位按钮</summary>
-		private void btnReset_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) {
-			if(selectedTreeVM == null) {
-				return;
-			}
-		}
-
-		/// <summary>点击写入按钮</summary>
-		private void lstDetailInfo_ClickWrite(object sender, RoutedEventArgs e) {
-			try {
-				int idx = lstDetailInfo.SelectedIndex;
-				if(selectedDetailItemVM == null) {
-					return;
-				}
-				if(idx < 0 || idx >= selectedDetailItemVM.Count) {
-					return;
-				}
-
-				DevDetailItemVM itemVM = selectedDetailItemVM[idx];
-
-				WritePLCWin win = new WritePLCWin();
-				win.show(this, selectedTreeVM.Name, itemVM);
-				if(!win.isOk) {
-					return;
-				}
-
-				string val = win.value;
-				MonitorServer monitor = EquipmentSimpleFactory.ins.FindEquipment(EquipmentName.Monitor) as MonitorServer;
-				monitor.writeData(selectedTreeVM, idx, val);
-			} catch(Exception) {
-
-			}
-		}
-
-		/// <summary>点击复位按钮</summary>
-		private void lstDetailInfo_ClickReset(object sender, RoutedEventArgs e) {
-			try {
-				int idx = lstDetailInfo.SelectedIndex;
-				if(selectedDetailItemVM == null) {
-					return;
-				}
-				if(idx < 0 || idx >= selectedDetailItemVM.Count) {
-					return;
-				}
-
-				DevDetailItemVM itemVM = selectedDetailItemVM[idx];
-
-				OkBoxWin win = new OkBoxWin();
-				win.show(this, "确定复位?", "复位<" + itemVM.Name + ">?");
-				if(!win.isOk) {
-					return;
-				}
-
-				//PLCMonitorServer.ins.writeData(selectedTreeVM, idx, "0");
-				MonitorServer monitor = EquipmentSimpleFactory.ins.FindEquipment(EquipmentName.Monitor) as MonitorServer;
-				monitor.restData(selectedTreeVM, idx);
-			} catch(Exception) {
-
-			}
-		}
-	}
+namespace parkMonitor
+{
+    /// <summary>
+    /// MainWindow.xaml 的交互逻辑
+    /// </summary>
+    public partial class MainWindow : Window
+    {
+        List<ObjectTreeRootVM> lstObjectTree = new List<ObjectTreeRootVM>();
+
+        public MainWinVM winVM = new MainWinVM();
+
+        //List<PcStatusPanelVM> lstCentralVM = new List<PcStatusPanelVM>();
+
+        MainBll bll = new MainBll();
+
+        //NumMachineDetailVMCtl numMachineDetailVMCtl = new NumMachineDetailVMCtl();
+        //Dictionary<DeviceType, ObjectTreeRootVM> mapTree = new Dictionary<DeviceType, ObjectTreeRootVM>();
+
+        //PcStatusVMCtl centralPanelVMCtl = new PcStatusVMCtl();
+        //UIExample example = new UIExample();
+        ObjectVM selectedTreeVM = null;
+        ObservableCollection<DevDetailItemVM> selectedDetailItemVM = null;
+        XmlCtl xmlConfig = new XmlCtl();
+        private bool isScrollLogBox = true;
+
+        public MainWindow()
+        {
+            InitializeComponent();
+
+            //winform 样式
+            System.Windows.Forms.Application.EnableVisualStyles();
+            System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false);
+
+            MainModel.ins.mainWin = this;
+            //MainModel.ins.xmlConfig = xmlConfig;
+            //loadConfig();
+
+            DataContext = winVM;
+            clearLogText();
+
+            //initTestData();
+
+            //initVM();
+            //winVM.panel.pcStatusCtl.cpu.Num = 50;
+
+            bll.init();
+
+            //example
+            //UIExample.ins.init();
+
+            //测试-模拟异步操作
+            //Task.Run(() => {
+            //	try {
+            //		Thread.Sleep(1500);
+
+            //		//UIExample.ins.changeNumMachine("001");
+            //		//UIExample.ins.removeNumMachine("002");
+            //		//UIExample.ins.changeLogInfo(">web server losed");
+            //		//UIExample.ins.changeLogInfo(">tcp connect refused");
+            //	} catch(Exception ex) {
+            //		Debug.WriteLine(ex.ToString());
+            //	}
+            //});
+        }
+
+        /// <summary>init ViewModel</summary>
+        //private void initVM() {
+
+        //}
+
+        //private void loadConfig()
+        //{
+        //    try
+        //    {
+        //        MainModel md = MainModel.ins;
+        //        PLCConfigMd plc = md.plcConfigMd;
+
+        //        xmlConfig.load(SysConst.configPath() + "config.xml");
+
+        //        //debug
+        //        bool isDebug = xmlConfig.attrBool("parkMonitor.win.debug", false);
+        //        if (isDebug)
+        //        {
+        //            win.WindowState = WindowState.Normal;
+        //            win.WindowStyle = WindowStyle.SingleBorderWindow;
+        //        }
+
+        //        //plc
+        //        var xmlPLC = xmlConfig.child("parkMonitor.config.PLC");
+        //        plc.timeGap = xmlPLC.valueInt("timeGap", 2000);
+        //        //plc.strIp = xmlPLC.value("ip", "192.168.0.10");
+        //        //plc.strPort = xmlPLC.value("port", "502");
+        //        //plc.strStation = xmlPLC.value("station", "1");
+
+        //    }
+        //    catch (Exception)
+        //    {
+
+        //    }
+        //}
+
+        /// <summary>测试数据</summary>
+        private void initTestData()
+        {
+            DataContext = winVM = new DesignMainWinVM();
+        }
+
+        //树形菜单-选中item事件
+        private void treeObjectInfo_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
+        {
+            try
+            {
+                ObjectVM data = e.NewValue as ObjectVM;
+                //非叶子节点
+                if (data == null)
+                {
+                    return;
+                }
+
+                selectedTreeVM = null;
+                btnReset.Visibility = Visibility.Collapsed;
+
+                //test
+                //Debug.WriteLine(data.Pkey);
+                MonitorServer monitor = EquipmentSimpleFactory.ins.FindEquipment(EquipmentName.Monitor) as MonitorServer;
+                var detailVM = monitor.getSelectedDetailViewModel(data);
+                if (detailVM == null)
+                {
+                    //UIExample.ins.clickTree(data);
+                    winVM.DevInfoDetail = null;
+                    selectedTreeVM = null;
+                    selectedDetailItemVM = null;
+                    return;
+                }
+                else
+                {
+                    winVM.DevInfoDetail = detailVM;
+
+                    selectedTreeVM = data;
+                    selectedDetailItemVM = detailVM;
+
+                    //if(data.CanReset) {
+                    //	btnReset.Visibility = Visibility.Visible;
+                    //}
+                }
+            }
+            catch (Exception)
+            {
+
+            }
+
+            //Debug.WriteLine("设备名  :" + data.Name);
+            //Debug.WriteLine("设备类型:" + data.DevType);
+            //Debug.WriteLine("主键    :" + data.Pkey);
+            //winVM.DevInfoDetail[0].Data = (new Random()).Next(100).ToString();
+            //winVM.DevInfoDetail = new System.Collections.ObjectModel.ObservableCollection<DevDetailItemVM>();
+            //winVM.DevInfoDetail.Add(new DevDetailItemVM() { Name = "aaaa", Data = "111" });
+            //winVM.DevInfoDetail.Add(new DevDetailItemVM() { Name = "bbbbb", Data = "221" });
+        }
+
+        private void txtLog_PreviewKeyDown(object sender, KeyEventArgs e)
+        {
+            e.Handled = true;
+        }
+
+        public void clearLogText()
+        {
+            //logTextLen = 0;
+            rtxtLog.Document.Blocks.Clear();
+            rtxtLog.Document.LineHeight = 2;
+            //TextRange tr = new TextRange(rtxtLog.Document.ContentEnd, rtxtLog.Document.ContentEnd);
+            //tr.Text = "\r\n";
+            removeFirstLog();
+        }
+
+        public void removeFirstLog()
+        {
+            Block block = rtxtLog.Document.Blocks.FirstOrDefault();
+            if (block != null)
+            {
+                rtxtLog.Document.Blocks.Remove(block);
+            }
+        }
+
+        //int logTextLen = 0;
+        private void addLogText(string text, Brush color)
+        {
+            rtxtLog.Document.Blocks.Add(new Paragraph(new Run(text) { Foreground = color }) { LineHeight = 1 });
+            //TextRange tr = new TextRange(rtxtLog.Document.ContentEnd, rtxtLog.Document.ContentEnd);
+            //tr.Text = text;
+            //tr.ApplyPropertyValue(TextElement.ForegroundProperty, color);
+        }
+
+        public void addLogText(UILogModel data)
+        {
+            bool isScrollLogBox = IsScrolledToEnd(rtxtLog);
+            addLogText(data.info, data.color);
+            if (isScrollLogBox)
+            {
+                scrollLogToEnd();
+            }
+        }
+
+        public void setLogText(List<UILogModel> data)
+        {
+            bool isScrollLogBox = IsScrolledToEnd(rtxtLog);
+            //var startPos = rtxtLog.Selection.Start;
+            //var endPos = rtxtLog.Selection.End;
+
+            clearLogText();
+            for (int i = 0; i < data.Count; ++i)
+            {
+                addLogText(data[i].info, data[i].color);
+            }
+
+            //rtxtLog.Selection.Select(startPos, endPos);
+
+            if (isScrollLogBox)
+            {
+                scrollLogToEnd();
+            }
+        }
+
+        /// <summary>设置日志信息</summary>
+        //public void setLogText(string text) {
+        //	bool isScrollLogBox = (txtLog.SelectionStart == txtLog.Text.Length);
+        //	int idx = txtLog.SelectionStart;
+        //	winVM.LogInfo = text;
+        //	txtLog.SelectionStart = idx;
+
+        //	if(isScrollLogBox) {
+        //		scrollLogToEnd();
+        //	}
+        //}
+
+        private bool IsScrolledToEnd(RichTextBox textBox)
+        {
+            return textBox.VerticalOffset + textBox.ViewportHeight >= textBox.ExtentHeight;
+        }
+
+        /// <summary>滚动日志框到底部</summary>
+        private void scrollLogToEnd()
+        {
+            //txtLog.SelectionStart = txtLog.Text.Length;
+            //txtLog.SelectionLength = 0;
+            //txtLog.ScrollToEnd();
+
+            rtxtLog.ScrollToEnd();
+        }
+
+        //点击关闭按钮事件
+        private void btnClose_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
+        {
+            OkBoxWin win = new OkBoxWin();
+            language.Language lng = language.Language.ins;
+
+            win.show(this, lng.exit, lng.sureExit);
+
+            if (win.isOk)
+            {
+                Close();
+            }
+        }
+
+        private void grdDevTreeType_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
+        {
+            winVM.IsDevTreeShowList = !winVM.IsDevTreeShowList;
+        }
+
+        private void win_Closed(object sender, EventArgs e)
+        {
+            CmdServer.ins.send(CmdType.MainWinClosed);
+
+            xmlConfig.save();
+        }
+
+        /// <summary>点击复位按钮</summary>
+        private void btnReset_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
+        {
+            if (selectedTreeVM == null)
+            {
+                return;
+            }
+        }
+
+        /// <summary>点击写入按钮</summary>
+        private void lstDetailInfo_ClickWrite(object sender, RoutedEventArgs e)
+        {
+            try
+            {
+                int idx = lstDetailInfo.SelectedIndex;
+                if (selectedDetailItemVM == null)
+                {
+                    return;
+                }
+                if (idx < 0 || idx >= selectedDetailItemVM.Count)
+                {
+                    return;
+                }
+
+                DevDetailItemVM itemVM = selectedDetailItemVM[idx];
+
+                WritePLCWin win = new WritePLCWin();
+                win.show(this, selectedTreeVM.Name, itemVM);
+                if (!win.isOk)
+                {
+                    return;
+                }
+
+                string val = win.value;
+                MonitorServer monitor = EquipmentSimpleFactory.ins.FindEquipment(EquipmentName.Monitor) as MonitorServer;
+                monitor.writeData(selectedTreeVM, idx, val);
+            }
+            catch (Exception)
+            {
+
+            }
+        }
+
+        /// <summary>点击复位按钮</summary>
+        private void lstDetailInfo_ClickReset(object sender, RoutedEventArgs e)
+        {
+            try
+            {
+                int idx = lstDetailInfo.SelectedIndex;
+                if (selectedDetailItemVM == null)
+                {
+                    return;
+                }
+                if (idx < 0 || idx >= selectedDetailItemVM.Count)
+                {
+                    return;
+                }
+
+                DevDetailItemVM itemVM = selectedDetailItemVM[idx];
+
+                OkBoxWin win = new OkBoxWin();
+                win.show(this, "确定复位?", "复位<" + itemVM.Name + ">?");
+                if (!win.isOk)
+                {
+                    return;
+                }
+
+                //PLCMonitorServer.ins.writeData(selectedTreeVM, idx, "0");
+                MonitorServer monitor = EquipmentSimpleFactory.ins.FindEquipment(EquipmentName.Monitor) as MonitorServer;
+                monitor.restData(selectedTreeVM, idx);
+            }
+            catch (Exception)
+            {
+
+            }
+        }
+    }
 }