Przeglądaj źródła

接收数据延迟

callm 6 lat temu
rodzic
commit
ecb5acf4ca

+ 15 - 0
UAS-出货标签管理(吉利通)/CustomControl/SerialPortWithTag.cs

@@ -15,6 +15,8 @@ namespace UAS_LabelMachine.CustomControl
 
         private string tag;
 
+        int sleepTime;
+
         public SerialPortWithTag()
         {
             InitializeComponent();
@@ -32,5 +34,18 @@ namespace UAS_LabelMachine.CustomControl
                 tag = value;
             }
         }
+
+        public int SleepTime
+        {
+            get
+            {
+                return sleepTime;
+            }
+
+            set
+            {
+                sleepTime = value;
+            }
+        }
     }
 }

+ 4 - 39
UAS-出货标签管理(吉利通)/PublicMethod/AccessDBHelper.cs

@@ -108,7 +108,6 @@ namespace UAS_LabelMachine
             OleDbDataAdapter ad = new OleDbDataAdapter(command);
             ad.Fill(dt);
             ad.Dispose();
-            
             return dt;
         }
 
@@ -137,7 +136,6 @@ namespace UAS_LabelMachine
                 ad.Fill(dt);
             }
             ad.Dispose();
-            
             if (dt.Rows.Count > 0)
             {
                 return dt.Rows[0][0];
@@ -167,7 +165,6 @@ namespace UAS_LabelMachine
             {
 
             }
-            
         }
 
         public void DeleleFile(string accessFile)
@@ -259,26 +256,6 @@ namespace UAS_LabelMachine
                 tx.Rollback();
                 throw new Exception(E.Message);
             }
-            
-            //string[][] param_array = new string[dt.Columns.Count][];
-            //for (int i = 0; i < dt.Columns.Count; i++)
-            //{
-            //    param_array[i] = new string[dt.Rows.Count];
-            //}
-            ////变量所有的行,如果有主键为空的则移除,不为空的进行参数的拼接
-            //for (int i = dt.Rows.Count - 1; i >= 0; i--)
-            //{
-            //    //当为新添加行的时候才去设置参数,设置过后索引+1
-            //    for (int j = 0; j < dt.Columns.Count; j++)
-            //    {
-            //        param_array[j][i] = dt.Rows[i][j].ToString();
-            //    }
-            //}
-            //for (int i = 0; i < dt.Columns.Count; i++)
-            //{
-            //    command.Parameters.AddWithValue(dt.Columns[i].ColumnName, param_array[i]);
-            //}
-            //command.ExecuteNonQuery();
         }
 
         public void BatchInsert(string tableName, DataTable dt)
@@ -293,16 +270,10 @@ namespace UAS_LabelMachine
             using (OleDbCommandBuilder builder = new OleDbCommandBuilder(adapter))
             {
                 adapter.InsertCommand = builder.GetInsertCommand();
-                for (int i = 0; i < adapter.InsertCommand.Parameters.Count; i++)
-                {
-                    Console.WriteLine(adapter.InsertCommand.Parameters[i].ParameterName);
-                }
                 foreach (string one in columnList)
                 {
-                    Console.WriteLine(one.ToLower());
                     adapter.InsertCommand.Parameters.Add(new OleDbParameter(one.ToLower(), "Test"));
                 }
-                Console.WriteLine(adapter.Update(dt));
             }
         }
 
@@ -319,7 +290,6 @@ namespace UAS_LabelMachine
             OleDbDataAdapter ad = new OleDbDataAdapter(command);
             ad.Fill(dt);
             ad.Dispose();
-            
             return int.Parse(dt.Rows[0][0].ToString());
         }
 
@@ -539,7 +509,6 @@ namespace UAS_LabelMachine
                 ad.Fill(dt);
             }
             ad.Dispose();
-            
             return int.Parse(dt.Rows[0][0].ToString()) > 0;
         }
 
@@ -637,7 +606,7 @@ namespace UAS_LabelMachine
                     }
                     break;
             }
-            
+
             return result;
         }
 
@@ -650,7 +619,7 @@ namespace UAS_LabelMachine
             SQL = SQL.Replace("?", ":Param");
             command = new OleDbCommand(SQL, this._odcConnection);
             command.ExecuteNonQuery();
-            
+
         }
 
         public int GetDistinctRowCount(string TableName, string Field)
@@ -674,7 +643,7 @@ namespace UAS_LabelMachine
                 ad.Fill(dt);
             }
             ad.Dispose();
-            
+
             return int.Parse(dt.Rows[0][0].ToString());
         }
 
@@ -797,7 +766,6 @@ namespace UAS_LabelMachine
                 command.Connection.Open();
                 Rowcount = command.ExecuteNonQuery();
             }
-            
             return Rowcount;
         }
 
@@ -827,7 +795,6 @@ namespace UAS_LabelMachine
             }
             for (int i = 0; i < command.Parameters.Count; i++)
                 param[i] = command.Parameters[i].Value.ToString();
-            
         }
 
         /// <summary>
@@ -866,7 +833,6 @@ namespace UAS_LabelMachine
                 tx.Rollback();
                 throw new Exception(E.Message);
             }
-            
         }
 
         /// <summary>
@@ -936,12 +902,11 @@ namespace UAS_LabelMachine
             if (dt.Rows.Count > 0)
             {
                 ad.Dispose();
-                
+
                 return dt.Rows[0][0];
             }
             else
             {
-                
                 return "";
             }
         }

+ 3 - 3
UAS-出货标签管理(吉利通)/PublicMethod/DataHelper.cs

@@ -1095,7 +1095,7 @@ namespace UAS_LabelMachine
         /// </summary>
         /// <param name="ProcedureName"></param>
         /// <param name="param"></param>
-        public void CallProcedure(string ProcedureName,DataTable upload)
+        public void CallProcedure(string ProcedureName, DataTable upload)
         {
             StringBuilder sql = new StringBuilder();
             sql.Append("declare barcode BarCodeUpload_arr;begin barcode:=BarCodeUpload_arr(");
@@ -1104,12 +1104,12 @@ namespace UAS_LabelMachine
                 sql.Append("BarCodeUpload(");
                 for (int j = 0; j < upload.Columns.Count; j++)
                 {
-                    sql.Append("'"+upload.Rows[i][j].ToString()+"',");
+                    sql.Append("'" + upload.Rows[i][j].ToString() + "',");
                 }
                 sql.Remove(sql.Length - 1, 1);
                 sql.Append("),");
             }
-            sql.Remove(sql.Length-1,1);
+            sql.Remove(sql.Length - 1, 1);
             sql.Append(");sp_uploadbarcode(barcode);END;");
             command = new OracleCommand();
             command.Connection = connection;

Plik diff jest za duży
+ 243 - 196
UAS-出货标签管理(吉利通)/UAS_出货标签管理.Designer.cs


+ 24 - 5
UAS-出货标签管理(吉利通)/UAS_出货标签管理.cs

@@ -174,6 +174,11 @@ namespace UAS_LabelMachine
             if (dr.Length > 0)
             {
                 FrontendCheck.PortName = dr[0]["COM"].ToString();
+                int sleeptime = 0;
+                if (int.TryParse(dr[0]["DATAWAIT"].ToString(), out sleeptime))
+                {
+                    FrontendCheck.SleepTime = sleeptime;
+                }
                 FrontendCheck.Tag = "FrontendCheck";
                 FrontendCheck.BaudRate = int.Parse(dr[0]["BaudRate"].ToString());
                 FrontendCheck.DataReceived += Serial_DataReceived;
@@ -184,6 +189,11 @@ namespace UAS_LabelMachine
             {
                 BackendCheck.PortName = dr[0]["COM"].ToString();
                 BackendCheck.Tag = "BackendCheck";
+                int sleeptime = 0;
+                if (int.TryParse(dr[0]["DATAWAIT"].ToString(), out sleeptime))
+                {
+                    BackendCheck.SleepTime = sleeptime;
+                }
                 BackendCheck.BaudRate = int.Parse(dr[0]["BaudRate"].ToString());
                 BackendCheck.DataReceived += Serial_DataReceived;
                 BackendCheck.Open();
@@ -204,6 +214,7 @@ namespace UAS_LabelMachine
             {
                 string ErrorMsg = "";
                 SerialPortWithTag port = sender as SerialPortWithTag;
+                Thread.Sleep(port.SleepTime);
                 int len = port.BytesToRead;
                 byte[] readBuffer = new byte[len];
                 port.Read(readBuffer, 0, len); //将数据读入缓存
@@ -220,7 +231,7 @@ namespace UAS_LabelMachine
                 switch (port.Tag)
                 {
                     case "PLC1":
-                        MessageLog.AppendText(msg, Color.Blue);
+                        MessageLog.AppendText(msg + "\n", Color.Blue);
                         ////返回的指令和设备执行的动作对应
                         //foreach (var item in instruct)
                         //{
@@ -287,7 +298,7 @@ namespace UAS_LabelMachine
             catch (Exception ex)
             {
                 LogManager.DoLog(ex.StackTrace);
-                MessageBox.Show("接收返回消息异常!具体原因:" + ex.Message, "提示信息");
+                MessageBox.Show("接收返回消息异常!具体原因:" + ex.Message + ex.StackTrace, "提示信息");
             }
         }
 
@@ -620,11 +631,13 @@ namespace UAS_LabelMachine
         {
             ErrorMsg = "";
             DataTable dtt = LabelInf.DataSource as DataTable;
+            MessageLog.AppendText(msg + "\n");
             string[] msgArr = msg.Split(back_sg_separator.Text.ToCharArray());
             //需要校验2项数据,完成校验后此项的值需要为2则表示校验成功
             int checkItemCount = 0;
             List<string> CheckItem = new List<string>();
             string pibid = "";
+            string pibid1 = "";
             for (int i = 0; i < msgArr.Length; i++)
             {
                 if (RecheckCuprodcode.Checked)
@@ -640,7 +653,7 @@ namespace UAS_LabelMachine
                         pibid = adh.getFieldDataByCondition("prodiobarcode", "min(pib_id)", "pib_inoutno='" + pi_inoutno.Text + "' and pd_custprodcode='" + msgArr[i] + "' and pib_ifrecheck=0").ToString();
                         if (pibid != "")
                         {
-
+                            pibid1 = pibid;
                             CheckItem.Remove("客户料号");
                             checkItemCount = checkItemCount + 1;
                         }
@@ -671,6 +684,7 @@ namespace UAS_LabelMachine
                     pibid = adh.getFieldDataByCondition("prodiobarcode", "min(pib_id)", "pib_inoutno='" + pi_inoutno.Text + "' and pib_custbarcode='" + msgArr[i] + "' and pib_ifrecheck=0").ToString();
                     if (pibid != "")
                     {
+                        pibid1 = pibid;
                         CheckItem.Remove("唯一条码");
                         checkItemCount = checkItemCount + 1;
                     }
@@ -693,12 +707,12 @@ namespace UAS_LabelMachine
             }
             else
             {
-                DataRow[] dr = LabelInfDataTable.Select("pib_id=" + pibid);
+                DataRow[] dr = LabelInfDataTable.Select("pib_id=" + pibid1);
                 if (dr.Length > 0)
                 {
                     dr[0]["pib_ifrecheck"] = -1;
                 }
-                adh.ExecuteSql("update prodiobarcode set pib_ifrecheck=-1 where pib_id=" + pibid, "update");
+                adh.ExecuteSql("update prodiobarcode set pib_ifrecheck=-1 where pib_id=" + pibid1, "update");
             }
             LabelInf.Invalidate();
             RefreshProcessData();
@@ -2162,5 +2176,10 @@ namespace UAS_LabelMachine
             PageSize = int.Parse(PageSizeNum.Value.ToString());
             LoadGridData();
         }
+
+        private void button1_Click(object sender, EventArgs e)
+        {
+            adh.ExecuteSql("delete from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "'", "delete");
+        }
     }
 }

Niektóre pliki nie zostały wyświetlone z powodu dużej ilości zmienionych plików