张泳健 пре 8 година
родитељ
комит
46517f84d8

BIN
.vs/GWSocketClient/v15/.suo Прегледај датотеку


+ 33 - 0
GWSocketClient/Form1.Designer.cs Прегледај датотеку

@@ -50,9 +50,12 @@
50 50
             this.label5 = new System.Windows.Forms.Label();
51 51
             this.toolStripStatusLabel2 = new System.Windows.Forms.ToolStripStatusLabel();
52 52
             this.tsslCCIDLEN = new System.Windows.Forms.ToolStripStatusLabel();
53
+            this.groupBox2 = new System.Windows.Forms.GroupBox();
54
+            this.listBoxShow = new System.Windows.Forms.ListBox();
53 55
             this.groupBox1.SuspendLayout();
54 56
             this.menuStrip1.SuspendLayout();
55 57
             this.statusStrip1.SuspendLayout();
58
+            this.groupBox2.SuspendLayout();
56 59
             this.SuspendLayout();
57 60
             // 
58 61
             // groupBox1
@@ -194,6 +197,7 @@
194 197
             this.btnQuickLogout.TabIndex = 6;
195 198
             this.btnQuickLogout.Text = "退出登录";
196 199
             this.btnQuickLogout.UseVisualStyleBackColor = true;
200
+            this.btnQuickLogout.Click += new System.EventHandler(this.btnQuickLogout_Click);
197 201
             // 
198 202
             // btnSendData
199 203
             // 
@@ -262,11 +266,37 @@
262 266
             this.tsslCCIDLEN.Size = new System.Drawing.Size(32, 17);
263 267
             this.tsslCCIDLEN.Text = "20.0";
264 268
             // 
269
+            // groupBox2
270
+            // 
271
+            this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
272
+            | System.Windows.Forms.AnchorStyles.Left) 
273
+            | System.Windows.Forms.AnchorStyles.Right)));
274
+            this.groupBox2.Controls.Add(this.listBoxShow);
275
+            this.groupBox2.Location = new System.Drawing.Point(12, 396);
276
+            this.groupBox2.Name = "groupBox2";
277
+            this.groupBox2.Size = new System.Drawing.Size(883, 218);
278
+            this.groupBox2.TabIndex = 13;
279
+            this.groupBox2.TabStop = false;
280
+            this.groupBox2.Text = "groupBox2";
281
+            // 
282
+            // listBoxShow
283
+            // 
284
+            this.listBoxShow.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
285
+            | System.Windows.Forms.AnchorStyles.Left) 
286
+            | System.Windows.Forms.AnchorStyles.Right)));
287
+            this.listBoxShow.FormattingEnabled = true;
288
+            this.listBoxShow.ItemHeight = 12;
289
+            this.listBoxShow.Location = new System.Drawing.Point(8, 20);
290
+            this.listBoxShow.Name = "listBoxShow";
291
+            this.listBoxShow.Size = new System.Drawing.Size(869, 184);
292
+            this.listBoxShow.TabIndex = 0;
293
+            // 
265 294
             // Form1
266 295
             // 
267 296
             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
268 297
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
269 298
             this.ClientSize = new System.Drawing.Size(907, 639);
299
+            this.Controls.Add(this.groupBox2);
270 300
             this.Controls.Add(this.statusStrip1);
271 301
             this.Controls.Add(this.groupBox1);
272 302
             this.Controls.Add(this.menuStrip1);
@@ -279,6 +309,7 @@
279 309
             this.menuStrip1.PerformLayout();
280 310
             this.statusStrip1.ResumeLayout(false);
281 311
             this.statusStrip1.PerformLayout();
312
+            this.groupBox2.ResumeLayout(false);
282 313
             this.ResumeLayout(false);
283 314
             this.PerformLayout();
284 315
 
@@ -308,6 +339,8 @@
308 339
         private System.Windows.Forms.Label label5;
309 340
         private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel2;
310 341
         private System.Windows.Forms.ToolStripStatusLabel tsslCCIDLEN;
342
+        private System.Windows.Forms.GroupBox groupBox2;
343
+        private System.Windows.Forms.ListBox listBoxShow;
311 344
     }
312 345
 }
313 346
 

+ 13 - 2
GWSocketClient/Form1.cs Прегледај датотеку

@@ -7,6 +7,7 @@ using System.Linq;
7 7
 using System.Text;
8 8
 using System.Threading.Tasks;
9 9
 using System.Windows.Forms;
10
+using GWSocketClient.util;
10 11
 using XuanJiSocket;
11 12
 
12 13
 
@@ -33,6 +34,11 @@ namespace GWSocketClient
33 34
 
34 35
         private void receiveData(SocketHelper.Sockets sks)
35 36
         {
37
+            byte[] buffer = new byte[sks.Offset];
38
+            Array.Copy(sks.RecBuffer, buffer, sks.Offset);
39
+            string byteToHexStr = HexUtil.byteToHexStr(buffer);
40
+
41
+            MessageBox.Show("1" + byteToHexStr);
36 42
         }
37 43
 
38 44
         private void tbEquipmentAddress_TextChanged(object sender, EventArgs e)
@@ -52,7 +58,8 @@ namespace GWSocketClient
52 58
                 sockeTcpClients.InitSocket(ip, int.Parse(port));
53 59
                 sockeTcpClients.Start();
54 60
 
55
-                
61
+                byte[] ts = HexUtil.hexToBytes("7e7e7e4442832e833c8200143839383630324231313931353530343739383737f7");
62
+                sockeTcpClients.SendData(ts);
56 63
             }
57 64
             catch (Exception ex)
58 65
             {
@@ -64,10 +71,14 @@ namespace GWSocketClient
64 71
 
65 72
         private void tbCCID_TextChanged(object sender, EventArgs e)
66 73
         {
67
-            
68 74
             string ccid = tbCCID.Text.Trim();
69 75
 
70 76
             tsslCCIDLEN.Text = ccid.Length / 2.0 + "";
71 77
         }
78
+
79
+        private void btnQuickLogout_Click(object sender, EventArgs e)
80
+        {
81
+            sockeTcpClients.Stop();
82
+        }
72 83
     }
73 84
 }

+ 2 - 0
GWSocketClient/GWSocketClient.csproj Прегледај датотеку

@@ -57,6 +57,8 @@
57 57
     <Compile Include="Program.cs" />
58 58
     <Compile Include="Properties\AssemblyInfo.cs" />
59 59
     <Compile Include="util\CheckUtil.cs" />
60
+    <Compile Include="util\HexUtil.cs" />
61
+    <Compile Include="util\Utils.cs" />
60 62
     <EmbeddedResource Include="Form1.resx">
61 63
       <DependentUpon>Form1.cs</DependentUpon>
62 64
     </EmbeddedResource>

+ 54 - 0
GWSocketClient/util/HexUtil.cs Прегледај датотеку

@@ -0,0 +1,54 @@
1
+using System;
2
+using System.Collections.Generic;
3
+using System.Linq;
4
+using System.Text;
5
+using System.Threading.Tasks;
6
+
7
+namespace GWSocketClient.util
8
+{
9
+    class HexUtil
10
+    {
11
+        public static byte[] hexToBytes(string hex)
12
+        {
13
+            hex = hex.Replace(" ", "").Replace("\r", "").Replace("\t", "").Replace("\n", "");
14
+            int len = hex.Length / 2;
15
+            byte[] bs = new byte[len];
16
+            for (int i = 0; i < len; i++)
17
+            {
18
+                string sub = hex.Substring(2 * i, 2);
19
+//                String sub = hex.substring(2 * i, 2 * i + 2);
20
+                int v = Utils.hexToTen(sub);
21
+//                int v = Integer.valueOf(sub, 16);
22
+                bs[i] = (byte) v;
23
+            }
24
+
25
+            return bs;
26
+        }
27
+
28
+        public static String byteToHexStr(byte[] bs)
29
+        {
30
+            int len = bs.Length;
31
+            StringBuilder sb = new StringBuilder(len * 2);
32
+            for (int i = 0; i < len; i++)
33
+            {
34
+                byte b = bs[i];
35
+                string str = Convert.ToString(b, 16);
36
+//                String str = Integer.toHexString(b);
37
+                if (str.Length == 1)
38
+                {
39
+                    sb.Append("0").Append(str);
40
+                }
41
+                else if (str.Length > 2)
42
+                {
43
+                    sb.Append(str.Substring(str.Length - 2));
44
+                }
45
+                else
46
+                {
47
+                    sb.Append(str);
48
+                }
49
+            }
50
+
51
+            return sb.ToString();
52
+        }
53
+    }
54
+}

+ 133 - 0
GWSocketClient/util/Utils.cs Прегледај датотеку

@@ -0,0 +1,133 @@
1
+using System;
2
+using System.Collections.Generic;
3
+using System.Globalization;
4
+using System.Linq;
5
+using System.Text;
6
+using System.Threading.Tasks;
7
+
8
+namespace GWSocketClient.util
9
+{
10
+    class Utils
11
+    {
12
+        public static int hexToTen(string hex)
13
+        {
14
+            return int.Parse(hex, NumberStyles.HexNumber);
15
+        }
16
+
17
+
18
+        public static string hexToBin(string hex)
19
+        {
20
+            int res = hexToTen(hex);
21
+            return stringWith0(Convert.ToString(res, 2), 8);
22
+        }
23
+
24
+        public static string tenToHex(string ten)
25
+        {
26
+            return tenToHex(Convert.ToInt32(ten));
27
+        }
28
+
29
+
30
+        public static string tenToHex(int ten)
31
+        {
32
+            return Convert.ToString(ten, 16);
33
+        }
34
+
35
+
36
+        public static string tenToBin(string ten)
37
+        {
38
+            return tenToBin(Convert.ToInt32(ten));
39
+        }
40
+
41
+
42
+        public static string tenToBin(int ten)
43
+        {
44
+            return Convert.ToString(ten, 2);
45
+        }
46
+
47
+
48
+        public static string binToTen(string bin)
49
+        {
50
+            return binToTenInt(bin) + "";
51
+        }
52
+
53
+        public static int binToTenInt(string bin)
54
+        {
55
+            return Convert.ToInt32(bin, 2);
56
+        }
57
+
58
+
59
+        public static string binToHex(string bin)
60
+        {
61
+            int i = binToTenInt(bin);
62
+            return stringWith0(Convert.ToString(i, 16), 2);
63
+        }
64
+
65
+
66
+        public static string stringWith0(string str, int len)
67
+        {
68
+            int delta = len - str.Length;
69
+            string sb = "";
70
+            for (int i = 0; i < delta; i++)
71
+            {
72
+                sb += "0";
73
+            }
74
+            return sb + str;
75
+        }
76
+
77
+        public static string[] REG_STRING =
78
+        {
79
+            "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "a", "b", "c", "d", "e", "f"
80
+        };
81
+
82
+        public static string validInput(string reg)
83
+        {
84
+            string trim = reg.Trim();
85
+            if (trim.Length > 0)
86
+            {
87
+                string t = trim.Substring(trim.Length - 1, 1);
88
+                if (REG_STRING.Contains(t))
89
+                {
90
+                    return trim;
91
+                }
92
+                else
93
+                {
94
+                    return trim.Substring(0, trim.Length - 1);
95
+                }
96
+            }
97
+            return trim;
98
+        }
99
+
100
+        public static string calcCrcCode(string str)
101
+        {
102
+            List<string> list = new List<string>();
103
+            for (int i = 0; i < str.Length; i += 2)
104
+            {
105
+                list.Add(str.Substring(i, 2));
106
+            }
107
+
108
+            int result = 0;
109
+            for (int i = 3; i < list.Count(); i++)
110
+            {
111
+                result ^= hexToTen(list[i]);
112
+            }
113
+            return str + stringWith0(tenToHex(result), 2);
114
+        }
115
+
116
+
117
+        public static string calcCrcCode2(string str)
118
+        {
119
+            List<string> list = new List<string>();
120
+            for (int i = 0; i < str.Length; i += 2)
121
+            {
122
+                list.Add(str.Substring(i, 2));
123
+            }
124
+
125
+            int result = 0;
126
+            for (int i = 3; i < list.Count(); i++)
127
+            {
128
+                result ^= hexToTen(list[i]);
129
+            }
130
+            return stringWith0(tenToHex(result), 2);
131
+        }
132
+    }
133
+}