浏览代码

Fix Some Bug

张泳健 8 年前
父节点
当前提交
9cd2acfbaa
共有 2 个文件被更改,包括 28 次插入7 次删除
  1. 1 1
      GWSocketClient/Form1.Designer.cs
  2. 27 6
      GWSocketClient/Form1.cs

+ 1 - 1
GWSocketClient/Form1.Designer.cs 查看文件

@@ -411,7 +411,7 @@
411 411
             this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
412 412
             this.Name = "Form1";
413 413
             this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
414
-            this.Text = "Form1";
414
+            this.Text = "DTU模拟器";
415 415
             this.Load += new System.EventHandler(this.Form1_Load);
416 416
             this.groupBox1.ResumeLayout(false);
417 417
             this.groupBox1.PerformLayout();

+ 27 - 6
GWSocketClient/Form1.cs 查看文件

@@ -26,15 +26,17 @@ namespace GWSocketClient
26 26
         private string ip;
27 27
         private string port;
28 28
         private SocketHelper.TcpClients sockeTcpClients;
29
-        private VcarecityPD vcarecityProtocolBean;
29
+        private VcarecityPD vcarecityProtocolBean = null;
30 30
 
31 31
         private void Form1_Load(object sender, EventArgs e)
32 32
         {
33 33
             XmlLoader xmlLoader = new XmlLoader();
34 34
             vcarecityProtocolBean = xmlLoader.loadXml();
35
-            this.Text = vcarecityProtocolBean.ProtocolName + " - " + vcarecityProtocolBean.ProtocolNo + " - " +
36
-                        vcarecityProtocolBean.ProtocolStartSymbol;
37
-
35
+            if (vcarecityProtocolBean != null)
36
+            {
37
+                this.Text = vcarecityProtocolBean.ProtocolName + " - " + vcarecityProtocolBean.ProtocolNo + " - " +
38
+                            vcarecityProtocolBean.ProtocolStartSymbol;
39
+            }
38 40
 
39 41
             SocketHelper.pushSockets = new SocketHelper.PushSockets(receiveData); //注册推送器
40 42
             sockeTcpClients = new SocketHelper.TcpClients();
@@ -42,6 +44,15 @@ namespace GWSocketClient
42 44
             port = tbPort.Text.Trim();
43 45
         }
44 46
 
47
+        private bool showTopForNoLoadXML()
48
+        {
49
+            if (vcarecityProtocolBean == null)
50
+            {
51
+                MessageBox.Show("请先加载XML协议文件");
52
+                return false;
53
+            }
54
+            return true;
55
+        }
45 56
 
46 57
         private void receiveData(SocketHelper.Sockets sks)
47 58
         {
@@ -134,6 +145,9 @@ namespace GWSocketClient
134 145
         {
135 146
             try
136 147
             {
148
+                if (!showTopForNoLoadXML())
149
+                    return;
150
+
137 151
                 ip = tbIpaddress.Text.Trim();
138 152
                 port = tbPort.Text.Trim();
139 153
 
@@ -141,7 +155,7 @@ namespace GWSocketClient
141 155
                 sockeTcpClients.Start();
142 156
 
143 157
                 //                string loginCmd = "7e7e7e4442832e833c8200143839383630324231313931353530343739383737f7";
144
-                string loginCmd = "7e7e7e";
158
+                string loginCmd = vcarecityProtocolBean.ProtocolStartSymbol;
145 159
                 loginCmd += tbEquipmentAddress.Text.Trim() + "82" +
146 160
                             Utils.stringWith0(Utils.tenToHex(tbCCID.Text.Trim().Length / 2), 4);
147 161
                 loginCmd += tbCCID.Text.Trim();
@@ -170,7 +184,14 @@ namespace GWSocketClient
170 184
 
171 185
         private void btnQuickLogout_Click(object sender, EventArgs e)
172 186
         {
173
-            sockeTcpClients.Stop();
187
+            try
188
+            {
189
+                sockeTcpClients.Stop();
190
+            }
191
+            catch (Exception exception)
192
+            {
193
+//                addToListboxItem("你还没有登录!!" + exception.Message);
194
+            }
174 195
         }
175 196
 
176 197
         private void tsmiLoadXml_Click(object sender, EventArgs e)