//根据信息的种类 ,进行处理:1.数据信息,发送给DTU 2.控制命令,发送给WEB 3.设备列表,更新显示表格 private void proxyProcess(DataTransfer transfer) { switch (transfer.TransferType) { case DataTransferType.DataTransferDataInfo: { DataTransferInfo info = transfer.TransferDataInfo; DeviceInfo di = new DeviceInfo(); di.Parse(info.DeviceNo); string DeviceFullNo = DeviceModule.DeviceNo_Hex2Normal(di.SerialString); string DeviceFullNoMain = DeviceModule.GetDeviceNoMain(DeviceFullNo); bridge.sendToDtu(DeviceFullNo, DeviceFullNoMain, info.Data, info.Offset, info.Length); break; } case DataTransferType.DataTransferCommand: { DTU.GateWay.Protocol.Command command = transfer.TransferCommand; bridge.sendToWeb(command.DeviceInfo.SerialLong, command); break; } case DataTransferType.DataTransferDeviceList: { Device deviceList = transfer.DeviceList; DeviceEvent deviceEvent = transfer.DeviceEvent; updateDeviceListInGridView(deviceList, deviceEvent); break; } case DataTransferType.DataTransferLog: { break; } case DataTransferType.DataTransferUpdateDevice: { string kt = transfer.KeyType; string key = transfer.Key; if (SysCache.ShowInfoLog) { ShowLogData.add("更新设备缓存:" + kt + "," + key); logHelper.Info("更新设备缓存:" + kt + "," + key); } if (kt == "01") { Device device = DeviceModule.GetDeviceByFullDeviceNo_DB(key); if (device != null) { DeviceModule.UpdateDeviceInfo(device); if (dtuServer != null) { dtuServer.updateDevice(device); } updateDeviceListInGridView(device, null); } else { if (SysCache.ShowInfoLog) { ShowLogData.add("更新设备缓存:" + kt + "," + key + " 无法更新设备不存在"); logHelper.Info("更新设备缓存:" + kt + "," + key + " 无法更新设备不存在"); } } } else if (kt == "02") { DeviceModule.RemoveDeviceInfo(key); lock (this.deviceListsDataGridView) { int rows = this.deviceListsDataGridView.Rows.Count; for (int i = 0; i < rows; i++) { object obj = this.deviceListsDataGridView.Rows[i].Cells[1].Value; if (obj != null) { string val = obj.ToString(); if (val.Equals(key)) { this.deviceListsDataGridView.Rows.Remove(this.deviceListsDataGridView.Rows[i]); return; } } } } } break; } case DataTransferType.DataTransferUpdateCardUser: { string kt = transfer.KeyType; string key = transfer.Key; ShowLogData.add("更新用户卡缓存:" + kt + "," + key); if (kt == "01") { CardUser cardUser = CardUserModule.GetCardUserBySerialNumber_DB(key); if (cardUser != null) { CardUserModule.UpdateCardUserInfo(cardUser); } } else if (kt == "02") { CardUserModule.RemoveCardUserInfo(key); } break; } case DataTransferType.DataTransferUpdateDistrict: { ShowLogData.add("更新地区缓存"); initDistrictTree(); break; } } }
private void send(object o) { SafeSetLabel(this.label7, "", false); setAllButtonEnable(false); string OperationType = ""; int k = 0; try { k = Convert.ToInt32(o); switch (k) { case 1: OperationType = "设置时间"; break; case 2: OperationType = "设置开采量"; break; case 3: OperationType = "查询时间"; break; case 4: OperationType = "查询开采量"; break; case 5: OperationType = "远程开泵"; break; case 6: OperationType = "远程关泵"; break; case 7: OperationType = "设置主站射频地址"; break; case 8: OperationType = "屏蔽卡号"; break; case 9: OperationType = "解除屏蔽卡号"; break; case 10: OperationType = "水位计参数设置"; break; case 11: OperationType = "水位计参数查询"; break; case 12: OperationType = "水位查询"; break; case 13: OperationType = "状态查询"; break; default: OperationType = ""; break; } if (OperationType.Trim() == "") { SafeSetText(textBox2, "发送命令非法!命令字:" + k, false); setAllButtonEnable(true); return; } } catch (Exception ex) { SafeSetText(textBox2, "发送命令非法!" + ex.Message, false); setAllButtonEnable(true); return; } try { if (this.comboBox1.SelectedIndex < 1) { SafeSetText(textBox2, "请选择一个终端", false); setAllButtonEnable(true); return; } string deviceNo = this.comboBox1.Text.ToString().Trim(); Device device = DeviceModule.GetDeviceByFullDeviceNo(deviceNo); string resDeviceNo = DeviceModule.GetDeviceNoMain(deviceNo); Device resDevice = DeviceModule.GetDeviceByFullDeviceNo(resDeviceNo); if (resDeviceNo.Length != 15) { SafeSetText(textBox2, "终端编号错误!" + resDeviceNo, false); setAllButtonEnable(true); return; } BaseMessage cmd = new BaseMessage(); switch (k) { case 1: if (dateTimePicker1.Value < DateTime.Now.AddDays(-1) || dateTimePicker1.Value > DateTime.Now.AddDays(1)) { SafeSetText(textBox2, "终端时钟取值范围是当前时间前后一天", false); setAllButtonEnable(true); return; } CmdToDtuSetDateTime cmd1 = new CmdToDtuSetDateTime(); cmd1.AddressField = DeviceModule.DeviceNo_Normal2Hex(deviceNo); cmd1.StationType = (byte)device.StationType; cmd1.StationCode = device.StationType == 2 ? device.StationCode : 0; cmd1.DateTimeNew = dateTimePicker1.Value; cmd1.RawDataChar = cmd1.WriteMsg(); cmd1.RawDataStr = HexStringUtility.ByteArrayToHexString(cmd1.RawDataChar); ToDtuCommand.AddBaseMessageToDtu(cmd1.AddressField + "-" + cmd1.AFN, cmd1); cmd.AddressField = cmd1.AddressField; cmd.RawDataStr = cmd1.RawDataStr; cmd.RawDataChar = cmd1.RawDataChar; cmd.AFN = cmd1.AFN; break; case 2: decimal YearExploitation = 0; try { YearExploitation = decimal.Parse(this.textBox4.Text.Trim()); } catch { } if (YearExploitation < 0 || YearExploitation > 9999999.9M) { SafeSetText(textBox2, "开采量取值范围是0-9999999.9", false); setAllButtonEnable(true); return; } CmdToDtuSetYearExploitation cmd2 = new CmdToDtuSetYearExploitation(); cmd2.AddressField = DeviceModule.DeviceNo_Normal2Hex(deviceNo); cmd2.StationType = (byte)device.StationType; cmd2.StationCode = device.StationType == 2 ? device.StationCode : 0; cmd2.YearExploitation = YearExploitation; cmd2.RawDataChar = cmd2.WriteMsg(); cmd2.RawDataStr = HexStringUtility.ByteArrayToHexString(cmd2.RawDataChar); ToDtuCommand.AddBaseMessageToDtu(cmd2.AddressField + "-" + cmd2.AFN, cmd2); cmd.AddressField = cmd2.AddressField; cmd.RawDataStr = cmd2.RawDataStr; cmd.RawDataChar = cmd2.RawDataChar; cmd.AFN = cmd2.AFN; break; case 3: CmdToDtuQueryDateTime cmd3 = new CmdToDtuQueryDateTime(); cmd3.AddressField = DeviceModule.DeviceNo_Normal2Hex(deviceNo); cmd3.StationType = (byte)device.StationType; cmd3.StationCode = device.StationType == 2 ? device.StationCode : 0; cmd3.RawDataChar = cmd3.WriteMsg(); cmd3.RawDataStr = HexStringUtility.ByteArrayToHexString(cmd3.RawDataChar); ToDtuCommand.AddBaseMessageToDtu(cmd3.AddressField + "-" + cmd3.AFN, cmd3); cmd.AddressField = cmd3.AddressField; cmd.RawDataStr = cmd3.RawDataStr; cmd.RawDataChar = cmd3.RawDataChar; cmd.AFN = cmd3.AFN; break; case 4: CmdToDtuQueryYearExploitation cmd4 = new CmdToDtuQueryYearExploitation(); cmd4.AddressField = DeviceModule.DeviceNo_Normal2Hex(deviceNo); cmd4.StationType = (byte)device.StationType; cmd4.StationCode = device.StationType == 2 ? device.StationCode : 0; cmd4.RawDataChar = cmd4.WriteMsg(); cmd4.RawDataStr = HexStringUtility.ByteArrayToHexString(cmd4.RawDataChar); ToDtuCommand.AddBaseMessageToDtu(cmd4.AddressField + "-" + cmd4.AFN, cmd4); cmd.AddressField = cmd4.AddressField; cmd.RawDataStr = cmd4.RawDataStr; cmd.RawDataChar = cmd4.RawDataChar; cmd.AFN = cmd4.AFN; break; case 5: CmdToDtuOpenPump cmd5 = new CmdToDtuOpenPump(); cmd5.AddressField = DeviceModule.DeviceNo_Normal2Hex(deviceNo); cmd5.StationType = (byte)device.StationType; cmd5.StationCode = device.StationType == 2 ? device.StationCode : 0; cmd5.RawDataChar = cmd5.WriteMsg(); cmd5.RawDataStr = HexStringUtility.ByteArrayToHexString(cmd5.RawDataChar); ToDtuCommand.AddBaseMessageToDtu(cmd5.AddressField + "-" + cmd5.AFN, cmd5); cmd.AddressField = cmd5.AddressField; cmd.RawDataStr = cmd5.RawDataStr; cmd.RawDataChar = cmd5.RawDataChar; cmd.AFN = cmd5.AFN; break; case 6: CmdToDtuClosePump cmd6 = new CmdToDtuClosePump(); cmd6.AddressField = DeviceModule.DeviceNo_Normal2Hex(deviceNo); cmd6.StationType = (byte)device.StationType; cmd6.StationCode = device.StationType == 2 ? device.StationCode : 0; cmd6.RawDataChar = cmd6.WriteMsg(); cmd6.RawDataStr = HexStringUtility.ByteArrayToHexString(cmd6.RawDataChar); ToDtuCommand.AddBaseMessageToDtu(cmd6.AddressField + "-" + cmd6.AFN, cmd6); cmd.AddressField = cmd6.AddressField; cmd.RawDataStr = cmd6.RawDataStr; cmd.RawDataChar = cmd6.RawDataChar; cmd.AFN = cmd6.AFN; break; case 7: CmdToDtuSetStationCode cmd7 = new CmdToDtuSetStationCode(); if (device.StationType == 0) { SafeSetText(textBox2, "非主从站无法设置分站射频地址", false); setAllButtonEnable(true); return; } else if (device.StationType == 1) { cmd7.AddressField = deviceNo.Substring(0, 12) + Convert.ToInt32(deviceNo.Substring(12, 3)).ToString("X").PadLeft(2, '0'); cmd7.StationType = (byte)device.StationType; cmd7.StationCode = device.StationType == 2 ? device.StationCode : 0; List <Device> DeviceSubList = DeviceModule.GetAllDeviceSubList(device.Id); List <int> list = new List <int>(); foreach (Device DeviceSub in DeviceSubList) { list.Add(DeviceSub.StationCode); } cmd7.StationCodeList = list; } else if (device.StationType == 2) { cmd7.AddressField = resDeviceNo.Substring(0, 12) + Convert.ToInt32(resDeviceNo.Substring(12, 3)).ToString("X").PadLeft(2, '0'); cmd7.StationType = (byte)resDevice.StationType; cmd7.StationCode = resDevice.StationType == 2 ? resDevice.StationCode : 0; List <Device> DeviceSubList = DeviceModule.GetAllDeviceSubList(resDevice.Id); List <int> list = new List <int>(); foreach (Device DeviceSub in DeviceSubList) { list.Add(DeviceSub.StationCode); } cmd7.StationCodeList = list; } cmd7.RawDataChar = cmd7.WriteMsg(); cmd7.RawDataStr = HexStringUtility.ByteArrayToHexString(cmd7.RawDataChar); ToDtuCommand.AddBaseMessageToDtu(cmd7.AddressField + "-" + cmd7.AFN, cmd7); cmd.AddressField = cmd7.AddressField; cmd.RawDataStr = cmd7.RawDataStr; cmd.RawDataChar = cmd7.RawDataChar; cmd.AFN = cmd7.AFN; break; case 8: string SerialNumber1 = this.textBox3.Text.Trim(); if (SerialNumber1.Length != 8) { SafeSetText(textBox2, "卡号长度只能为8位", false); setAllButtonEnable(true); return; } if (!Regex.IsMatch(SerialNumber1, "^[0-9A-Fa-f]+$")) { SafeSetText(textBox2, "卡号只能为0-9A-Fa-f", false); setAllButtonEnable(true); return; } CmdToDtuShieldSerialNumber cmd8 = new CmdToDtuShieldSerialNumber(); cmd8.AddressField = DeviceModule.DeviceNo_Normal2Hex(deviceNo); cmd8.StationType = (byte)device.StationType; cmd8.StationCode = device.StationType == 2 ? device.StationCode : 0; cmd8.SerialNumber = SerialNumber1; cmd8.RawDataChar = cmd8.WriteMsg(); cmd8.RawDataStr = HexStringUtility.ByteArrayToHexString(cmd8.RawDataChar); ToDtuCommand.AddBaseMessageToDtu(cmd8.AddressField + "-" + cmd8.AFN, cmd8); cmd.AddressField = cmd8.AddressField; cmd.RawDataStr = cmd8.RawDataStr; cmd.RawDataChar = cmd8.RawDataChar; cmd.AFN = cmd8.AFN; break; case 9: string SerialNumber2 = this.textBox3.Text.Trim(); if (SerialNumber2.Length != 8) { SafeSetText(textBox2, "卡号长度只能为8位", false); setAllButtonEnable(true); return; } if (!Regex.IsMatch(SerialNumber2, "^[0-9A-Fa-f]+$")) { SafeSetText(textBox2, "卡号只能为0-9A-Fa-f", false); setAllButtonEnable(true); return; } CmdToDtuShieldSerialNumberCancel cmd9 = new CmdToDtuShieldSerialNumberCancel(); cmd9.AddressField = DeviceModule.DeviceNo_Normal2Hex(deviceNo); cmd9.StationType = (byte)device.StationType; cmd9.StationCode = device.StationType == 2 ? device.StationCode : 0; cmd9.SerialNumber = SerialNumber2; cmd9.RawDataChar = cmd9.WriteMsg(); cmd9.RawDataStr = HexStringUtility.ByteArrayToHexString(cmd9.RawDataChar); ToDtuCommand.AddBaseMessageToDtu(cmd9.AddressField + "-" + cmd9.AFN, cmd9); cmd.AddressField = cmd9.AddressField; cmd.RawDataStr = cmd9.RawDataStr; cmd.RawDataChar = cmd9.RawDataChar; cmd.AFN = cmd9.AFN; break; case 10: CmdToDtuSetGroundWaterParam cmd10 = new CmdToDtuSetGroundWaterParam(); cmd10.AddressField = DeviceModule.DeviceNo_Normal2Hex(deviceNo); cmd10.StationType = (byte)device.StationType; cmd10.StationCode = device.StationType == 2 ? device.StationCode : 0; cmd10.Range = byte.Parse(this.txtRange.Text.Trim()); cmd10.LineLength = double.Parse(this.txtLineLength.Text.Trim()); cmd10.RawDataChar = cmd10.WriteMsg(); cmd10.RawDataStr = HexStringUtility.ByteArrayToHexString(cmd10.RawDataChar); ToDtuCommand.AddBaseMessageToDtu(cmd10.AddressField + "-" + cmd10.AFN, cmd10); cmd.AddressField = cmd10.AddressField; cmd.RawDataStr = cmd10.RawDataStr; cmd.RawDataChar = cmd10.RawDataChar; cmd.AFN = cmd10.AFN; break; case 11: CmdToDtuQueryGroundWaterParam cmd11 = new CmdToDtuQueryGroundWaterParam(); cmd11.AddressField = DeviceModule.DeviceNo_Normal2Hex(deviceNo); cmd11.StationType = (byte)device.StationType; cmd11.StationCode = device.StationType == 2 ? device.StationCode : 0; cmd11.RawDataChar = cmd11.WriteMsg(); cmd11.RawDataStr = HexStringUtility.ByteArrayToHexString(cmd11.RawDataChar); ToDtuCommand.AddBaseMessageToDtu(cmd11.AddressField + "-" + cmd11.AFN, cmd11); cmd.AddressField = cmd11.AddressField; cmd.RawDataStr = cmd11.RawDataStr; cmd.RawDataChar = cmd11.RawDataChar; cmd.AFN = cmd11.AFN; break; case 12: CmdToDtuQueryGroundWater cmd12 = new CmdToDtuQueryGroundWater(); cmd12.AddressField = DeviceModule.DeviceNo_Normal2Hex(deviceNo); cmd12.StationType = (byte)device.StationType; cmd12.StationCode = device.StationType == 2 ? device.StationCode : 0; cmd12.RawDataChar = cmd12.WriteMsg(); cmd12.RawDataStr = HexStringUtility.ByteArrayToHexString(cmd12.RawDataChar); ToDtuCommand.AddBaseMessageToDtu(cmd12.AddressField + "-" + cmd12.AFN, cmd12); cmd.AddressField = cmd12.AddressField; cmd.RawDataStr = cmd12.RawDataStr; cmd.RawDataChar = cmd12.RawDataChar; cmd.AFN = cmd12.AFN; break; case 13: CmdToDtuQueryState cmd13 = new CmdToDtuQueryState(); cmd13.AddressField = DeviceModule.DeviceNo_Normal2Hex(deviceNo); cmd13.StationType = (byte)device.StationType; cmd13.StationCode = device.StationType == 2 ? device.StationCode : 0; cmd13.RawDataChar = cmd13.WriteMsg(); cmd13.RawDataStr = HexStringUtility.ByteArrayToHexString(cmd13.RawDataChar); ToDtuCommand.AddBaseMessageToDtu(cmd13.AddressField + "-" + cmd13.AFN, cmd13); cmd.AddressField = cmd13.AddressField; cmd.RawDataStr = cmd13.RawDataStr; cmd.RawDataChar = cmd13.RawDataChar; cmd.AFN = cmd13.AFN; break; } SafeSetText(textBox2, cmd.RawDataStr, false); SafeSetText(textBox2, Environment.NewLine + "添加发送命令保存!" + cmd.AddressField + "-" + cmd.AFN, true); DeviceOperation op = new DeviceOperation(); op.DeviceNo = deviceNo; op.DeviceName = DeviceModule.GetDeviceByFullDeviceNo(deviceNo).DeviceName; op.OperationTime = DateTime.Now; op.OperationType = OperationType; op.RawData = cmd.RawDataStr; op.Remark = ""; op.UserId = -1; op.UserName = "******"; op.State = "等待发送"; if (OnlineDeviceService.GetOnline(deviceNo) != null || OnlineDeviceService.GetOnline(resDeviceNo) != null) { if (bridge != null) { if (bridge.sendToDtu(deviceNo, resDeviceNo, cmd.RawDataChar, 0, cmd.RawDataChar.Length)) { op.State = "发送成功"; } else { op.State = "发送失败"; } } DeviceOperationModule.AddDeviceOperation(op); if (op.State == "发送失败") { ToDtuCommand.RemoveBaseMessageFromDtu(cmd.AddressField + "-" + cmd.AFN); } if (ToDtuCommand.GetBaseMessageToDtuByKey(cmd.AddressField + "-" + cmd.AFN) != null) { int timeDelay = 0; bool flag = false; while (timeDelay < 300) { BaseMessage res = null; switch (k) { case 1: res = (CmdResponseToDtuSetDateTime)ToDtuCommand.GetBaseMessageFromDtuByKey(cmd.AddressField + "-" + cmd.AFN); if (res != null) { SafeSetText(textBox2, Environment.NewLine + OperationType + "成功!" + timeDelay + ",返回结果:" + ((CmdResponseToDtuSetDateTime)res).DateTimeNew.ToString("yyyy-MM-dd HH:mm:ss"), true); ToDtuCommand.RemoveBaseMessageFromDtu(cmd.AddressField + "-" + cmd.AFN); flag = true; } break; case 2: res = (CmdResponseToDtuSetYearExploitation)ToDtuCommand.GetBaseMessageFromDtuByKey(cmd.AddressField + "-" + cmd.AFN); if (res != null) { SafeSetText(textBox2, Environment.NewLine + OperationType + "成功!" + timeDelay + ",返回结果:" + ((CmdResponseToDtuSetYearExploitation)res).YearExploitation, true); ToDtuCommand.RemoveBaseMessageFromDtu(cmd.AddressField + "-" + cmd.AFN); flag = true; } break; case 3: res = (CmdResponseToDtuQueryDateTime)ToDtuCommand.GetBaseMessageFromDtuByKey(cmd.AddressField + "-" + cmd.AFN); if (res != null) { SafeSetText(textBox2, Environment.NewLine + OperationType + "成功!" + timeDelay + ",返回结果:" + ((CmdResponseToDtuQueryDateTime)res).DateTimeNew.ToString("yyyy-MM-dd HH:mm:ss"), true); ToDtuCommand.RemoveBaseMessageFromDtu(cmd.AddressField + "-" + cmd.AFN); flag = true; } break; case 4: res = (CmdResponseToDtuQueryYearExploitation)ToDtuCommand.GetBaseMessageFromDtuByKey(cmd.AddressField + "-" + cmd.AFN); if (res != null) { SafeSetText(textBox2, Environment.NewLine + OperationType + "成功!" + timeDelay + ",返回结果:" + ((CmdResponseToDtuQueryYearExploitation)res).YearExploitation, true); ToDtuCommand.RemoveBaseMessageFromDtu(cmd.AddressField + "-" + cmd.AFN); flag = true; } break; case 5: res = (CmdResponseToDtuOpenPump)ToDtuCommand.GetBaseMessageFromDtuByKey(cmd.AddressField + "-" + cmd.AFN); if (res != null) { SafeSetText(textBox2, Environment.NewLine + OperationType + "成功!" + timeDelay + ",返回结果:" + ((CmdResponseToDtuOpenPump)res).Result, true); ToDtuCommand.RemoveBaseMessageFromDtu(cmd.AddressField + "-" + cmd.AFN); flag = true; } break; case 6: res = (CmdResponseToDtuClosePump)ToDtuCommand.GetBaseMessageFromDtuByKey(cmd.AddressField + "-" + cmd.AFN); if (res != null) { SafeSetText(textBox2, Environment.NewLine + OperationType + "成功!" + timeDelay + ",返回结果:" + ((CmdResponseToDtuClosePump)res).Result, true); ToDtuCommand.RemoveBaseMessageFromDtu(cmd.AddressField + "-" + cmd.AFN); flag = true; } break; case 7: res = (CmdResponseToDtuSetStationCode)ToDtuCommand.GetBaseMessageFromDtuByKey(cmd.AddressField + "-" + cmd.AFN); if (res != null) { SafeSetText(textBox2, Environment.NewLine + OperationType + "成功!" + timeDelay + ",返回结果:" + ((CmdResponseToDtuSetStationCode)res).Result, true); ToDtuCommand.RemoveBaseMessageFromDtu(cmd.AddressField + "-" + cmd.AFN); flag = true; } break; case 8: res = (CmdResponseToDtuShieldSerialNumber)ToDtuCommand.GetBaseMessageFromDtuByKey(cmd.AddressField + "-" + cmd.AFN); if (res != null) { SafeSetText(textBox2, Environment.NewLine + OperationType + "成功!" + timeDelay + ",返回结果:" + ((CmdResponseToDtuShieldSerialNumber)res).Result, true); ToDtuCommand.RemoveBaseMessageFromDtu(cmd.AddressField + "-" + cmd.AFN); flag = true; } break; case 9: res = (CmdResponseToDtuShieldSerialNumberCancel)ToDtuCommand.GetBaseMessageFromDtuByKey(cmd.AddressField + "-" + cmd.AFN); if (res != null) { SafeSetText(textBox2, Environment.NewLine + OperationType + "成功!" + timeDelay + ",返回结果:" + ((CmdResponseToDtuShieldSerialNumberCancel)res).Result, true); ToDtuCommand.RemoveBaseMessageFromDtu(cmd.AddressField + "-" + cmd.AFN); flag = true; } break; case 10: res = (CmdResponseToDtuSetGroundWaterParam)ToDtuCommand.GetBaseMessageFromDtuByKey(cmd.AddressField + "-" + cmd.AFN); if (res != null) { SafeSetText(textBox2, Environment.NewLine + OperationType + "成功!" + timeDelay + ",返回结果:" + ((CmdResponseToDtuSetGroundWaterParam)res).Result, true); ToDtuCommand.RemoveBaseMessageFromDtu(cmd.AddressField + "-" + cmd.AFN); flag = true; } break; case 11: res = (CmdResponseToDtuQueryGroundWaterParam)ToDtuCommand.GetBaseMessageFromDtuByKey(cmd.AddressField + "-" + cmd.AFN); if (res != null) { SafeSetText(textBox2, Environment.NewLine + OperationType + "成功!" + timeDelay + ",返回结果:" + ((CmdResponseToDtuQueryGroundWaterParam)res).Range + " | " + ((CmdResponseToDtuQueryGroundWaterParam)res).LineLength, true); SafeSetText(txtRange, ((CmdResponseToDtuQueryGroundWaterParam)res).Range.ToString(), false); SafeSetText(txtLineLength, ((CmdResponseToDtuQueryGroundWaterParam)res).LineLength.ToString(), false); ToDtuCommand.RemoveBaseMessageFromDtu(cmd.AddressField + "-" + cmd.AFN); flag = true; } break; case 12: res = (CmdResponseToDtuQueryGroundWater)ToDtuCommand.GetBaseMessageFromDtuByKey(cmd.AddressField + "-" + cmd.AFN); if (res != null) { SafeSetText(textBox2, Environment.NewLine + OperationType + "成功!" + timeDelay + ",返回结果:" + ((CmdResponseToDtuQueryGroundWater)res).Acq_Time.ToString("yyyy-MM-dd HH:mm:ss") + " | " + ((CmdResponseToDtuQueryGroundWater)res).GroundWaterLevel + " | " + ((CmdResponseToDtuQueryGroundWater)res).LineLength, true); SafeSetText(txtAcq_Time, ((CmdResponseToDtuQueryGroundWater)res).Acq_Time.ToString("yyyy-MM-dd HH:mm:ss"), false); SafeSetText(txtGroundWaterLevel, ((CmdResponseToDtuQueryGroundWater)res).GroundWaterLevel.ToString(), false); SafeSetText(txtLineLength, ((CmdResponseToDtuQueryGroundWater)res).LineLength.ToString(), false); ToDtuCommand.RemoveBaseMessageFromDtu(cmd.AddressField + "-" + cmd.AFN); flag = true; } break; case 13: res = (CmdResponseToDtuQueryState)ToDtuCommand.GetBaseMessageFromDtuByKey(cmd.AddressField + "-" + cmd.AFN); if (res != null) { SafeSetText(textBox2, Environment.NewLine + OperationType + "成功!" + timeDelay + ",返回结果:" + ((CmdResponseToDtuQueryState)res).State + ",上报时间:" + ((CmdResponseToDtuQueryState)res).DateTimeNew.ToString("yyyy-MM-dd HH:mm:ss") + //",累计用电量:" + ((CmdResponseToDtuQueryState)res).ElectricUsed + ",累计用水量:" + ((CmdResponseToDtuQueryState)res).WaterUsed, true); ToDtuCommand.RemoveBaseMessageFromDtu(cmd.AddressField + "-" + cmd.AFN); flag = true; } break; } if (flag) { if (res != null) { SafeSetText(textBox2, Environment.NewLine + "是否带密码:" + (res.IsPW ? "1|" + res.PW : "0") + ",是否带时间戳:" + (res.IsTP ? "1|" + res.TP : "0"), true); } break; } Thread.Sleep(100); timeDelay = timeDelay + 1; } if (!flag) { SafeSetText(textBox2, Environment.NewLine + OperationType + "出错!" + "响应超时", true); } } else { SafeSetText(textBox2, Environment.NewLine + OperationType + "出错!" + "无命令保存", true); } } else { op.State = "终端离线"; SafeSetText(textBox2, Environment.NewLine + OperationType + "出错!" + "终端离线", true); } DeviceOperationModule.AddDeviceOperation(op); } catch (Exception ex) { SafeSetText(textBox2, OperationType + "出错!" + Environment.NewLine + ex.Message, false); } setAllButtonEnable(true); }