Browse Source

添加ASCII 数据解析方式

章政 6 years ago
parent
commit
8ae6228bb6

+ 68 - 1
PLCDataReader/ClassFile/BaseUtil.cs

@@ -29,9 +29,76 @@
                 LRCre += string.Format("{0:X}", index);
             }
 
-            LRCre = string.Format("{0:X}", int.Parse(LRCre, System.Globalization.NumberStyles.HexNumber)+1);
+            LRCre = string.Format("{0:X}", int.Parse(LRCre, System.Globalization.NumberStyles.HexNumber) + 1);
 
             return LRCre;
         }
+
+        public static string ASCIIToString(string ASCII)
+        {
+            string ReturnStr = "";
+            ASCII = ASCII.Replace(" ", "").Replace("3A", "").Replace("0D", "").Replace("0A", "");
+            System.Console.WriteLine(ASCII);
+            for (int i = 0; i < ASCII.Length; i = i + 2)
+            {
+                if (i + 2 < ASCII.Length)
+                {
+                    switch (ASCII.Substring(i, 2))
+                    {
+                        case "30":
+                            ReturnStr += "0";
+                            break;
+                        case "31":
+                            ReturnStr += "1";
+                            break;
+                        case "32":
+                            ReturnStr += "2";
+                            break;
+                        case "33":
+                            ReturnStr += "3";
+                            break;
+                        case "34":
+                            ReturnStr += "4";
+                            break;
+                        case "35":
+                            ReturnStr += "5";
+                            break;
+                        case "36":
+                            ReturnStr += "6";
+                            break;
+                        case "37":
+                            ReturnStr += "7";
+                            break;
+                        case "38":
+                            ReturnStr += "8";
+                            break;
+                        case "39":
+                            ReturnStr += "9";
+                            break;
+                        case "41":
+                            ReturnStr += "A";
+                            break;
+                        case "42":
+                            ReturnStr += "B";
+                            break;
+                        case "43":
+                            ReturnStr += "C";
+                            break;
+                        case "44":
+                            ReturnStr += "D";
+                            break;
+                        case "45":
+                            ReturnStr += "E";
+                            break;
+                        case "46":
+                            ReturnStr += "F";
+                            break;
+                        default:
+                            break;
+                    }
+                }
+            }
+            return ReturnStr;
+        }
     }
 }

+ 1 - 1
PLCDataReader/ClassFile/ModeBusTCPServer.cs

@@ -183,7 +183,7 @@ namespace ClassFile
                 {
                     connection = socketWatch.Accept();
                 }
-                catch (Exception)
+                catch (SocketException e)
                 {
                     break;
                 }

+ 13 - 12
PLCDataReader/MainWindow.Designer.cs

@@ -38,7 +38,7 @@
             this.SEND = new System.Windows.Forms.Button();
             this.IPTEXT = new System.Windows.Forms.Label();
             this.label1 = new System.Windows.Forms.Label();
-            this.Encoding = new System.Windows.Forms.ComboBox();
+            this.Encoding1 = new System.Windows.Forms.ComboBox();
             this.SENDMESSAGE = new UAS_PLCDataReader.RichTextAutoBottom();
             this.Result = new UAS_PLCDataReader.RichTextAutoBottom();
             this.SuspendLayout();
@@ -115,6 +115,7 @@
             this.SEND.TabIndex = 9;
             this.SEND.Text = "SEND";
             this.SEND.UseVisualStyleBackColor = true;
+            this.SEND.Click += new System.EventHandler(this.SEND_Click);
             // 
             // IPTEXT
             // 
@@ -134,18 +135,18 @@
             this.label1.TabIndex = 11;
             this.label1.Text = "编码格式";
             // 
-            // Encoding
+            // Encoding1
             // 
-            this.Encoding.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
-            this.Encoding.FormattingEnabled = true;
-            this.Encoding.Items.AddRange(new object[] {
+            this.Encoding1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
+            this.Encoding1.FormattingEnabled = true;
+            this.Encoding1.Items.AddRange(new object[] {
             "UTF-8",
             "ASCII",
             "Hexadecimal"});
-            this.Encoding.Location = new System.Drawing.Point(533, 89);
-            this.Encoding.Name = "Encoding";
-            this.Encoding.Size = new System.Drawing.Size(157, 20);
-            this.Encoding.TabIndex = 12;
+            this.Encoding1.Location = new System.Drawing.Point(533, 89);
+            this.Encoding1.Name = "Encoding1";
+            this.Encoding1.Size = new System.Drawing.Size(157, 20);
+            this.Encoding1.TabIndex = 12;
             // 
             // SENDMESSAGE
             // 
@@ -168,7 +169,7 @@
             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
             this.ClientSize = new System.Drawing.Size(702, 358);
-            this.Controls.Add(this.Encoding);
+            this.Controls.Add(this.Encoding1);
             this.Controls.Add(this.label1);
             this.Controls.Add(this.IPTEXT);
             this.Controls.Add(this.SEND);
@@ -186,7 +187,7 @@
             this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
             this.Text = "PLCDataReader";
             this.Load += new System.EventHandler(this.Form1_Load);
-            this.ResumeLayout(true);
+            this.ResumeLayout(false);
             this.PerformLayout();
 
         }
@@ -205,7 +206,7 @@
         private System.Windows.Forms.Button SEND;
         private System.Windows.Forms.Label IPTEXT;
         private System.Windows.Forms.Label label1;
-        private System.Windows.Forms.ComboBox Encoding;
+        private System.Windows.Forms.ComboBox Encoding1;
     }
 }
 

+ 41 - 1
PLCDataReader/MainWindow.cs

@@ -3,6 +3,7 @@ using System.Windows.Forms;
 using System.Net;
 using System.Net.Sockets;
 using ClassFile;
+using System.Text;
 
 namespace UAS_PLCDataReader
 {
@@ -25,7 +26,7 @@ namespace UAS_PLCDataReader
                 if (IpEntry.AddressList[i].AddressFamily == AddressFamily.InterNetwork)
                     IP.Text = IpEntry.AddressList[i].ToString();
             }
-            Encoding.Text = Encoding.Items[0].ToString();
+            Encoding1.Text = Encoding1.Items[0].ToString();
         }
 
         private void OpenServer_Click(object sender, EventArgs e)
@@ -49,5 +50,44 @@ namespace UAS_PLCDataReader
                 Port.Enabled = true;
             }
         }
+
+        private void SEND_Click(object sender, EventArgs e)
+        {
+            Console.WriteLine(BaseUtil.ASCIIToString(SENDMESSAGE.Text));
+        }
+
+        public static string HexStringToASCII(string hexstring)
+        {
+            byte[] bt = HexStringToBinary(hexstring);
+            string lin = "";
+            for (int i = 0; i < bt.Length; i++)
+            {
+                lin = lin + bt[i] + " ";
+            }
+
+            string[] ss = lin.Trim().Split(new char[] { ' ' });
+            char[] c = new char[ss.Length];
+            int a;
+            for (int i = 0; i < c.Length; i++)
+            {
+                a = Convert.ToInt32(ss[i]);
+                c[i] = Convert.ToChar(a);
+            }
+
+            string b = new string(c);
+            return b;
+        }
+
+        public static byte[] HexStringToBinary(string hexstring)
+        {
+
+            string[] tmpary = hexstring.Trim().Split(' ');
+            byte[] buff = new byte[tmpary.Length];
+            for (int i = 0; i < buff.Length; i++)
+            {
+                buff[i] = Convert.ToByte(tmpary[i], 16);
+            }
+            return buff;
+        }
     }
 }

+ 24 - 23
UAS-出货标签管理(泽天)/UAS_出货标签管理.Designer.cs

@@ -850,7 +850,7 @@
             // 
             this.label18.AutoSize = true;
             this.label18.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.label18.Location = new System.Drawing.Point(59, 134);
+            this.label18.Location = new System.Drawing.Point(63, 138);
             this.label18.Name = "label18";
             this.label18.Size = new System.Drawing.Size(13, 17);
             this.label18.TabIndex = 90;
@@ -884,7 +884,7 @@
             // 
             this.label16.AutoSize = true;
             this.label16.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.label16.Location = new System.Drawing.Point(58, 71);
+            this.label16.Location = new System.Drawing.Point(62, 75);
             this.label16.Name = "label16";
             this.label16.Size = new System.Drawing.Size(13, 17);
             this.label16.TabIndex = 87;
@@ -918,7 +918,7 @@
             // 
             this.label12.AutoSize = true;
             this.label12.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.label12.Location = new System.Drawing.Point(2, 106);
+            this.label12.Location = new System.Drawing.Point(8, 103);
             this.label12.Name = "label12";
             this.label12.Size = new System.Drawing.Size(56, 17);
             this.label12.TabIndex = 77;
@@ -928,7 +928,7 @@
             // 
             this.label7.AutoSize = true;
             this.label7.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.label7.Location = new System.Drawing.Point(2, 28);
+            this.label7.Location = new System.Drawing.Point(8, 25);
             this.label7.Name = "label7";
             this.label7.Size = new System.Drawing.Size(56, 17);
             this.label7.TabIndex = 76;
@@ -1080,6 +1080,7 @@
             this.DateCode1.DataPropertyName = "DateCode1";
             this.DateCode1.HeaderText = "DateCode1";
             this.DateCode1.Name = "DateCode1";
+            this.DateCode1.Visible = false;
             this.DateCode1.Width = 84;
             // 
             // pib_qty
@@ -1191,7 +1192,7 @@
             // 
             this.SingleLabelPrint.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
             this.SingleLabelPrint.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.SingleLabelPrint.Location = new System.Drawing.Point(56, 177);
+            this.SingleLabelPrint.Location = new System.Drawing.Point(84, 172);
             this.SingleLabelPrint.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
             this.SingleLabelPrint.Name = "SingleLabelPrint";
             this.SingleLabelPrint.Size = new System.Drawing.Size(68, 26);
@@ -1206,7 +1207,7 @@
             this.SingleLabelAutoPrint.Checked = true;
             this.SingleLabelAutoPrint.CheckState = System.Windows.Forms.CheckState.Checked;
             this.SingleLabelAutoPrint.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.SingleLabelAutoPrint.Location = new System.Drawing.Point(5, 93);
+            this.SingleLabelAutoPrint.Location = new System.Drawing.Point(7, 91);
             this.SingleLabelAutoPrint.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
             this.SingleLabelAutoPrint.Name = "SingleLabelAutoPrint";
             this.SingleLabelAutoPrint.Size = new System.Drawing.Size(75, 21);
@@ -1264,7 +1265,7 @@
             // 
             this.label2.AutoSize = true;
             this.label2.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.label2.Location = new System.Drawing.Point(4, 119);
+            this.label2.Location = new System.Drawing.Point(10, 118);
             this.label2.Name = "label2";
             this.label2.Size = new System.Drawing.Size(32, 17);
             this.label2.TabIndex = 92;
@@ -1287,7 +1288,7 @@
             // 
             this.label5.AutoSize = true;
             this.label5.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.label5.Location = new System.Drawing.Point(3, 153);
+            this.label5.Location = new System.Drawing.Point(9, 153);
             this.label5.Name = "label5";
             this.label5.Size = new System.Drawing.Size(32, 17);
             this.label5.TabIndex = 50;
@@ -1320,7 +1321,7 @@
             this.MidLabelAutoPrint.Checked = true;
             this.MidLabelAutoPrint.CheckState = System.Windows.Forms.CheckState.Checked;
             this.MidLabelAutoPrint.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.MidLabelAutoPrint.Location = new System.Drawing.Point(5, 91);
+            this.MidLabelAutoPrint.Location = new System.Drawing.Point(5, 90);
             this.MidLabelAutoPrint.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
             this.MidLabelAutoPrint.Name = "MidLabelAutoPrint";
             this.MidLabelAutoPrint.Size = new System.Drawing.Size(75, 21);
@@ -1363,7 +1364,7 @@
             // LogingOut
             // 
             this.LogingOut.AutoSize = true;
-            this.LogingOut.Location = new System.Drawing.Point(103, 4);
+            this.LogingOut.Location = new System.Drawing.Point(100, 1);
             this.LogingOut.Name = "LogingOut";
             this.LogingOut.Size = new System.Drawing.Size(42, 21);
             this.LogingOut.TabIndex = 77;
@@ -1389,7 +1390,7 @@
             // 
             this.label10.AutoSize = true;
             this.label10.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.label10.Location = new System.Drawing.Point(3, 147);
+            this.label10.Location = new System.Drawing.Point(9, 147);
             this.label10.Name = "label10";
             this.label10.Size = new System.Drawing.Size(32, 17);
             this.label10.TabIndex = 90;
@@ -1399,7 +1400,7 @@
             // 
             this.label6.AutoSize = true;
             this.label6.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.label6.Location = new System.Drawing.Point(2, 110);
+            this.label6.Location = new System.Drawing.Point(8, 110);
             this.label6.Name = "label6";
             this.label6.Size = new System.Drawing.Size(32, 17);
             this.label6.TabIndex = 87;
@@ -1618,6 +1619,17 @@
         private System.Windows.Forms.Label pi_title;
         private System.Windows.Forms.Label label9;
         private System.Windows.Forms.Label ProcessCount;
+        private System.Windows.Forms.DataGridViewTextBoxColumn pd_pdno;
+        private System.Windows.Forms.DataGridViewTextBoxColumn pjd_id;
+        private System.Windows.Forms.DataGridViewTextBoxColumn pd_custprodcode1;
+        private System.Windows.Forms.DataGridViewTextBoxColumn pd_prodcode;
+        private System.Windows.Forms.DataGridViewTextBoxColumn pd_whcode;
+        private System.Windows.Forms.DataGridViewTextBoxColumn CollectedNum;
+        private System.Windows.Forms.DataGridViewTextBoxColumn UnCollectedNum;
+        private System.Windows.Forms.DataGridViewTextBoxColumn pd_outqty;
+        private System.Windows.Forms.DataGridViewTextBoxColumn pr_unit;
+        private System.Windows.Forms.DataGridViewTextBoxColumn pd_brand;
+        private System.Windows.Forms.DataGridViewTextBoxColumn pjd_zxbzs_user;
         private System.Windows.Forms.DataGridViewCheckBoxColumn Choose;
         private System.Windows.Forms.DataGridViewCheckBoxColumn pib_ifprint;
         private System.Windows.Forms.DataGridViewTextBoxColumn pib_id1;
@@ -1638,16 +1650,5 @@
         private System.Windows.Forms.DataGridViewTextBoxColumn pr_spec;
         private System.Windows.Forms.DataGridViewTextBoxColumn pib_outboxcode1;
         private System.Windows.Forms.DataGridViewTextBoxColumn pib_outboxcode2;
-        private System.Windows.Forms.DataGridViewTextBoxColumn pd_pdno;
-        private System.Windows.Forms.DataGridViewTextBoxColumn pjd_id;
-        private System.Windows.Forms.DataGridViewTextBoxColumn pd_custprodcode1;
-        private System.Windows.Forms.DataGridViewTextBoxColumn pd_prodcode;
-        private System.Windows.Forms.DataGridViewTextBoxColumn pd_whcode;
-        private System.Windows.Forms.DataGridViewTextBoxColumn CollectedNum;
-        private System.Windows.Forms.DataGridViewTextBoxColumn UnCollectedNum;
-        private System.Windows.Forms.DataGridViewTextBoxColumn pd_outqty;
-        private System.Windows.Forms.DataGridViewTextBoxColumn pr_unit;
-        private System.Windows.Forms.DataGridViewTextBoxColumn pd_brand;
-        private System.Windows.Forms.DataGridViewTextBoxColumn pjd_zxbzs_user;
     }
 }

+ 16 - 11
UAS-出货标签管理(泽天)/UAS_出货标签管理.cs

@@ -469,8 +469,8 @@ namespace UAS_LabelMachine
             SingleLabelCombox.DataSource = dt;
             if (SingleLabelCombox.Text != "")
             {
-                if (!SingleLabelCombox.SelectedValue.ToString().Contains("System.Data.DataRowView"))
-                    SingleReport.Load(SingleLabelCombox.SelectedValue.ToString());
+                //if (!SingleLabelCombox.SelectedValue.ToString().Contains("System.Data.DataRowView"))
+                //    SingleReport.Load(SingleLabelCombox.SelectedValue.ToString());
             }
             sql.Clear();
             sql.Append("select to_char(nvl(cl_date,sysdate),'YYYY-MM-DD HH24:Mi:SS') cl_date,cl_labelurl,cl_labelname,cl_isdefault,la_id||'#'||cl_labelurl||'#'||to_char(cl_date,'YYYY-MM-DD HH24:Mi:SS')  la_id,cl_custcode from customerlabel left join prodinout on pi_cardcode=cl_custcode ");
@@ -482,10 +482,9 @@ namespace UAS_LabelMachine
             MidLabelCombox.DataSource = dt;
             if (MidLabelCombox.Text != "")
             {
-                if (!MidLabelCombox.SelectedValue.ToString().Contains("System.Data.DataRowView"))
-                    MidReport.Load(MidLabelCombox.SelectedValue.ToString());
+                //if (!MidLabelCombox.SelectedValue.ToString().Contains("System.Data.DataRowView"))
+                //    MidReport.Load(MidLabelCombox.SelectedValue.ToString());
             }
-            //缓存中盒参数
             sql.Clear();
             sql.Append("select to_char(nvl(cl_date,sysdate),'YYYY-MM-DD HH24:Mi:SS') cl_date,cl_labelurl,cl_labelname,cl_isdefault,la_id||'#'||cl_labelurl||'#'||to_char(cl_date,'YYYY-MM-DD HH24:Mi:SS')  la_id,cl_custcode from customerlabel left join prodinout on pi_cardcode=cl_custcode ");
             sql.Append("left join customer on cu_code=cl_custcode left join label on la_code=CL_LABELCODE where ((pi_cardcode='" + pi_cardcode.Text + "' ");
@@ -496,10 +495,10 @@ namespace UAS_LabelMachine
             OutBoxCombox.DataSource = dt;
             if (OutBoxCombox.Text != "")
             {
-                if (!OutBoxCombox.SelectedValue.ToString().Contains("System.Data.DataRowView"))
-                    OutReport.Load(OutBoxCombox.SelectedValue.ToString());
+                //if (!OutBoxCombox.SelectedValue.ToString().Contains("System.Data.DataRowView"))
+                //    OutReport.Load(OutBoxCombox.SelectedValue.ToString());
             }
-            FootReport.Load(@"\\10.2.10.238\PRINTE\FASTREPORT\唛头.frx");
+            //FootReport.Load(@"\\10.2.10.238\PRINTE\FASTREPORT\唛头.frx");
             //缓存外箱参数
             ComBoxClickChangeLabelDoc = true;
         }
@@ -1063,6 +1062,7 @@ namespace UAS_LabelMachine
             {
                 BaseUtil.FillDgvWithDataTable(LabelInf, LabelInfDataTable);
             }
+            LabelInf.AutoResizeColumns();
             if (LabelInf.Rows.Count > 0)
                 LabelInf.FirstDisplayedScrollingRowIndex = LabelInf.Rows.Count - 1;
             double CollectNum = 0;
@@ -1619,8 +1619,10 @@ namespace UAS_LabelMachine
                         if (i + 1 < LabelInf.Rows.Count)
                         {
                             string FPrcode = LabelInf.Rows[i].Cells["pib_prodcode"].Value.ToString();
+                            string FPocode = LabelInf.Rows[i].Cells["pd_pocode"].Value.ToString();
                             string BPrcode = LabelInf.Rows[i + 1].Cells["pib_prodcode"].Value.ToString();
-                            if (FPrcode != BPrcode)
+                            string BPocode = LabelInf.Rows[i + 1].Cells["pd_pocode"].Value.ToString();
+                            if (FPrcode != BPrcode || FPocode != BPocode)
                             {
                                 MaxNum = MaxNum + 1;
                             }
@@ -1714,8 +1716,11 @@ namespace UAS_LabelMachine
         int SelectRowIndex = -1;
         private void LabelInf_CellClick(object sender, DataGridViewCellEventArgs e)
         {
-            LabelInf.Rows[e.RowIndex].Selected = true;
-            SelectRowIndex = e.RowIndex;
+            if (e.RowIndex >= 0)
+            {
+                LabelInf.Rows[e.RowIndex].Selected = true;
+                SelectRowIndex = e.RowIndex;
+            }
         }
     }
 }