瀏覽代碼

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

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

26
         private string ip;
26
         private string ip;
27
         private string port;
27
         private string port;
28
         private SocketHelper.TcpClients sockeTcpClients;
28
         private SocketHelper.TcpClients sockeTcpClients;
29
-        private VcarecityPD vcarecityProtocolBean;
29
+        private VcarecityPD vcarecityProtocolBean = null;
30
 
30
 
31
         private void Form1_Load(object sender, EventArgs e)
31
         private void Form1_Load(object sender, EventArgs e)
32
         {
32
         {
33
             XmlLoader xmlLoader = new XmlLoader();
33
             XmlLoader xmlLoader = new XmlLoader();
34
             vcarecityProtocolBean = xmlLoader.loadXml();
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
             SocketHelper.pushSockets = new SocketHelper.PushSockets(receiveData); //注册推送器
41
             SocketHelper.pushSockets = new SocketHelper.PushSockets(receiveData); //注册推送器
40
             sockeTcpClients = new SocketHelper.TcpClients();
42
             sockeTcpClients = new SocketHelper.TcpClients();
42
             port = tbPort.Text.Trim();
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
         private void receiveData(SocketHelper.Sockets sks)
57
         private void receiveData(SocketHelper.Sockets sks)
47
         {
58
         {
134
         {
145
         {
135
             try
146
             try
136
             {
147
             {
148
+                if (!showTopForNoLoadXML())
149
+                    return;
150
+
137
                 ip = tbIpaddress.Text.Trim();
151
                 ip = tbIpaddress.Text.Trim();
138
                 port = tbPort.Text.Trim();
152
                 port = tbPort.Text.Trim();
139
 
153
 
141
                 sockeTcpClients.Start();
155
                 sockeTcpClients.Start();
142
 
156
 
143
                 //                string loginCmd = "7e7e7e4442832e833c8200143839383630324231313931353530343739383737f7";
157
                 //                string loginCmd = "7e7e7e4442832e833c8200143839383630324231313931353530343739383737f7";
144
-                string loginCmd = "7e7e7e";
158
+                string loginCmd = vcarecityProtocolBean.ProtocolStartSymbol;
145
                 loginCmd += tbEquipmentAddress.Text.Trim() + "82" +
159
                 loginCmd += tbEquipmentAddress.Text.Trim() + "82" +
146
                             Utils.stringWith0(Utils.tenToHex(tbCCID.Text.Trim().Length / 2), 4);
160
                             Utils.stringWith0(Utils.tenToHex(tbCCID.Text.Trim().Length / 2), 4);
147
                 loginCmd += tbCCID.Text.Trim();
161
                 loginCmd += tbCCID.Text.Trim();
170
 
184
 
171
         private void btnQuickLogout_Click(object sender, EventArgs e)
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
         private void tsmiLoadXml_Click(object sender, EventArgs e)
197
         private void tsmiLoadXml_Click(object sender, EventArgs e)