Browse Source

高登PLC取数优化

callm 3 years ago
parent
commit
bebf88d6c1

+ 3 - 3
PLCDataReader/DataOperate/DataHelper.cs

@@ -10,11 +10,11 @@ namespace UAS_PLCDataReader.DataOperate
     class DataHelper
     {
         //内网地址
-        public static readonly string Address = "192.168.0.158";
+        //public static readonly string Address = "192.168.0.158";
         //外网地址
-        //public static readonly string Address = "183.238.39.179";
+        public static readonly string Address = "183.239.180.106";
         //外网地址
-        private readonly string ConnectionStrings = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=GOLDEN;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=" + Address + ")(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
+        private readonly string ConnectionStrings = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=GOLDEN;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=183.239.180.106)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
         //ERP地址
         public static readonly string ERPAddesss = "http://" + Address + ":8099/ERP/";
         //用户选择的数据库的连接字符串

+ 7 - 6
PLCDataReader/Main.cs

@@ -225,7 +225,7 @@ namespace UAS_PLCDataReader
             ButtonDeleteCommandSet.Grid = GridPollingSetting;
 
             //指令设置界面
-            GridCommandSetting.GetDataSQL = "select 0 CHECKEDCOLUMN,dc_id,dc_code,dc_ifng,dc_name,dc_type,case when dc_type='INQTY' then '投入' when dc_type='INGORE' then '忽略' when dc_type='NGQTY' then '不良' when dc_type='OUTQTY' then '产出' when dc_type='TEMPERATURE' then '温度' when dc_type='PARAM1' then '参数1' when dc_type='PARAM2' then '参数2' when dc_type='PARAM3' then '参数3' when dc_type='PARAM4' then '参数4' when dc_type='PARAM5' then '参数5' when dc_type='PARAM6' then '参数6' when dc_type='PARAM7' then '参数7' when dc_type='PARAM8' then '参数8' when dc_type='PARAM9' then '参数9' when dc_type='PARAM10' then '参数10' when dc_type='PARAM3' then '参数3' when dc_type='WAITTIME' then '待料时间' when dc_type='BREAKTIME' then '故障时长' when dc_type='MANSTOPTIME' then '人工停机时长' when dc_type='WORKTIME' then '正常工作时长' when dc_type='STARTTIME' then '开机时长' when dc_type='RUNTIME' then '设备运行时长'   end dc_typename,dc_value,dc_dataindex,dc_sendcoding,dc_receivecoding,db_name,dc_man,dc_date,dc_address from devicecommand left join devicebrand on db_code=dc_debrand ".ToUpper();
+            GridCommandSetting.GetDataSQL = "select 0 CHECKEDCOLUMN,dc_id,dc_code,dc_ifng,dc_name,dc_type,case when dc_type='INQTY' then '投入' when dc_type='INGORE' then '忽略' when dc_type='NGQTY' then '不良' when dc_type='OUTQTY' then '产出' when dc_type='TEMPERATURE' then '温度' when dc_type='PARAM1' then '参数1' when dc_type='PARAM2' then '参数2' when dc_type='PARAM3' then '参数3' when dc_type='PARAM4' then '参数4' when dc_type='PARAM5' then '参数5' when dc_type='PARAM6' then '参数6' when dc_type='PARAM7' then '参数7' when dc_type='PARAM8' then '参数8' when dc_type='PARAM9' then '参数9' when dc_type='PARAM10' then '参数10' when dc_type='PARAM3' then '参数3' when dc_type='WAITTIME' then '待料时间' when dc_type='BREAKTIME' then '故障时长' when dc_type='MANSTOPTIME' then '人工停机时长' when dc_type='WORKTIME' then '正常工作时长' when dc_type='STARTTIME' then '开机时长' when dc_type='RUNTIME' then '设备运行时长' when dc_type='BADDETAIL' then '不良明细'  end dc_typename,dc_value,dc_dataindex,dc_sendcoding,dc_receivecoding,db_name,dc_man,dc_date,dc_address from devicecommand left join devicebrand on db_code=dc_debrand ".ToUpper();
             GridCommandSetting.TableName = "devicecommand";
             GridCommandSetting.ID = "dc_id";
             GridCommandSetting.InsertSQL = "insert into devicecommand(dc_id,dc_code,dc_name,dc_value,dc_debrand,dc_sendcoding,dc_receivecoding,dc_man,dc_date,dc_dataindex,dc_type,dc_address) values(devicecommand_seq.nextval,:dc_code,:dc_name,:dc_value,'" + BaseUtil.GetComboxEditValue(Brand) + "',:dc_sendcoding,:dc_receivecoding,'" + User.UserName + "',sysdate,:dc_dataindex,:dc_type,:)";
@@ -507,7 +507,7 @@ namespace UAS_PLCDataReader
                     NextDecode = GridViewPollSetting.GetRowCellValue(i + 1, "DPC_DECODE").ToString();
                 }
                 //设备编号不相同的时候
-                if (LastDecode != NextDecode || i == GridPollingSetting.RowCount - 1)
+                if (!StartDecode.Contains(LastDecode))
                 {
                     Polling pl = new Polling();
                     //加入最后一行指令
@@ -536,8 +536,9 @@ namespace UAS_PLCDataReader
                     }
                     else LogicHandler.UpdateDeviceStatus(pl.DeviceCode, pl.DeviceName, "设备未启用", DeviceStatus.Stopped, 0);
                 }
-                else
+                else 
                 {
+                    if (GridViewPollSetting.GetRowCellValue(i, "DPC_ENABLE").ToString() != "0")
                     CommandCode.Add(GridViewPollSetting.GetRowCellValue(i, "DPC_DCCODE").ToString());
                 }
             }
@@ -627,6 +628,7 @@ namespace UAS_PLCDataReader
                         int SendCommandByteSize = 0;
                         if (dc_dr.Length > 0)
                         {
+                            
                             Command = dc_dr[0]["dc_value"].ToString();
                             SendCommandByteSize = Encoding.Default.GetBytes(Command.ToCharArray()).Length;
                         }
@@ -644,7 +646,6 @@ namespace UAS_PLCDataReader
                             }
                             catch (Exception ex)
                             {
-                                Console.WriteLine(ex.Message + ex.StackTrace);
                                 LogicHandler.UpdateDeviceStatus(pl.DeviceCode, pl.DeviceName, ex.Message, DeviceStatus.Disconnect, -1);
                             }
                         }
@@ -678,12 +679,12 @@ namespace UAS_PLCDataReader
                             int[] Arr = BaseUtil.GetDecimalData(BaseUtil.ASCIIToString(client[IP].Returnvalue[IP]), 8);
                             Console.WriteLine(IP + " " + Arr.Length + " " + dc_dr.Length);
                             //如果返回的是不良代码的集合,则表示连续的不良
-                            if (dc_dr[0]["dc_type"].ToString() == "BADDETAIL")
+                            if (dc_dr.Length>0&&dc_dr[0]["dc_type"].ToString() == "BADDETAIL")
                             {
                                 //命令行只需要设置一条指令,通过参数长度来设置Key
                                 for (int j = 0; j < Arr.Length; j++)
                                 {
-                                    ItemData.Add(dc_dr[j]["dc_type"].ToString() + j, Arr[j].ToString());
+                                    ItemData.Add(dc_dr[0]["dc_type"].ToString() + j, Arr[j].ToString());
                                 }
                             }
                             else

+ 1 - 0
PLCDataReader/PublicMethod/BaseUtil.cs

@@ -425,6 +425,7 @@ namespace UAS_PLCDataReader.PublicMethod
                             //低位在前,高位在后返回2710 0000,转换0000 2710
                             string Low = RealData.Substring(i, DataSize).Substring(4, 4);
                             string High = RealData.Substring(i, DataSize).Substring(0, 4);
+                            //Console.WriteLine(Convert.ToInt32("0x" + Low + High, 16));
                             ReturnData.Add(Convert.ToInt32("0x" + Low + High, 16));
                         }
                     }

+ 17 - 4
PLCDataReader/PublicMethod/LogicHandler.cs

@@ -176,10 +176,13 @@ namespace UAS_PLCDataReader.PublicMethod
                 return;
             StringBuilder sql = new StringBuilder();
             StringBuilder sql1 = new StringBuilder();
+            StringBuilder sql2 = new StringBuilder();
             //更新设备运行状态
             sql.Append("update DeviceRunstatus set ");
             //更新设备工作时间
-            sql1.Append("merge into deviceworktime a using  (select '" + Decode + "' decode,sysdate time from  dual)  b on(trunc(a.dwt_indate)=trunc(b.time) and a.dwt_decode = b.decode) when matched then update set ");
+            sql1.Append("merge into deviceworktime a using  (select '' decode,sysdate time from  dual)  b on(trunc(a.dwt_indate)=trunc(b.time) and a.dwt_decode = b.decode) when matched then update set ");
+            //不良代码索引
+            int BadIndex = 0;
             foreach (var item in ItemData)
             {
                 switch (item.Key)
@@ -309,15 +312,25 @@ namespace UAS_PLCDataReader.PublicMethod
                 }
                 if (item.Key.Contains("BADDETAIL"))
                 {
-                    DataTable dt = (DataTable)dh.ExecuteSql("select bgd_badcode from badgroup left join BADGROUPDETAIL on bg_id=bgd_bgid order by bgd_detno", "select");
-
+                    DataTable dt = (DataTable)dh.ExecuteSql("select bgd_badcode from badgroup left join BADGROUPDETAIL on bg_id=bgd_bgid where bg_code='"+ Decode + "' order by bgd_detno", "select");
+                    if(BadIndex<dt.Rows.Count)
+                    {
+                        string badcode = dt.Rows[BadIndex]["bgd_badcode"].ToString();
+                        sql2.Clear();
+                        sql2.Append("merge into makebad a using  (select '"+ Decode + "' decode,sysdate time from  dual)b ");
+                        sql2.Append("on(trunc(a.mb_indate)=trunc(b.time) and a.mb_badcode = '"+ badcode + "' and a.mb_decode='"+Decode+"') when matched then update set ");
+                        sql2.Append("mb_value='"+item.Value+ "',mb_updatetime=sysdate when not matched then insert (mb_id,mb_decode,mb_badcode,mb_value,mb_updatetime)values(deviceworktime_seq.nextval,'" + Decode+"', '"+ badcode + "', '" + item.Value+"',sysdate)");
+                        Console.WriteLine(Decode);
+                        Main.QueueUpdateDevice.Enqueue(sql2.ToString());
+                    }
+                    BadIndex = BadIndex + 1;
                 }
             }
             //更新设别运行状态
             sql.Append("dr_updatedate=sysdate where dr_decode='" + Decode + "'");
             Main.QueueUpdateDevice.Enqueue(sql.ToString());
             //更新设备工作时长
-            sql1.Append("dwt_indate=sysdate  when not matched then insert (dwt_id,dwt_decode,dwt_indate) values(deviceworktime_seq.nextval,'" + Decode + "',sysdate)");
+            sql1.Append("dwt_updatetime=sysdate  when not matched then insert (dwt_id,dwt_decode,dwt_indate) values(deviceworktime_seq.nextval,'" + Decode + "',sysdate)");
             Main.QueueUpdateDevice.Enqueue(sql1.ToString());
         }