public string ReadMsg(string UserDataAll) { short SerialNumberTmp; DateTime SendTimeTmp; string msg = WaterBaseMessageService.GetSerialNumberAndSendTime(UserDataAll, out SerialNumberTmp, out SendTimeTmp); if (msg == "") { SerialNumber = SerialNumberTmp; SendTime = SendTimeTmp; } else { if (ShowLog) { logHelper.Error(msg); } return(msg); } try { Iden_F1 = new Identifier_F1(); Iden_F1.RemoteStation = UserDataAll.Substring(20, 10); } catch (Exception ex) { if (ShowLog) { logHelper.Error(ex.Message + Environment.NewLine + "获取遥测站出错" + " " + RawDataStr); } return("获取遥测站出错"); } string Remain = UserDataAll.Substring(30); msg = ""; List <Identifier> List_RTUParam = Identifier.analyse(Remain, AFN, out msg); if (msg == "") { if (List_RTUParam.Count == 1) { if (List_RTUParam[0].GetKey() == (byte)Identifier_Standard._45) { Identifier_45 iden = (Identifier_45)List_RTUParam[0]; isUsed = iden.AlarmStateV[32 - (int)AlarmState._10] == '1'; } else { msg = "数据体非法,参数关键字非法"; } } else { msg = "数据体非法,参数超过1个"; } } return(msg); }
public string ReadMsg(string UserDataAll) { short SerialNumberTmp; DateTime SendTimeTmp; string msg = WaterBaseMessageService.GetSerialNumberAndSendTime(UserDataAll, out SerialNumberTmp, out SendTimeTmp); if (msg == "") { SerialNumber = SerialNumberTmp; SendTime = SendTimeTmp; } else { if (ShowLog) { logHelper.Error(msg); } return(msg); } try { Iden_F1 = new Identifier_F1(); Iden_F1.RemoteStation = UserDataAll.Substring(20, 10); } catch (Exception ex) { if (ShowLog) { logHelper.Error(ex.Message + Environment.NewLine + "获取遥测站出错" + " " + RawDataStr); } return("获取遥测站出错"); } try { string Remain = UserDataAll.Substring(30); int count = Convert.ToInt32(Remain.Substring(0, 2), 16); Ps = new bool[count]; string hexStr = Remain.Substring(2, ((count - 1) / 8 + 1) * 2); string binStr = HexStringUtility.HexStringToBinString(hexStr); for (int i = 0; i < binStr.Length; i++) { if (count > binStr.Length - i - 1) { Ps[binStr.Length - i - 1] = binStr[i] == '1'; } } } catch (Exception ex) { if (ShowLog) { logHelper.Error(ex.Message + Environment.NewLine + "获取泵开关状态出错" + " " + RawDataStr); } return("获取泵开关状态出错"); } return(""); }
public string ReadMsg(string UserDataAll) { short SerialNumberTmp; DateTime SendTimeTmp; string msg = WaterBaseMessageService.GetSerialNumberAndSendTime(UserDataAll, out SerialNumberTmp, out SendTimeTmp); if (msg == "") { SerialNumber = SerialNumberTmp; SendTime = SendTimeTmp; } else { if (ShowLog) { logHelper.Error(msg); } return(msg); } try { Iden_F1 = new Identifier_F1(); Iden_F1.RemoteStation = UserDataAll.Substring(20, 10); } catch (Exception ex) { if (ShowLog) { logHelper.Error(ex.Message + Environment.NewLine + "获取遥测站出错" + " " + RawDataStr); } return("获取遥测站出错"); } string Remain = UserDataAll.Substring(30).ToUpper(); msg = ""; List <RTUParam> List_RTUParam = RTUParam.analyse(Remain, AFN, out msg); if (msg == "") { if (List_RTUParam.Count == 1) { if (List_RTUParam[0].GetKey() == (byte)RTUParam.RTUParamKey._03) { newPW = (RTUParam_03)List_RTUParam[0]; } else { msg = "数据体非法,参数1关键字非法"; } } else { msg = "数据体非法,参数不为1个"; } } return(""); }
public string ReadMsg(string UserDataAll) { short SerialNumberTmp; DateTime SendTimeTmp; string msg = WaterBaseMessageService.GetSerialNumberAndSendTime(UserDataAll, out SerialNumberTmp, out SendTimeTmp); if (msg == "") { SerialNumber = SerialNumberTmp; SendTime = SendTimeTmp; } else { if (ShowLog) { logHelper.Error(msg); } return(msg); } try { Iden_F1 = new Identifier_F1(); Iden_F1.RemoteStation = UserDataAll.Substring(20, 10); } catch (Exception ex) { if (ShowLog) { logHelper.Error(ex.Message + Environment.NewLine + "获取遥测站出错" + " " + RawDataStr); } return("获取遥测站出错"); } States = new List <short>(); for (int i = 0; i < stateDec.Length; i++) { if (UserDataAll.Length >= 30 + 4 * (i + 1)) { string s = UserDataAll.Substring(30 + 4 * i, 4); States.Add(Convert.ToInt16(s, 16)); } else { States.Add(0); } } return(""); }
public string ReadMsg(string UserDataAll) { short SerialNumberTmp; DateTime SendTimeTmp; string msg = WaterBaseMessageService.GetSerialNumberAndSendTime(UserDataAll, out SerialNumberTmp, out SendTimeTmp); if (msg == "") { SerialNumber = SerialNumberTmp; SendTime = SendTimeTmp; } else { if (ShowLog) { logHelper.Error(msg); } return(msg); } try { Iden_F1 = new Identifier_F1(); Iden_F1.RemoteStation = UserDataAll.Substring(20, 10); } catch (Exception ex) { if (ShowLog) { logHelper.Error(ex.Message + Environment.NewLine + "获取遥测站出错" + " " + RawDataStr); } return("获取遥测站出错"); } try { VersionL = Convert.ToByte(UserDataAll.Substring(30, 2), 16); VersionC = HexStringUtility.HexStringToStr(UserDataAll.Substring(32, 2 * VersionL)); } catch (Exception ex) { if (ShowLog) { logHelper.Error(ex.Message + Environment.NewLine + "获取版本信息出错" + " " + RawDataStr); } return("获取版本信息出错"); } return(""); }
public string ReadMsg(string UserDataAll) { short SerialNumberTmp; DateTime SendTimeTmp; string msg = WaterBaseMessageService.GetSerialNumberAndSendTime(UserDataAll, out SerialNumberTmp, out SendTimeTmp); if (msg == "") { SerialNumber = SerialNumberTmp; SendTime = SendTimeTmp; } else { if (ShowLog) { logHelper.Error(msg); } return(msg); } try { Iden_F1 = new Identifier_F1(); Iden_F1.RemoteStation = UserDataAll.Substring(20, 10); } catch (Exception ex) { if (ShowLog) { logHelper.Error(ex.Message + Environment.NewLine + "获取遥测站出错" + " " + RawDataStr); } return("获取遥测站出错"); } string Remain = UserDataAll.Substring(30).ToUpper(); msg = ""; List_RTUParam = RTUParam.analyse(Remain, AFN, out msg); return(msg); }
public string ReadMsg(string UserDataAll) { short SerialNumberTmp; DateTime SendTimeTmp; string msg = WaterBaseMessageService.GetSerialNumberAndSendTime(UserDataAll, out SerialNumberTmp, out SendTimeTmp); if (msg == "") { SerialNumber = SerialNumberTmp; SendTime = SendTimeTmp; } else { if (ShowLog) { logHelper.Error(msg); } return(msg); } try { //StationType = Convert.ToByte(UserDataAll.Substring(30, 2), 16); Iden_F1 = new Identifier_F1(); Iden_F1.RemoteStation = UserDataAll.Substring(20, 10); Iden_F1.StationType = Convert.ToByte(UserDataAll.Substring(30, 2), 16); } catch (Exception ex) { if (ShowLog) { logHelper.Error(ex.Message + Environment.NewLine + "获取遥测站出错" + " " + RawDataStr); } return("获取遥测站出错"); } try { //ObsTime = DateTime.ParseExact("20" + UserDataAll.Substring(36, 10) + "00", "yyyyMMddHHmmss", CultureInfo.InvariantCulture); Iden_F0 = new Identifier_F0(); Iden_F0.ObsTime = DateTime.ParseExact("20" + UserDataAll.Substring(36, 10) + "00", "yyyyMMddHHmmss", CultureInfo.InvariantCulture); } catch (Exception ex) { if (ShowLog) { logHelper.Error(ex.Message + Environment.NewLine + "获取观测时间出错" + " " + RawDataStr); } return("获取观测时间出错"); } try { byte key_04 = Convert.ToByte(UserDataAll.Substring(46, 2), 16); if (key_04 != (int)Identifier_Standard._04) { return("获取时间步长码出错"); } string LengthStr_04 = UserDataAll.Substring(48, 2); int[] LS_04 = WaterBaseProtocol.GetLengthList(LengthStr_04); int ByteCount_04 = LS_04[0]; int Digits_04 = LS_04[1]; Iden_04 = new Identifier_04(); Iden_04.SetVal(ByteCount_04, Digits_04, UserDataAll.Substring(50, 6)); } catch (Exception ex) { if (ShowLog) { logHelper.Error(ex.Message + Environment.NewLine + "获取时间步长码出错" + " " + RawDataStr); } return("获取时间步长码出错"); } string Remain = UserDataAll.Substring(56).ToUpper(); if (Remain.Length > 4) { byte Key = Convert.ToByte(Remain.Substring(0, 2), 16); Idens = new List <Identifier>(); if (Key == (byte)Identifier_Standard._FF) { if (Remain.Length > 6) { byte KeySub = Convert.ToByte(Remain.Substring(2, 2), 16); Remain = Remain.Substring(6); if (KeySub == (byte)Identifier_Custom._03) { while (Remain.Length >= 24) { Identifier_FF_03 id = new Identifier_FF_03(); id.SetVal(0, 0, Remain.Substring(0, 24)); Idens.Add(id); Remain = Remain.Substring(24); } } else if (KeySub == (byte)Identifier_Custom._0E) { while (Remain.Length >= 36) { Identifier_FF_0E id = new Identifier_FF_0E(); id.SetVal(0, 0, Remain.Substring(0, 36)); Idens.Add(id); Remain = Remain.Substring(24); } } } } else { string LengthStr = Remain.Substring(2, 2); int[] LS = WaterBaseProtocol.GetLengthList(LengthStr); int ByteCount = LS[0]; int Digits = LS[1]; if (ByteCount > 0) { Remain = Remain.Substring(4); if (Key == (byte)Identifier_Standard._1A) { while (Remain.Length >= ByteCount * 2) { Identifier_1A id = new Identifier_1A(); id.SetVal(ByteCount, Digits, Remain.Substring(0, ByteCount * 2)); Idens.Add(id); Remain = Remain.Substring(ByteCount * 2); } } else if (Key == (byte)Identifier_Standard._1F) { while (Remain.Length >= ByteCount * 2) { Identifier_1F id = new Identifier_1F(); id.SetVal(ByteCount, Digits, Remain.Substring(0, ByteCount * 2)); Idens.Add(id); Remain = Remain.Substring(ByteCount * 2); } } else if (Key == (byte)Identifier_Standard._20) { while (Remain.Length >= ByteCount * 2) { Identifier_20 id = new Identifier_20(); id.SetVal(ByteCount, Digits, Remain.Substring(0, ByteCount * 2)); Idens.Add(id); Remain = Remain.Substring(ByteCount * 2); } } else if (Key == (byte)Identifier_Standard._26) { while (Remain.Length >= ByteCount * 2) { Identifier_26 id = new Identifier_26(); id.SetVal(ByteCount, Digits, Remain.Substring(0, ByteCount * 2)); Idens.Add(id); Remain = Remain.Substring(ByteCount * 2); } } else if (Key == (byte)Identifier_Standard._38) { while (Remain.Length >= ByteCount * 2) { Identifier_38 id = new Identifier_38(); id.SetVal(ByteCount, Digits, Remain.Substring(0, ByteCount * 2)); Idens.Add(id); Remain = Remain.Substring(ByteCount * 2); } } else if (Key == (byte)Identifier_Standard._39) { while (Remain.Length >= ByteCount * 2) { Identifier_39 id = new Identifier_39(); id.SetVal(ByteCount, Digits, Remain.Substring(0, ByteCount * 2)); Idens.Add(id); Remain = Remain.Substring(ByteCount * 2); } } else if (Key == (byte)Identifier_Standard._F4) { while (Remain.Length >= ByteCount * 2) { Identifier_F4 id = new Identifier_F4(); id.SetVal(ByteCount, Digits, Remain.Substring(0, ByteCount * 2)); Idens.Add(id); Remain = Remain.Substring(ByteCount * 2); } } else if (Key == (byte)Identifier_Standard._F5) { while (Remain.Length >= ByteCount * 2) { Identifier_F5 id = new Identifier_F5(); id.SetVal(ByteCount, Digits, Remain.Substring(0, ByteCount * 2)); Idens.Add(id); Remain = Remain.Substring(ByteCount * 2); } } } } } return(""); }
private void button2_Click(object sender, EventArgs e) { byte[] bs = null; FileInfo fileInfo = new FileInfo(this.textBox1.Text); FileStream fs = null; if (fileInfo.Exists) { try { long len = fileInfo.Length; fs = fileInfo.OpenRead(); bs = new byte[len]; fs.Read(bs, 0, (int)len); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { if (fs != null) { fs.Close(); } } } if (bs == null) { MessageBox.Show("图片选择错误!"); } WaterCmd_36_2 cmd = new WaterCmd_36_2(); cmd.CenterStation = f1.GetCenterStation(); cmd.RemoteStation = f1.GetRemoteStation(); cmd.PW = f1.GetPW(); cmd.SerialNumber = f1.GetCount(); cmd.SendTime = DateTime.Now; Identifier_F1 iden_F1 = new Identifier_F1(); iden_F1.RemoteStation = cmd.RemoteStation; iden_F1.StationType = (byte)WaterBaseProtocol.StationType.River; Identifier_F0 iden_F0 = new Identifier_F0(); iden_F0.ObsTime = cmd.SendTime; Identifier_F3 iden_F3 = new Identifier_F3(); iden_F3.ImgContent = bs; cmd.List_Identifier = new List <Identifier>(); cmd.List_Identifier.Add(iden_F1); cmd.List_Identifier.Add(iden_F0); cmd.List_Identifier.Add(iden_F3); string msg = cmd.WriteMsg(); if (msg == "") { MessageBox.Show("命令数量:" + cmd.MsgList.Length); this.textBox2.Text = ""; wbms = cmd.MsgList; Thread t = new Thread(showMsg); t.Start(); } else { MessageBox.Show(msg); } }