Browse Source

调整从内存取设备参数

章政 6 years ago
parent
commit
b7d6f670a3

+ 47 - 47
PLCDataReader/Device/Information/DeviceStatusInfo.Designer.cs

@@ -31,8 +31,12 @@ namespace UAS_PLCDataReader.Device.Infomation
         private void InitializeComponent()
         {
             this.groupControl1 = new DevExpress.XtraEditors.GroupControl();
+            this.de_linecode = new UAS_PLCDataReader.CustomerControl.ValueLabel.ValueLabel();
+            this.de_address = new UAS_PLCDataReader.CustomerControl.ValueLabel.ValueLabel();
             this.labelControl4 = new DevExpress.XtraEditors.LabelControl();
+            this.de_wccode = new UAS_PLCDataReader.CustomerControl.ValueLabel.ValueLabel();
             this.labelControl3 = new DevExpress.XtraEditors.LabelControl();
+            this.de_name = new UAS_PLCDataReader.CustomerControl.ValueLabel.ValueLabel();
             this.labelControl2 = new DevExpress.XtraEditors.LabelControl();
             this.labelControl1 = new DevExpress.XtraEditors.LabelControl();
             this.groupControl2 = new DevExpress.XtraEditors.GroupControl();
@@ -46,15 +50,11 @@ namespace UAS_PLCDataReader.Device.Infomation
             this.labelControl9 = new DevExpress.XtraEditors.LabelControl();
             this.labelControl14 = new DevExpress.XtraEditors.LabelControl();
             this.groupControl3 = new DevExpress.XtraEditors.GroupControl();
+            this.dpg_runtime = new UAS_PLCDataReader.CustomerControl.ValueLabel.ValueLabel();
             this.dpg_count = new UAS_PLCDataReader.CustomerControl.ValueLabel.ValueLabel();
             this.dpg_receivedatasize = new UAS_PLCDataReader.CustomerControl.ValueLabel.ValueLabel();
             this.dpg_senddatasize = new UAS_PLCDataReader.CustomerControl.ValueLabel.ValueLabel();
             this.dpg_starttime = new UAS_PLCDataReader.CustomerControl.ValueLabel.ValueLabel();
-            this.de_linecode = new UAS_PLCDataReader.CustomerControl.ValueLabel.ValueLabel();
-            this.de_address = new UAS_PLCDataReader.CustomerControl.ValueLabel.ValueLabel();
-            this.de_wccode = new UAS_PLCDataReader.CustomerControl.ValueLabel.ValueLabel();
-            this.de_name = new UAS_PLCDataReader.CustomerControl.ValueLabel.ValueLabel();
-            this.dpg_runtime = new UAS_PLCDataReader.CustomerControl.ValueLabel.ValueLabel();
             ((System.ComponentModel.ISupportInitialize)(this.groupControl1)).BeginInit();
             this.groupControl1.SuspendLayout();
             ((System.ComponentModel.ISupportInitialize)(this.groupControl2)).BeginInit();
@@ -79,6 +79,22 @@ namespace UAS_PLCDataReader.Device.Infomation
             this.groupControl1.TabIndex = 0;
             this.groupControl1.Text = "设备信息";
             // 
+            // de_linecode
+            // 
+            this.de_linecode.Appearance.Font = new System.Drawing.Font("黑体", 12F);
+            this.de_linecode.Location = new System.Drawing.Point(70, 137);
+            this.de_linecode.Name = "de_linecode";
+            this.de_linecode.Size = new System.Drawing.Size(0, 16);
+            this.de_linecode.TabIndex = 19;
+            // 
+            // de_address
+            // 
+            this.de_address.Appearance.Font = new System.Drawing.Font("黑体", 12F);
+            this.de_address.Location = new System.Drawing.Point(70, 106);
+            this.de_address.Name = "de_address";
+            this.de_address.Size = new System.Drawing.Size(0, 16);
+            this.de_address.TabIndex = 18;
+            // 
             // labelControl4
             // 
             this.labelControl4.Appearance.Font = new System.Drawing.Font("黑体", 12F);
@@ -88,6 +104,14 @@ namespace UAS_PLCDataReader.Device.Infomation
             this.labelControl4.TabIndex = 6;
             this.labelControl4.Text = "线体";
             // 
+            // de_wccode
+            // 
+            this.de_wccode.Appearance.Font = new System.Drawing.Font("黑体", 12F);
+            this.de_wccode.Location = new System.Drawing.Point(70, 74);
+            this.de_wccode.Name = "de_wccode";
+            this.de_wccode.Size = new System.Drawing.Size(0, 16);
+            this.de_wccode.TabIndex = 17;
+            // 
             // labelControl3
             // 
             this.labelControl3.Appearance.Font = new System.Drawing.Font("黑体", 12F);
@@ -97,6 +121,14 @@ namespace UAS_PLCDataReader.Device.Infomation
             this.labelControl3.TabIndex = 5;
             this.labelControl3.Text = "区域";
             // 
+            // de_name
+            // 
+            this.de_name.Appearance.Font = new System.Drawing.Font("黑体", 12F);
+            this.de_name.Location = new System.Drawing.Point(70, 41);
+            this.de_name.Name = "de_name";
+            this.de_name.Size = new System.Drawing.Size(0, 16);
+            this.de_name.TabIndex = 16;
+            // 
             // labelControl2
             // 
             this.labelControl2.Appearance.Font = new System.Drawing.Font("黑体", 12F);
@@ -222,10 +254,18 @@ namespace UAS_PLCDataReader.Device.Infomation
             this.groupControl3.Controls.Add(this.labelControl11);
             this.groupControl3.Location = new System.Drawing.Point(216, 12);
             this.groupControl3.Name = "groupControl3";
-            this.groupControl3.Size = new System.Drawing.Size(250, 349);
+            this.groupControl3.Size = new System.Drawing.Size(328, 349);
             this.groupControl3.TabIndex = 2;
             this.groupControl3.Text = "运行信息";
             // 
+            // dpg_runtime
+            // 
+            this.dpg_runtime.Appearance.Font = new System.Drawing.Font("黑体", 12F);
+            this.dpg_runtime.Location = new System.Drawing.Point(101, 74);
+            this.dpg_runtime.Name = "dpg_runtime";
+            this.dpg_runtime.Size = new System.Drawing.Size(0, 16);
+            this.dpg_runtime.TabIndex = 16;
+            // 
             // dpg_count
             // 
             this.dpg_count.Appearance.Font = new System.Drawing.Font("黑体", 12F);
@@ -258,51 +298,11 @@ namespace UAS_PLCDataReader.Device.Infomation
             this.dpg_starttime.Size = new System.Drawing.Size(0, 16);
             this.dpg_starttime.TabIndex = 0;
             // 
-            // de_linecode
-            // 
-            this.de_linecode.Appearance.Font = new System.Drawing.Font("黑体", 12F);
-            this.de_linecode.Location = new System.Drawing.Point(70, 137);
-            this.de_linecode.Name = "de_linecode";
-            this.de_linecode.Size = new System.Drawing.Size(0, 16);
-            this.de_linecode.TabIndex = 19;
-            // 
-            // de_address
-            // 
-            this.de_address.Appearance.Font = new System.Drawing.Font("黑体", 12F);
-            this.de_address.Location = new System.Drawing.Point(70, 106);
-            this.de_address.Name = "de_address";
-            this.de_address.Size = new System.Drawing.Size(0, 16);
-            this.de_address.TabIndex = 18;
-            // 
-            // de_wccode
-            // 
-            this.de_wccode.Appearance.Font = new System.Drawing.Font("黑体", 12F);
-            this.de_wccode.Location = new System.Drawing.Point(70, 74);
-            this.de_wccode.Name = "de_wccode";
-            this.de_wccode.Size = new System.Drawing.Size(0, 16);
-            this.de_wccode.TabIndex = 17;
-            // 
-            // de_name
-            // 
-            this.de_name.Appearance.Font = new System.Drawing.Font("黑体", 12F);
-            this.de_name.Location = new System.Drawing.Point(70, 41);
-            this.de_name.Name = "de_name";
-            this.de_name.Size = new System.Drawing.Size(0, 16);
-            this.de_name.TabIndex = 16;
-            // 
-            // dpg_runtime
-            // 
-            this.dpg_runtime.Appearance.Font = new System.Drawing.Font("黑体", 12F);
-            this.dpg_runtime.Location = new System.Drawing.Point(101, 74);
-            this.dpg_runtime.Name = "dpg_runtime";
-            this.dpg_runtime.Size = new System.Drawing.Size(0, 16);
-            this.dpg_runtime.TabIndex = 16;
-            // 
             // DeviceStatusInfo
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 14F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
-            this.ClientSize = new System.Drawing.Size(478, 373);
+            this.ClientSize = new System.Drawing.Size(556, 373);
             this.Controls.Add(this.groupControl3);
             this.Controls.Add(this.groupControl2);
             this.Controls.Add(this.groupControl1);

+ 11 - 3
PLCDataReader/Device/Information/DeviceStatusInfo.cs

@@ -39,11 +39,19 @@ namespace UAS_PLCDataReader.Device.Infomation
             {
                 BaseUtil.SetFormValue(Controls, dt);
             }
-            dt = (DataTable)dh.ExecuteSql("select dpg_count,round((sysdate-dpg_starttime)*1440)||'分钟' dpg_runtime,dpg_starttime,dpg_senddatasize,dpg_receivedatasize from DEVICEPOLLINGLOG where dpg_id=(select max(dpg_id) from DEVICEPOLLINGLOG where dpg_decode='" + de_code + "') and dpg_status='Running'", "select");
-            if (dt.Rows.Count > 0)
+            if (Main.ReturnData.ContainsKey(de_code))
             {
-                BaseUtil.SetFormValue(Controls, dt);
+                dpg_count.Text = Main.ReturnData[de_code].SendCount.ToString();
+                dpg_runtime.Text = (DateTime.Now - Main.ReturnData[de_code].StartTime).TotalMinutes.ToString().Substring(0, 3) + "分钟";
+                dpg_starttime.Text = Main.ReturnData[de_code].StartTime.ToString("yyyy-MM-dd HH:mm:ss");
+                dpg_senddatasize.Text = Main.ReturnData[de_code].SendDataSize.ToString();
+                dpg_receivedatasize.Text = Main.ReturnData[de_code].ReceiveDataSize.ToString();
             }
+            //dt = (DataTable)dh.ExecuteSql("select dpg_count,round((sysdate-dpg_starttime)*1440)||'分钟' dpg_runtime,dpg_starttime,dpg_senddatasize,dpg_receivedatasize from DEVICEPOLLINGLOG where dpg_id=(select max(dpg_id) from DEVICEPOLLINGLOG where dpg_decode='" + de_code + "') and dpg_status='Running'", "select");
+            //if (dt.Rows.Count > 0)
+            //{
+            //    BaseUtil.SetFormValue(Controls, dt);
+            //}
         }
 
         private void DeviceStatusInfo_KeyDown(object sender, KeyEventArgs e)

+ 198 - 0
PLCDataReader/Entity/Device.cs

@@ -0,0 +1,198 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace UAS_PLCDataReader.Entity
+{
+    public class Device
+    {
+        /// <summary>
+        /// 设备名称
+        /// </summary>
+        private string decode;
+        /// <summary>
+        /// 设备名称
+        /// </summary>
+        private string dename;
+        /// <summary>
+        /// 运行状态
+        /// </summary>
+        private string runStatus;
+        /// <summary>
+        /// 发送数据字节
+        /// </summary>
+        private int sendDataSize;
+        /// <summary>
+        /// 接收数据字节
+        /// </summary>
+        private int receiveDataSize;
+        /// <summary>
+        /// 发送数据次数
+        /// </summary>
+        private int sendCount;
+        /// <summary>
+        /// 温度
+        /// </summary>
+        private float temperature;
+        /// <summary>
+        /// 投产数
+        /// </summary>
+        private int inQTY;
+        /// <summary>
+        /// 合格数
+        /// </summary>
+        private int okQTY;
+        /// <summary>
+        /// 启动时间
+        /// </summary>
+        private DateTime startTime;
+        /// <summary>
+        /// 返回参数
+        /// </summary>
+        private Dictionary<string, string> itemData;
+
+        public string Decode
+        {
+            get
+            {
+                return decode;
+            }
+
+            set
+            {
+                decode = value;
+            }
+        }
+
+        public string Dename
+        {
+            get
+            {
+                return dename;
+            }
+
+            set
+            {
+                dename = value;
+            }
+        }
+
+        public string RunStatus
+        {
+            get
+            {
+                return runStatus;
+            }
+
+            set
+            {
+                runStatus = value;
+            }
+        }
+
+        public int SendDataSize
+        {
+            get
+            {
+                return sendDataSize;
+            }
+
+            set
+            {
+                sendDataSize = value;
+            }
+        }
+
+        public int ReceiveDataSize
+        {
+            get
+            {
+                return receiveDataSize;
+            }
+
+            set
+            {
+                receiveDataSize = value;
+            }
+        }
+
+        public int SendCount
+        {
+            get
+            {
+                return sendCount;
+            }
+
+            set
+            {
+                sendCount = value;
+            }
+        }
+
+        public Dictionary<string, string> ItemData
+        {
+            get
+            {
+                return itemData;
+            }
+
+            set
+            {
+                itemData = value;
+            }
+        }
+
+        public DateTime StartTime
+        {
+            get
+            {
+                return startTime;
+            }
+
+            set
+            {
+                startTime = value;
+            }
+        }
+
+        public float Temperature
+        {
+            get
+            {
+                return temperature;
+            }
+
+            set
+            {
+                temperature = value;
+            }
+        }
+
+        public int InQTY
+        {
+            get
+            {
+                return inQTY;
+            }
+
+            set
+            {
+                inQTY = value;
+            }
+        }
+
+        public int OkQTY
+        {
+            get
+            {
+                return okQTY;
+            }
+
+            set
+            {
+                okQTY = value;
+            }
+        }
+    }
+}

+ 42 - 26
PLCDataReader/Main.cs

@@ -30,7 +30,7 @@ namespace UAS_PLCDataReader
         ModeBusTCPServer mbt = new ModeBusTCPServer();
         List<string> SQL = new List<string>();
         //存放所有的设备返回的数据,用于比较
-        public static Dictionary<string, Dictionary<string, string>> ReturnData = new Dictionary<string, Dictionary<string, string>>();
+        public static Dictionary<string, Entity.Device> ReturnData = new Dictionary<string, Entity.Device>();
 
         #region 初始化代码
         public Main()
@@ -426,10 +426,13 @@ namespace UAS_PLCDataReader
                     Command = dt1.Rows[0]["dc_value"].ToString();
                     SendCommandByteSize = Encoding.Default.GetBytes(Command.ToCharArray()).Length;
                 }
+                //发送指令
                 mbt.Send(IP, SendCoding, ReceiveCoding, Command);
+                //成功返回了信息
                 if (mbt.Returnvalue.ContainsKey(IP))
                 {
                     int ReceiveCommandByteSize = Encoding.Default.GetBytes(mbt.Returnvalue[IP].ToCharArray()).Length;
+                    //存放返回的所有数据
                     Dictionary<string, string> ItemData = new Dictionary<string, string>();
                     int[] Arr = BaseUtil.GetDecimalData(BaseUtil.ASCIIToString(mbt.Returnvalue[IP]), 8);
                     for (int i = 0; i < Arr.Length; i++)
@@ -439,42 +442,55 @@ namespace UAS_PLCDataReader
                     //如果不包含该项数据则在键值对中添加
                     if (!ReturnData.ContainsKey(Decode))
                     {
-                        ReturnData.Add(Decode, ItemData);
+                        //添加本地数据内容
+                        Entity.Device device = new Entity.Device();
+                        device.Decode = pl.DeviceCode;
+                        device.Dename = pl.DeviceName;
+                        device.StartTime = DateTime.Now;
+                        device.RunStatus = "Running";
+                        device.ReceiveDataSize += ReceiveCommandByteSize;
+                        device.SendDataSize += SendCommandByteSize;
+                        device.SendCount += 1;
+                        device.ItemData = ItemData;
+                        ReturnData.Add(Decode, device);
                     }
                     else
                     {
+                        ReturnData[Decode].ReceiveDataSize += ReceiveCommandByteSize;
+                        ReturnData[Decode].SendDataSize += SendCommandByteSize;
+                        ReturnData[Decode].SendCount += 1;
                         //检测键值对是否发生变化,发生变化时赋予新值
-                        if ((BaseUtil.CheckDicDiff(ReturnData[Decode], ItemData)))
+                        if ((BaseUtil.CheckDicDiff(ReturnData[Decode].ItemData, ItemData)))
                         {
-                            ReturnData[Decode] = ItemData;
+                            ReturnData[Decode].ItemData = ItemData;
                         }
                     }
                     mbt.Returnvalue.Remove(IP);
-                    SQL.Clear();
-                    //更新轮询状态
-                    sql.Clear();
-                    sql.Append("update DEVICEPOLLINGCONFIG set dpc_status='Running' where dpc_decode='" + Decode + "' and dpc_dccode='" + Dccode + "'");
-                    dh.ExecuteSql(sql.ToString(), "update");
-                    //更新轮询日志状态
-                    sql.Clear();
-                    sql.Append("update DEVICEPOLLINGLOG set dpg_status='Running',dpg_senddatasize=nvl(dpg_senddatasize,0)+" + SendCommandByteSize);
-                    sql.Append(",dpg_receivedatasize=nvl(dpg_receivedatasize,0)+" + ReceiveCommandByteSize + ",dpg_count=nvl(dpg_count,0)+1 ");
-                    sql.Append(" where dpg_id=(select max(dpg_id) from DEVICEPOLLINGLOG where dpg_decode='" + Decode + "')");
-                    dh.ExecuteSql(sql.ToString(), "update");
+                    //SQL.Clear();
+                    ////更新轮询状态
+                    //sql.Clear();
+                    //sql.Append("update DEVICEPOLLINGCONFIG set dpc_status='Running' where dpc_decode='" + Decode + "' and dpc_dccode='" + Dccode + "'");
+                    //dh.ExecuteSql(sql.ToString(), "update");
+                    ////更新轮询日志状态
+                    //sql.Clear();
+                    //sql.Append("update DEVICEPOLLINGLOG set dpg_status='Running',dpg_senddatasize=nvl(dpg_senddatasize,0)+" + SendCommandByteSize);
+                    //sql.Append(",dpg_receivedatasize=nvl(dpg_receivedatasize,0)+" + ReceiveCommandByteSize + ",dpg_count=nvl(dpg_count,0)+1 ");
+                    //sql.Append(" where dpg_id=(select max(dpg_id) from DEVICEPOLLINGLOG where dpg_decode='" + Decode + "')");
+                    //dh.ExecuteSql(sql.ToString(), "update");
                 }
                 else
                 {
-                    SQL.Clear();
-                    //更新轮询状态
-                    sql.Clear();
-                    sql.Append("update DEVICEPOLLINGCONFIG set dpc_status='Stop' where dpc_decode='" + Decode + "' and dpc_dccode='" + Dccode + "'");
-                    dh.ExecuteSql(sql.ToString(), "update");
-                    //更新轮询日志状态
-                    sql.Clear();
-                    sql.Append("update DEVICEPOLLINGLOG set dpg_status='Running',dpg_senddatasize=nvl(dpg_senddatasize,0)+");
-                    sql.Append(SendCommandByteSize + ",dpg_count=nvl(dpg_count,0)+1 ");
-                    sql.Append("where dpg_id=(select max(dpg_id) from DEVICEPOLLINGLOG where dpg_decode='" + Decode + "')");
-                    dh.ExecuteSql(sql.ToString(), "update");
+                    //SQL.Clear();
+                    ////更新轮询状态
+                    //sql.Clear();
+                    //sql.Append("update DEVICEPOLLINGCONFIG set dpc_status='Stop' where dpc_decode='" + Decode + "' and dpc_dccode='" + Dccode + "'");
+                    //dh.ExecuteSql(sql.ToString(), "update");
+                    ////更新轮询日志状态
+                    //sql.Clear();
+                    //sql.Append("update DEVICEPOLLINGLOG set dpg_status='Running',dpg_senddatasize=nvl(dpg_senddatasize,0)+");
+                    //sql.Append(SendCommandByteSize + ",dpg_count=nvl(dpg_count,0)+1 ");
+                    //sql.Append("where dpg_id=(select max(dpg_id) from DEVICEPOLLINGLOG where dpg_decode='" + Decode + "')");
+                    //dh.ExecuteSql(sql.ToString(), "update");
                 }
             }
         }