Browse Source

调整比对

章政 6 years ago
parent
commit
b74defaf65

+ 34 - 0
PLCDataReader/Entity/Device.cs

@@ -51,6 +51,14 @@ namespace UAS_PLCDataReader.Entity
         /// 返回参数
         /// </summary>
         private Dictionary<string, string> itemData;
+        /// <summary>
+        /// 工单号
+        /// </summary>
+        private string makeCode;
+        /// <summary>
+        /// 指令编号
+        /// </summary>
+        private string dccode;
 
         public string Decode
         {
@@ -194,5 +202,31 @@ namespace UAS_PLCDataReader.Entity
                 okQTY = value;
             }
         }
+
+        public string MakeCode
+        {
+            get
+            {
+                return makeCode;
+            }
+
+            set
+            {
+                makeCode = value;
+            }
+        }
+
+        public string Dccode
+        {
+            get
+            {
+                return dccode;
+            }
+
+            set
+            {
+                dccode = value;
+            }
+        }
     }
 }

+ 14 - 7
PLCDataReader/Main.Designer.cs

@@ -128,6 +128,7 @@ namespace UAS_PLCDataReader
             this.PollSettingCheckedColumn = new DevExpress.XtraGrid.Columns.GridColumn();
             this.dpc_id = new DevExpress.XtraGrid.Columns.GridColumn();
             this.dpc_decode = new DevExpress.XtraGrid.Columns.GridColumn();
+            this.dpc_dename = new DevExpress.XtraGrid.Columns.GridColumn();
             this.dpc_interval = new DevExpress.XtraGrid.Columns.GridColumn();
             this.dpc_dccode = new DevExpress.XtraGrid.Columns.GridColumn();
             this.PollSettingItemSearchLookUpEdit = new DevExpress.XtraEditors.Repository.RepositoryItemSearchLookUpEdit();
@@ -168,7 +169,7 @@ namespace UAS_PLCDataReader
             this.GridViewWorkCenterStatus = new UAS_PLCDataReader.CustomerControl.GridViewWithSerialNum.GridViewWithSerialNum();
             this.TimerDeviceStatus = new System.Windows.Forms.Timer(this.components);
             this.CommonTipController = new DevExpress.Utils.ToolTipController(this.components);
-            this.dpc_dename = new DevExpress.XtraGrid.Columns.GridColumn();
+            this.TimerUpdateDevice = new System.Windows.Forms.Timer(this.components);
             ((System.ComponentModel.ISupportInitialize)(this.RibbonNav)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.MainTabControl)).BeginInit();
             this.MainTabControl.SuspendLayout();
@@ -1215,6 +1216,14 @@ namespace UAS_PLCDataReader
             this.dpc_decode.VisibleIndex = 1;
             this.dpc_decode.Width = 90;
             // 
+            // dpc_dename
+            // 
+            this.dpc_dename.Caption = "设备名称";
+            this.dpc_dename.FieldName = "DPC_DENAME";
+            this.dpc_dename.Name = "dpc_dename";
+            this.dpc_dename.Visible = true;
+            this.dpc_dename.VisibleIndex = 2;
+            // 
             // dpc_interval
             // 
             this.dpc_interval.Caption = "轮询间隔(秒)";
@@ -1615,13 +1624,10 @@ namespace UAS_PLCDataReader
             // 
             this.CommonTipController.AutoPopDelay = 10000;
             // 
-            // dpc_dename
+            // TimerUpdateDevice
             // 
-            this.dpc_dename.Caption = "设备名称";
-            this.dpc_dename.FieldName = "DPC_DENAME";
-            this.dpc_dename.Name = "dpc_dename";
-            this.dpc_dename.Visible = true;
-            this.dpc_dename.VisibleIndex = 2;
+            this.TimerUpdateDevice.Interval = 20000;
+            this.TimerUpdateDevice.Tick += new System.EventHandler(this.TimerUpdateDevice_Tick);
             // 
             // Main
             // 
@@ -1822,5 +1828,6 @@ namespace UAS_PLCDataReader
         private DevExpress.XtraGrid.Columns.GridColumn de_sourcecode;
         private DevExpress.XtraEditors.Repository.RepositoryItemDateEdit repositoryItemDateEdit1;
         private DevExpress.XtraGrid.Columns.GridColumn dpc_dename;
+        private System.Windows.Forms.Timer TimerUpdateDevice;
     }
 }

+ 61 - 5
PLCDataReader/Main.cs

@@ -31,6 +31,10 @@ namespace UAS_PLCDataReader
         List<string> SQL = new List<string>();
         //存放所有的设备返回的数据,用于比较
         public static Dictionary<string, Entity.Device> ReturnData = new Dictionary<string, Entity.Device>();
+        /// <summary>
+        /// 需要更新的设备列表
+        /// </summary>
+        public static Queue<Entity.Device> QueueUpdateDevice = new Queue<Entity.Device>();
 
         #region 初始化代码
         public Main()
@@ -124,6 +128,8 @@ namespace UAS_PLCDataReader
             ButtonAddNetConfig.Grid = GridDeviceNetSetting;
             ButtonSaveNetConfig.Grid = GridDeviceNetSetting;
 
+            TimerUpdateDevice.Start();
+
             Ptime = new Dictionary<int, PollingTimer>();
         }
         /// <summary>
@@ -276,6 +282,32 @@ namespace UAS_PLCDataReader
             }
             e.Handled = true;
         }
+
+        /// <summary>
+        /// 设备数据更新列表
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
+        private void TimerUpdateDevice_Tick(object sender, EventArgs e)
+        {
+            Console.WriteLine("Begin" + QueueUpdateDevice.Count);
+            while (QueueUpdateDevice.Count > 0)
+            {
+                Entity.Device item = QueueUpdateDevice.Dequeue();
+                SQL.Clear();
+                //更新轮询状态
+                sql.Clear();
+                sql.Append("update DEVICEPOLLINGCONFIG set dpc_status='Running' where dpc_decode='" + item.Decode + "' and dpc_dccode='" + item.Dccode + "'");
+                dh.ExecuteSql(sql.ToString(), "update");
+                //更新轮询日志状态
+                sql.Clear();
+                sql.Append("update DEVICEPOLLINGLOG set dpg_status='Running',dpg_senddatasize=nvl(dpg_senddatasize,0)+" + item.SendDataSize);
+                sql.Append(",dpg_receivedatasize=nvl(dpg_receivedatasize,0)+" + item.ReceiveDataSize + ",dpg_count=nvl(dpg_count,0)+1 ");
+                sql.Append(" where dpg_id=(select max(dpg_id) from DEVICEPOLLINGLOG where dpg_decode='" + item.Decode + "')");
+                dh.ExecuteSql(sql.ToString(), "update");
+            }
+            Console.WriteLine("End" + QueueUpdateDevice.Count);
+        }
         #endregion
 
         #region PageCommandSet业务代码(指令设置)
@@ -428,6 +460,27 @@ namespace UAS_PLCDataReader
                 }
                 //发送指令
                 mbt.Send(IP, SendCoding, ReceiveCoding, Command);
+                //如果不包含该项数据则在键值对中添加
+                if (!ReturnData.ContainsKey(Decode))
+                {
+                    //添加本地数据内容
+                    Entity.Device device = new Entity.Device();
+                    device.Decode = pl.DeviceCode;
+                    device.Dename = pl.DeviceName;
+                    device.StartTime = DateTime.Now;
+                    device.RunStatus = "Running";
+                    device.SendDataSize += SendCommandByteSize;
+                    device.SendCount += 1;
+                    device.Dccode = pl.CommandCode;
+                    ReturnData.Add(Decode, device);
+                }
+                else
+                {
+                    //每次更新轮询的数据
+                    ReturnData[Decode].SendDataSize += SendCommandByteSize;
+                    ReturnData[Decode].SendCount += 1;
+                    //检测键值对是否发生变化,发生变化时赋予新值
+                }
                 //成功返回了信息
                 if (mbt.Returnvalue.ContainsKey(IP))
                 {
@@ -439,7 +492,6 @@ namespace UAS_PLCDataReader
                     {
                         ItemData.Add("Item" + i, Arr[i].ToString());
                     }
-                    //如果不包含该项数据则在键值对中添加
                     if (!ReturnData.ContainsKey(Decode))
                     {
                         //添加本地数据内容
@@ -449,20 +501,24 @@ namespace UAS_PLCDataReader
                         device.StartTime = DateTime.Now;
                         device.RunStatus = "Running";
                         device.ReceiveDataSize += ReceiveCommandByteSize;
-                        device.SendDataSize += SendCommandByteSize;
-                        device.SendCount += 1;
+                        device.Dccode = pl.CommandCode;
                         device.ItemData = ItemData;
                         ReturnData.Add(Decode, device);
                     }
                     else
                     {
+                        if (ReturnData[Decode].ItemData == null)
+                        {
+                            ReturnData[Decode].ItemData = ItemData;
+                        }
+                        //每次更新轮询的数据
                         ReturnData[Decode].ReceiveDataSize += ReceiveCommandByteSize;
-                        ReturnData[Decode].SendDataSize += SendCommandByteSize;
-                        ReturnData[Decode].SendCount += 1;
                         //检测键值对是否发生变化,发生变化时赋予新值
                         if ((BaseUtil.CheckDicDiff(ReturnData[Decode].ItemData, ItemData)))
                         {
                             ReturnData[Decode].ItemData = ItemData;
+                            QueueUpdateDevice.Enqueue(ReturnData[Decode]);
+                            LogicHandler.DoDeviceDataDiffLog(pl.DeviceCode, pl.DeviceName, pl.CommandCode, User.UserName);
                         }
                     }
                     mbt.Returnvalue.Remove(IP);

+ 3 - 0
PLCDataReader/Main.resx

@@ -476,6 +476,9 @@
   <metadata name="CommonTipController.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
     <value>164, 18</value>
   </metadata>
+  <metadata name="TimerUpdateDevice.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+    <value>360, 12</value>
+  </metadata>
   <data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
     <value>
         AAABAAEAQEAAAAEAIAAoQgAAFgAAACgAAABAAAAAgAAAAAEAIAAAAAAAAEAAABMLAAATCwAAAAAAAAAA

+ 11 - 0
PLCDataReader/PublicMethod/LogicHandler.cs

@@ -37,5 +37,16 @@ namespace UAS_PLCDataReader.PublicMethod
                 return false;
             }
         }
+
+        /// <summary>
+        /// 进行差异日志记录
+        /// </summary>
+        public static void DoDeviceDataDiffLog(string iDeCode, string iDeName, string iCommand, string iMan)
+        {
+            sql.Clear();
+            sql.Append("insert into DeviceRunRecord(drr_id,drr_decode,drr_dename,drr_command,drr_date,drr_doman,drr_remark)");
+            sql.Append("values(DeviceRunRecord_seq.nextval,'" + iDeCode + "','" + iDeName + "','" + iCommand + "',sysdate,'" + iMan + "','')");
+            dh.ExecuteSql(sql.ToString(), "insert");
+        }
     }
 }

+ 1 - 0
PLCDataReader/UAS_PLCDataReader.csproj

@@ -247,6 +247,7 @@
     <Compile Include="Device\Information\DeviceStatusInfo.Designer.cs">
       <DependentUpon>DeviceStatusInfo.cs</DependentUpon>
     </Compile>
+    <Compile Include="Entity\Device.cs" />
     <Compile Include="Entity\Polling.cs" />
     <Compile Include="Entity\SocketObject.cs" />
     <Compile Include="Entity\SystemInf.cs" />