Kerry 8 年之前
父節點
當前提交
ae7eccad72
共有 3 個文件被更改,包括 64 次插入32 次删除
  1. 二進制
      .vs/GWSocketClient/v15/.suo
  2. 64 32
      GWSocketClient/Form1.cs
  3. 二進制
      GWSocketClient/bin/Debug/dbfile/ID_INFO.accdb

二進制
.vs/GWSocketClient/v15/.suo 查看文件


+ 64 - 32
GWSocketClient/Form1.cs 查看文件

37
 
37
 
38
         private void Form1_Load(object sender, EventArgs e)
38
         private void Form1_Load(object sender, EventArgs e)
39
         {
39
         {
40
-            XmlLoader xmlLoader = new XmlLoader();
41
-            vcarecityProtocolBean = xmlLoader.loadXml();
40
+//            XmlLoader xmlLoader = new XmlLoader();
41
+//            vcarecityProtocolBean = xmlLoader.loadXml();
42
             if (vcarecityProtocolBean != null)
42
             if (vcarecityProtocolBean != null)
43
             {
43
             {
44
                 this.Text = vcarecityProtocolBean.ProtocolName + " - " + vcarecityProtocolBean.ProtocolNo + " - " +
44
                 this.Text = vcarecityProtocolBean.ProtocolName + " - " + vcarecityProtocolBean.ProtocolNo + " - " +
114
         //处理回复信息
114
         //处理回复信息
115
         private void handleResponse(SocketHelper.Sockets sks, string reqData)
115
         private void handleResponse(SocketHelper.Sockets sks, string reqData)
116
         {
116
         {
117
-            string resp = tfTmpResponse.Text.Trim();
117
+            //取出原数据功能码
118
+            string functionWord = reqData.Substring(18, 2);
119
+            int funcode = Utils.hexToTen(functionWord);
118
 
120
 
119
-            if (resp.Equals(""))
121
+            if (!(funcode == 16 || funcode == 32))
120
             {
122
             {
121
-                resp = "00";
123
+                Console.WriteLine(funcode + " 这个功能码不用回复!");
124
+                return;
122
             }
125
             }
123
 
126
 
124
-            string functionWord = reqData.Substring(18, 2);
125
-            int funcode = Utils.hexToTen(functionWord);
126
 
127
 
127
             //16 表示要读数据,返回数据库中的数据
128
             //16 表示要读数据,返回数据库中的数据
128
             //32 表示返回结果 成功:00 失败:01 
129
             //32 表示返回结果 成功:00 失败:01 
129
 
130
 
130
-
131
             //数据长度
131
             //数据长度
132
-            int dataLen = Utils.hexToTen(reqData.Substring(20, 4));
132
+            int dataLen = Utils.hexToTen(reqData.Substring(20, 4)) * 2;
133
+
133
             string readlData = "";
134
             string readlData = "";
134
             try
135
             try
135
             {
136
             {
138
             catch (Exception e)
139
             catch (Exception e)
139
             {
140
             {
140
                 Console.WriteLine(e.Message);
141
                 Console.WriteLine(e.Message);
141
-                addToListboxItem("数据长度与帧长度对不上!!");
142
+                addToListboxItem("数据长度与帧长度对不上!! 帧数据长度=" + (dataLen / 2) + " ,Error=" + e.Message);
142
                 return;
143
                 return;
143
             }
144
             }
144
 
145
 
146
+            //消息流水&测量点
147
+            string flowPoint = readlData.Substring(0, 6);
148
+            //ID
145
             string myId = readlData.Substring(6, 4);
149
             string myId = readlData.Substring(6, 4);
150
+            //对应信息
146
             string idInfo = readlData.Substring(10);
151
             string idInfo = readlData.Substring(10);
147
 
152
 
153
+            //回复功能码
154
+            int responceFunCode = funcode + 128;
155
+
156
+            string cmd = reqData.Substring(0, 18); //前面的
157
+
158
+            cmd += Utils.stringWith0(Utils.tenToHex(responceFunCode), 2); //回复功能码
159
+            string body = flowPoint + myId;
160
+
148
             if (funcode == 32)
161
             if (funcode == 32)
149
             {
162
             {
150
                 //设置数据
163
                 //设置数据
151
                 int res = AccsessDbLoader.getInstance().setReceiveData(myId, idInfo);
164
                 int res = AccsessDbLoader.getInstance().setReceiveData(myId, idInfo);
165
+                //成功回复00 失败回复01
152
                 if (res > 0)
166
                 if (res > 0)
153
                 {
167
                 {
154
-                    //00
168
+                    body += "00";
169
+                    AccsessDbLoader.getInstance().reloadAccessDb();
155
                 }
170
                 }
156
                 else
171
                 else
157
                 {
172
                 {
158
-                    //01
173
+                    body += "01";
159
                 }
174
                 }
160
             }
175
             }
161
-            else if (funcode == 16)
176
+            else
162
             {
177
             {
163
-                //返回数据库的数据
164
-            }
165
-
178
+                //返回数据库的数据 OR 临时数据,如果临时数据有数据的话
179
+                try
180
+                {
181
+                    string responce = AccsessDbLoader.getInstance().getUserIdInfo()[myId];
166
 
182
 
167
-            if (funcode == 16 || funcode == 32)
168
-            {
169
-                funcode = funcode + 128;
170
-                functionWord = Utils.stringWith0(Utils.tenToHex(funcode), 2);
171
-                string cmd = reqData.Substring(0, 18) + functionWord;
172
-                string data = reqData.Substring(24, 10) + resp;
173
-                cmd = cmd + Utils.stringWith0(Utils.tenToHex(data.Length / 2), 4) + data;
174
-                cmd = Utils.calcCrcCode(cmd);
183
+                    if (!tfTmpResponse.Text.Trim().Equals(""))
184
+                    {
185
+                        string inputRespocse = tfTmpResponse.Text.Trim();
186
+                        responce = Utils.stringWith0(inputRespocse, responce.Length);
187
+                    }
188
+                    body += responce;
189
+                }
190
+                catch (Exception e)
191
+                {
192
+                    Console.WriteLine(e);
193
+                    addToListboxItem("异常,没有这个ID=(" + myId + "),ERROR=" + e.Message);
194
+                    return;
195
+                }
196
+            }
197
+            cmd += Utils.stringWith0(Utils.tenToHex(body.Length / 2), 4); //长度
198
+            cmd += body; //消息体 
199
+            cmd = Utils.calcCrcCode(cmd); //计算检验码
175
 
200
 
176
-                addToListboxItem(string.Format("回复服务端{0}回应消息:[{1}]", sks.Ip, cmd));
201
+            addToListboxItem(string.Format("回复服务端{0}回应消息:[{1}]", sks.Ip, cmd));
177
 
202
 
178
-                byte[] ts = HexUtil.hexToBytes(cmd);
179
-                sockeTcpClients.SendData(ts);
180
-            }
203
+            byte[] ts = HexUtil.hexToBytes(cmd);
204
+            sockeTcpClients.SendData(ts);
181
         }
205
         }
182
 
206
 
207
+
183
         private void tbEquipmentAddress_TextChanged(object sender, EventArgs e)
208
         private void tbEquipmentAddress_TextChanged(object sender, EventArgs e)
184
         {
209
         {
185
             string equipmentAddress = tbEquipmentAddress.Text.Trim();
210
             string equipmentAddress = tbEquipmentAddress.Text.Trim();
191
         {
216
         {
192
             try
217
             try
193
             {
218
             {
194
-                if (!showTopForNoLoadXML())
195
-                    return;
219
+                /*if (!showTopForNoLoadXML())
220
+                    return;*/
196
 
221
 
197
                 ip = tbIpaddress.Text.Trim();
222
                 ip = tbIpaddress.Text.Trim();
198
                 port = tbPort.Text.Trim();
223
                 port = tbPort.Text.Trim();
414
 
439
 
415
         private void btnTextCmd_Click(object sender, EventArgs e)
440
         private void btnTextCmd_Click(object sender, EventArgs e)
416
         {
441
         {
417
-            try
442
+            string code = Utils.calcCrcCode("7e7e7e123456789abc20000701010107030001");
443
+//            code = Utils.calcCrcCode("7e7e7e123456789abc10000501010107023f");
444
+            Console.WriteLine(code);
445
+
446
+            handleResponse(null, code);
447
+
448
+
449
+            /*try
418
             {
450
             {
419
                 Dictionary<string, string> abc = AccsessDbLoader.getInstance().getUserIdInfo();
451
                 Dictionary<string, string> abc = AccsessDbLoader.getInstance().getUserIdInfo();
420
                 MessageBox.Show(abc.Count + "");
452
                 MessageBox.Show(abc.Count + "");
424
             catch (Exception exception)
456
             catch (Exception exception)
425
             {
457
             {
426
                 Console.WriteLine(exception);
458
                 Console.WriteLine(exception);
427
-            }
459
+            }*/
428
         }
460
         }
429
     }
461
     }
430
 }
462
 }

二進制
GWSocketClient/bin/Debug/dbfile/ID_INFO.accdb 查看文件