Browse Source

Merge branch 'master' of ssh://10.10.100.21/source/mes-client

Hcsy 7 years ago
parent
commit
0e982c3970

+ 18 - 18
PLCDataReader/Main.Designer.cs

@@ -848,7 +848,7 @@ namespace UAS_PLCDataReader
             this.CommandSetCheckedColumn.Tag = "0";
             this.CommandSetCheckedColumn.Visible = true;
             this.CommandSetCheckedColumn.VisibleIndex = 0;
-            this.CommandSetCheckedColumn.Width = 46;
+            this.CommandSetCheckedColumn.Width = 39;
             // 
             // CheckEditCommandSet
             // 
@@ -868,7 +868,7 @@ namespace UAS_PLCDataReader
             this.dc_code.Name = "dc_code";
             this.dc_code.Visible = true;
             this.dc_code.VisibleIndex = 1;
-            this.dc_code.Width = 64;
+            this.dc_code.Width = 55;
             // 
             // dc_name
             // 
@@ -877,15 +877,14 @@ namespace UAS_PLCDataReader
             this.dc_name.Name = "dc_name";
             this.dc_name.Visible = true;
             this.dc_name.VisibleIndex = 2;
-            this.dc_name.Width = 71;
+            this.dc_name.Width = 61;
             // 
             // dc_type
             // 
             this.dc_type.Caption = "指令值";
             this.dc_type.FieldName = "DC_TYPE";
             this.dc_type.Name = "dc_type";
-            this.dc_type.Visible = true;
-            this.dc_type.VisibleIndex = 3;
+            this.dc_type.Width = 65;
             // 
             // dc_typename
             // 
@@ -893,7 +892,9 @@ namespace UAS_PLCDataReader
             this.dc_typename.ColumnEdit = this.DataItemRepositoryItemComboBox1;
             this.dc_typename.FieldName = "DC_TYPENAME";
             this.dc_typename.Name = "dc_typename";
-            this.dc_typename.Width = 57;
+            this.dc_typename.Visible = true;
+            this.dc_typename.VisibleIndex = 3;
+            this.dc_typename.Width = 76;
             // 
             // dc_dataindex
             // 
@@ -902,6 +903,7 @@ namespace UAS_PLCDataReader
             this.dc_dataindex.Name = "dc_dataindex";
             this.dc_dataindex.Visible = true;
             this.dc_dataindex.VisibleIndex = 4;
+            this.dc_dataindex.Width = 62;
             // 
             // dc_value
             // 
@@ -910,7 +912,7 @@ namespace UAS_PLCDataReader
             this.dc_value.Name = "dc_value";
             this.dc_value.Visible = true;
             this.dc_value.VisibleIndex = 5;
-            this.dc_value.Width = 154;
+            this.dc_value.Width = 128;
             // 
             // dc_sendcoding
             // 
@@ -920,7 +922,7 @@ namespace UAS_PLCDataReader
             this.dc_sendcoding.Name = "dc_sendcoding";
             this.dc_sendcoding.Visible = true;
             this.dc_sendcoding.VisibleIndex = 6;
-            this.dc_sendcoding.Width = 138;
+            this.dc_sendcoding.Width = 114;
             // 
             // CommandSetRepositoryItemComboBox1
             // 
@@ -937,7 +939,7 @@ namespace UAS_PLCDataReader
             this.dc_receivecoding.Name = "dc_receivecoding";
             this.dc_receivecoding.Visible = true;
             this.dc_receivecoding.VisibleIndex = 7;
-            this.dc_receivecoding.Width = 139;
+            this.dc_receivecoding.Width = 115;
             // 
             // dc_man
             // 
@@ -947,7 +949,7 @@ namespace UAS_PLCDataReader
             this.dc_man.OptionsColumn.AllowEdit = false;
             this.dc_man.Visible = true;
             this.dc_man.VisibleIndex = 9;
-            this.dc_man.Width = 151;
+            this.dc_man.Width = 126;
             // 
             // dc_date
             // 
@@ -959,7 +961,7 @@ namespace UAS_PLCDataReader
             this.dc_date.OptionsColumn.AllowEdit = false;
             this.dc_date.Visible = true;
             this.dc_date.VisibleIndex = 10;
-            this.dc_date.Width = 118;
+            this.dc_date.Width = 107;
             // 
             // repositoryItemDateEdit1
             // 
@@ -977,7 +979,7 @@ namespace UAS_PLCDataReader
             this.db_name.Name = "db_name";
             this.db_name.Visible = true;
             this.db_name.VisibleIndex = 8;
-            this.db_name.Width = 57;
+            this.db_name.Width = 47;
             // 
             // PageDeviceNetSetting
             // 
@@ -1348,8 +1350,6 @@ namespace UAS_PLCDataReader
             this.dpc_function.Caption = "解析函数";
             this.dpc_function.FieldName = "DPC_FUNCTION";
             this.dpc_function.Name = "dpc_function";
-            this.dpc_function.Visible = true;
-            this.dpc_function.VisibleIndex = 5;
             this.dpc_function.Width = 90;
             // 
             // dpc_enable
@@ -1359,7 +1359,7 @@ namespace UAS_PLCDataReader
             this.dpc_enable.FieldName = "DPC_ENABLE";
             this.dpc_enable.Name = "dpc_enable";
             this.dpc_enable.Visible = true;
-            this.dpc_enable.VisibleIndex = 6;
+            this.dpc_enable.VisibleIndex = 5;
             this.dpc_enable.Width = 90;
             // 
             // em_name1
@@ -1369,7 +1369,7 @@ namespace UAS_PLCDataReader
             this.em_name1.Name = "em_name1";
             this.em_name1.OptionsColumn.AllowEdit = false;
             this.em_name1.Visible = true;
-            this.em_name1.VisibleIndex = 9;
+            this.em_name1.VisibleIndex = 8;
             // 
             // dpc_status
             // 
@@ -1392,7 +1392,7 @@ namespace UAS_PLCDataReader
             this.dpc_remark.FieldName = "DPC_REMARK";
             this.dpc_remark.Name = "dpc_remark";
             this.dpc_remark.Visible = true;
-            this.dpc_remark.VisibleIndex = 7;
+            this.dpc_remark.VisibleIndex = 6;
             this.dpc_remark.Width = 87;
             // 
             // POLLSETTINGSTATUSCOLUMN
@@ -1402,7 +1402,7 @@ namespace UAS_PLCDataReader
             this.POLLSETTINGSTATUSCOLUMN.Name = "POLLSETTINGSTATUSCOLUMN";
             this.POLLSETTINGSTATUSCOLUMN.OptionsColumn.ReadOnly = true;
             this.POLLSETTINGSTATUSCOLUMN.Visible = true;
-            this.POLLSETTINGSTATUSCOLUMN.VisibleIndex = 8;
+            this.POLLSETTINGSTATUSCOLUMN.VisibleIndex = 7;
             this.POLLSETTINGSTATUSCOLUMN.Width = 98;
             // 
             // PollingSetItemLookUpEdit

+ 8 - 6
PLCDataReader/Main.cs

@@ -404,13 +404,13 @@ namespace UAS_PLCDataReader
                     sql.Append("insert into DEVICEPOLLINGLOG(dpg_id,dpg_decode,dpg_starttime,dpg_interval)values");
                     sql.Append("(DEVICEPOLLINGLOG_seq.nextval,'" + pl.DeviceCode + "',sysdate,'" + pl.Interval + "')");
                     dh.ExecuteSql(sql.ToString(), "insert");
-                    LogicHandler.UpdateDeviceStatus(pl.DeviceCode, pl.DeviceName, "running");
+                    LogicHandler.UpdateDeviceStatus(pl.Dh, pl.DeviceCode, pl.DeviceName, "running");
                     pt.AddTask(RunTask, pl);
                     //添加到状态为运行的行
                     PollSettingPaintRowIndex.Add(i);
                     GridPollingSetting.Focus();
                 }
-                else LogicHandler.UpdateDeviceStatus(pl.DeviceCode, pl.DeviceName, "stopped");
+                else LogicHandler.UpdateDeviceStatus(pl.Dh, pl.DeviceCode, pl.DeviceName, "stopped");
             }
         }
 
@@ -486,6 +486,7 @@ namespace UAS_PLCDataReader
                 else
                 {
                     ModBusTCPClient modclient = new ModBusTCPClient(DNC.Rows[0]["dnc_ip"].ToString(), DNC.Rows[0]["dnc_port"].ToString(), pl.DeviceCode, pl.DeviceName);
+                    modclient.Dh = dh;
                     client.Add(DpcID, modclient);
                 }
                 //如果不包含该项数据则在键值对中添加
@@ -538,10 +539,11 @@ namespace UAS_PLCDataReader
                     }
                     else
                     {
-                        if (ReturnData[Decode].ItemData == null)
+                        //在未获取过数据的时候并且获取到的数据不为空的时候进行设备数据的更新
+                        if (ReturnData[Decode].ItemData == null || (ReturnData[Decode].ItemData.Count == 0 && ItemData.Count != 0))
                         {
                             ReturnData[Decode].ItemData = ItemData;
-                            LogicHandler.UpdateDeviceData(Decode, ItemData);
+                            LogicHandler.UpdateDeviceData(dh, Decode, ItemData);
                         }
                         //每次更新轮询的数据
                         ReturnData[Decode].ReceiveDataSize += ReceiveCommandByteSize;
@@ -549,9 +551,9 @@ namespace UAS_PLCDataReader
                         if (BaseUtil.CheckDicDiff(ReturnData[Decode].ItemData, ItemData))
                         {
                             ReturnData[Decode].ItemData = ItemData;
-                            LogicHandler.UpdateDeviceData(Decode, ItemData);
+                            LogicHandler.UpdateDeviceData(dh, Decode, ItemData);
                             QueueUpdateDevice.Enqueue(ReturnData[Decode]);
-                            LogicHandler.DoDeviceDataDiffLog(pl.DeviceCode, pl.DeviceName, pl.CommandCode, User.UserName);
+                            LogicHandler.DoDeviceDataDiffLog(dh, pl.DeviceCode, pl.DeviceName, pl.CommandCode, User.UserName);
                         }
                     }
                     client[DpcID].Returnvalue.Remove(IP);

+ 21 - 10
PLCDataReader/PublicMethod/BaseUtil.cs

@@ -357,20 +357,31 @@ namespace UAS_PLCDataReader.PublicMethod
 
         public static int[] GetDecimalData(string HexStr, int DataSize)
         {
-            //去除前面的指令字符和数据长度字符
-            HexStr = HexStr.Replace(":", "");
-            string RealData = HexStr.Substring(6);
             List<int> ReturnData = new List<int>();
-            //每个地址位存的数据是DataSize个
-            for (int i = 0; i < RealData.Length; i = i + DataSize)
+            try
             {
-                if (i + DataSize < RealData.Length)
+                //去除前面的指令字符和数据长度字符
+                HexStr = HexStr.Replace(":", "");
+                if (HexStr != "")
                 {
-                    if (Convert.ToInt32("0x" + (RealData.Substring(i, DataSize).Substring(0, 4)), 16) / 1 != 0)
-                        ReturnData.Add(Convert.ToInt32("0x" + (RealData.Substring(i, DataSize).Substring(0, 4)), 16));
-                    else
-                        break;
+                    string RealData = HexStr.Substring(6);
+
+                    //每个地址位存的数据是DataSize个
+                    for (int i = 0; i < RealData.Length; i = i + DataSize)
+                    {
+                        if (i + DataSize < RealData.Length)
+                        {
+                            if (Convert.ToInt32("0x" + (RealData.Substring(i, DataSize).Substring(0, 4)), 16) / 1 != 0)
+                                ReturnData.Add(Convert.ToInt32("0x" + (RealData.Substring(i, DataSize).Substring(0, 4)), 16));
+                            else
+                                break;
+                        }
+                    }
                 }
+            }
+            catch (Exception)
+            {
+
             }
             return ReturnData.ToArray();
         }

+ 11 - 4
PLCDataReader/PublicMethod/LogicHandler.cs

@@ -41,7 +41,7 @@ namespace UAS_PLCDataReader.PublicMethod
         /// <summary>
         /// 进行差异日志记录
         /// </summary>
-        public static void DoDeviceDataDiffLog(string iDeCode, string iDeName, string iCommand, string iMan)
+        public static void DoDeviceDataDiffLog(DataHelper dh, 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)");
@@ -54,7 +54,7 @@ namespace UAS_PLCDataReader.PublicMethod
         /// </summary>
         /// <param name="Decode"></param>
         /// <param name="ItemData"></param>
-        public static void UpdateDeviceData(string Decode, Dictionary<string, string> ItemData)
+        public static void UpdateDeviceData(DataHelper dh, string Decode, Dictionary<string, string> ItemData)
         {
             string INQTY = "";
             string OUTQTY = "";
@@ -78,10 +78,17 @@ namespace UAS_PLCDataReader.PublicMethod
             }
             sql.Clear();
             sql.Append("update DeviceRunstatus set dr_qty=:dr_inqty,dr_okqty=:dr_okqty,dr_TEMPERATURE=:dr_TEMPERATURE where dr_decode='" + Decode + "'");
-            dh.ExecuteSql(sql.ToString(), "select", INQTY, OUTQTY, TEMPERATURE);
+            dh.ExecuteSql(sql.ToString(), "update", INQTY, OUTQTY, TEMPERATURE);
         }
 
-        public static void UpdateDeviceStatus(string iDecode, string iDename, string iDestatus)
+        /// <summary>
+        /// 更新设备运行状态
+        /// </summary>
+        /// <param name="dh"></param>
+        /// <param name="iDecode"></param>
+        /// <param name="iDename"></param>
+        /// <param name="iDestatus"></param>
+        public static void UpdateDeviceStatus(DataHelper dh, string iDecode, string iDename, string iDestatus)
         {
             sql.Clear();
             sql.Append("MERGE INTO DeviceRunstatus alias1 USING (select '" + iDecode + "' dr_decode from  dual) alias2 ");

+ 20 - 4
PLCDataReader/PublicMethod/ModBusTCPClient.cs

@@ -4,6 +4,7 @@ using System.Linq;
 using System.Net;
 using System.Net.Sockets;
 using System.Text;
+using UAS_PLCDataReader.DataOperate;
 
 namespace UAS_PLCDataReader.PublicMethod
 {
@@ -17,6 +18,8 @@ namespace UAS_PLCDataReader.PublicMethod
 
         private bool receiveData;
 
+        private DataOperate.DataHelper dh;
+
         private Dictionary<string, string> returnvalue = new Dictionary<string, string>();
 
         public bool IsOpen
@@ -84,6 +87,19 @@ namespace UAS_PLCDataReader.PublicMethod
             }
         }
 
+        internal DataHelper Dh
+        {
+            get
+            {
+                return dh;
+            }
+
+            set
+            {
+                dh = value;
+            }
+        }
+
         private string iP;
 
         private string port;
@@ -104,7 +120,7 @@ namespace UAS_PLCDataReader.PublicMethod
             catch (Exception e)
             {
                 Console.WriteLine(e.Message);
-                LogicHandler.UpdateDeviceStatus(decode, dename, "disconnect");
+                LogicHandler.UpdateDeviceStatus(Dh,decode, dename, "disconnect");
             }
         }
 
@@ -127,9 +143,9 @@ namespace UAS_PLCDataReader.PublicMethod
                 socket.Send(arr);
 
                 byte[] receive = new byte[1024 * 1024];
-                LogicHandler.UpdateDeviceStatus(decode, dename, "noanswer");
+                LogicHandler.UpdateDeviceStatus(Dh,decode, dename, "noanswer");
                 int length = socket.Receive(receive);
-                LogicHandler.UpdateDeviceStatus(decode, dename, "running");
+                LogicHandler.UpdateDeviceStatus(Dh,decode, dename, "running");
                 if (!returnvalue.ContainsKey(socket.RemoteEndPoint.ToString()))
                 {
                     returnvalue.Add(socket.RemoteEndPoint.ToString(), BaseUtil.ByteToHexadecimalString(receive, length));
@@ -138,7 +154,7 @@ namespace UAS_PLCDataReader.PublicMethod
             }
             catch (Exception)
             {
-                LogicHandler.UpdateDeviceStatus(decode, dename, "disconnect");
+                LogicHandler.UpdateDeviceStatus(Dh,decode, dename, "disconnect");
             }
         }
     }