Преглед на файлове

轮询指令接收处理

章政 преди 7 години
родител
ревизия
c6a9d3a10c
променени са 3 файла, в които са добавени 73 реда и са изтрити 26 реда
  1. 3 21
      UAS_DeviceMonitor/Main.Designer.cs
  2. 34 2
      UAS_DeviceMonitor/Main.cs
  3. 36 3
      UAS_DeviceMonitor/PublicMethod/ModeBusTCPServer.cs

+ 3 - 21
UAS_DeviceMonitor/Main.Designer.cs

@@ -35,11 +35,6 @@ namespace UAS_DeviceMonitor
         {
             System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Main));
             DevExpress.XtraBars.Ribbon.GalleryItemGroup galleryItemGroup1 = new DevExpress.XtraBars.Ribbon.GalleryItemGroup();
-            DevExpress.XtraBars.Ribbon.GalleryItem galleryItem1 = new DevExpress.XtraBars.Ribbon.GalleryItem();
-            DevExpress.Utils.SuperToolTip superToolTip1 = new DevExpress.Utils.SuperToolTip();
-            DevExpress.Utils.ToolTipTitleItem toolTipTitleItem1 = new DevExpress.Utils.ToolTipTitleItem();
-            DevExpress.Utils.ToolTipItem toolTipItem1 = new DevExpress.Utils.ToolTipItem();
-            DevExpress.Utils.ToolTipTitleItem toolTipTitleItem2 = new DevExpress.Utils.ToolTipTitleItem();
             this.RibbonNav = new DevExpress.XtraBars.Ribbon.RibbonControl();
             this.ButtonDeviceList = new DevExpress.XtraBars.BarButtonItem();
             this.ButtonDeviceNetSetting = new DevExpress.XtraBars.BarButtonItem();
@@ -1021,6 +1016,7 @@ namespace UAS_DeviceMonitor
             this.dpc_status.Caption = "状态";
             this.dpc_status.FieldName = "DPC_STATUS";
             this.dpc_status.Name = "dpc_status";
+            this.dpc_status.OptionsColumn.AllowEdit = false;
             this.dpc_status.Visible = true;
             this.dpc_status.VisibleIndex = 6;
             this.dpc_status.Width = 90;
@@ -1198,6 +1194,7 @@ namespace UAS_DeviceMonitor
             this.PageDeviceStatus.PageVisible = false;
             this.PageDeviceStatus.Size = new System.Drawing.Size(1027, 577);
             this.PageDeviceStatus.Text = "xtraTabPage1";
+            this.PageDeviceStatus.VisibleChanged += new System.EventHandler(this.PageDeviceStatus_VisibleChanged);
             // 
             // GalleryDeviceStatus
             // 
@@ -1213,21 +1210,6 @@ namespace UAS_DeviceMonitor
             galleryItemGroup1.Caption = "Group9";
             galleryItemGroup1.CaptionAlignment = DevExpress.XtraBars.Ribbon.GalleryItemGroupCaptionAlignment.Center;
             galleryItemGroup1.CaptionControlSize = new System.Drawing.Size(200, 200);
-            galleryItem1.Caption = "Item27";
-            galleryItem1.HoverImage = global::UAS_DeviceMonitor.Properties.Resources.netstatus_tx_64px_18991_easyicon_net;
-            galleryItem1.Image = global::UAS_DeviceMonitor.Properties.Resources.devicecontrol;
-            toolTipTitleItem1.Text = "123";
-            toolTipItem1.LeftIndent = 6;
-            toolTipItem1.Text = "123";
-            toolTipTitleItem2.LeftIndent = 6;
-            toolTipTitleItem2.Text = "123";
-            superToolTip1.Items.Add(toolTipTitleItem1);
-            superToolTip1.Items.Add(toolTipItem1);
-            superToolTip1.Items.Add(toolTipTitleItem2);
-            galleryItem1.SuperTip = superToolTip1;
-            galleryItem1.Value = 0;
-            galleryItemGroup1.Items.AddRange(new DevExpress.XtraBars.Ribbon.GalleryItem[] {
-            galleryItem1});
             this.GalleryDeviceStatus.Gallery.Groups.AddRange(new DevExpress.XtraBars.Ribbon.GalleryItemGroup[] {
             galleryItemGroup1});
             this.GalleryDeviceStatus.Gallery.ImageSize = new System.Drawing.Size(100, 100);
@@ -1236,7 +1218,7 @@ namespace UAS_DeviceMonitor
             this.GalleryDeviceStatus.Name = "GalleryDeviceStatus";
             this.GalleryDeviceStatus.Size = new System.Drawing.Size(1027, 546);
             this.GalleryDeviceStatus.TabIndex = 0;
-            this.GalleryDeviceStatus.Text = "galleryControl1";
+            this.GalleryDeviceStatus.Text = "GalleryDeviceStatus";
             // 
             // galleryControlClient1
             // 

+ 34 - 2
UAS_DeviceMonitor/Main.cs

@@ -4,15 +4,16 @@ using UAS_DeviceMonitor.DataOperate;
 using System.Data;
 using System.Text;
 using UAS_DeviceMonitor.Entity;
-using UAS_DeviceMonitor.Device.Command;
 using UAS_DeviceMonitor.PublicMethod;
 using DevExpress.XtraGrid.Views.Grid;
 using System.Collections.Generic;
 using System.Drawing;
+using DevExpress.XtraBars.Ribbon;
+using System.Threading;
 
 namespace UAS_DeviceMonitor
 {
-    public partial class Main : DevExpress.XtraBars.Ribbon.RibbonForm
+    public partial class Main : RibbonForm
     {
 
         StringBuilder sql = new StringBuilder();
@@ -300,6 +301,9 @@ namespace UAS_DeviceMonitor
                     Command = dt1.Rows[0]["dc_value"].ToString();
                 }
                 mbt.Send(IP, Coding, Command);
+                Thread.Sleep(5000);
+                Console.WriteLine(IP);
+                Console.WriteLine(mbt.Returnvalue);
             }
         }
 
@@ -377,5 +381,33 @@ namespace UAS_DeviceMonitor
             }
         }
         #endregion
+
+        #region 设备查看界面
+        private void PageDeviceStatus_VisibleChanged(object sender, EventArgs e)
+        {
+            if (PageDeviceStatus.PageVisible)
+            {
+                //清除之前添加的图像
+                for (int i = 0; i < GalleryDeviceStatus.Gallery.Groups.Count; i++)
+                {
+                    GalleryDeviceStatus.Gallery.Groups[i].Items.Clear();
+                }
+                DataTable dt = (DataTable)dh.ExecuteSql("select * from device left join DEVICEPOLLINGCONFIG on dpc_decode=de_code ", "select");
+                for (int i = 0; i < dt.Rows.Count; i++)
+                {
+                    GalleryItem gallery;
+                    if (dt.Rows[i]["dpc_status"].ToString() == "")
+                    {
+                        gallery = new GalleryItem(Properties.Resources.devicecontrol, dt.Rows[i]["de_name"].ToString(), dt.Rows[i]["de_code"].ToString());
+                    }
+                    else
+                    {
+                        gallery = new GalleryItem(Properties.Resources.close_24px_1069872_easyicon_net, dt.Rows[i]["de_name"].ToString(), dt.Rows[i]["de_code"].ToString());
+                    }
+                    GalleryDeviceStatus.Gallery.Groups[0].Items.Add(gallery);
+                }
+            }
+        }
+        #endregion
     }
 }

+ 36 - 3
UAS_DeviceMonitor/PublicMethod/ModeBusTCPServer.cs

@@ -12,9 +12,13 @@ namespace UAS_DeviceMonitor.PublicMethod
     {
         private bool isOpen = false;
 
+        private bool receiveData;
+
         Thread threadWatch = null; //负责监听客户端的线程
         Socket socketWatch = null; //负责监听客户端的套接字
 
+        string returnvalue;
+
         public bool IsOpen
         {
             get
@@ -54,6 +58,32 @@ namespace UAS_DeviceMonitor.PublicMethod
             }
         }
 
+        public bool ReceiveData
+        {
+            get
+            {
+                return receiveData;
+            }
+
+            set
+            {
+                receiveData = value;
+            }
+        }
+
+        public string Returnvalue
+        {
+            get
+            {
+                return returnvalue;
+            }
+
+            set
+            {
+                returnvalue = value;
+            }
+        }
+
         private string iP;
 
         private string port;
@@ -143,6 +173,7 @@ namespace UAS_DeviceMonitor.PublicMethod
                                     break;
                             }
                         }
+                        receiveData = false;
                     }
                     else
                     {
@@ -180,12 +211,10 @@ namespace UAS_DeviceMonitor.PublicMethod
                 //获取客户端的IP和端口号  
                 IPAddress clientIP = (connection.RemoteEndPoint as IPEndPoint).Address;
                 int clientPort = (connection.RemoteEndPoint as IPEndPoint).Port;
-
                 //让客户显示"连接成功的"的信息  
                 string sendmsg = "Connect Success!" + "LocalIP:" + clientIP + ",LocalPort" + clientPort.ToString();
                 byte[] arrSendMsg = Encoding.UTF8.GetBytes(sendmsg);
                 connection.Send(arrSendMsg);
-
                 //客户端网络结点号  
                 string remoteEndPoint = connection.RemoteEndPoint.ToString();
                 //显示与客户端连接情况
@@ -225,7 +254,10 @@ namespace UAS_DeviceMonitor.PublicMethod
                         break;
                     }
                     //将机器接受到的字节数组转换为人可以读懂的字符串     
-                    string strSRecMsg = Encoding.UTF8.GetString(arrServerRecMsg, 0, length);
+                    lock (returnvalue)
+                    {
+                        returnvalue = Encoding.UTF8.GetString(arrServerRecMsg, 0, length);
+                    }
                     //将发送的字符串信息附加到文本框txtMsg上     
                 }
                 catch (Exception)
@@ -243,6 +275,7 @@ namespace UAS_DeviceMonitor.PublicMethod
                     break;
                 }
             }
+            receiveData = true;
             if (socketServer != null)
             {
                 if (socketServer.RemoteEndPoint != null)