public override void SetVal(int ByteCount, int Digits, string hexStr) { if (ByteCount != 0 && Digits != 0) { this.Length = Convert.ToByte(WaterBaseProtocol.GetLengthHexStr(ByteCount, Digits), 16); } }
public override void SetVal(int ByteCount, int Digits, string hexStr) { if (ByteCount <= 0 && Digits <= 0) { ByteCount = 3; Digits = 0; } this.Length = Convert.ToByte(WaterBaseProtocol.GetLengthHexStr(ByteCount, Digits), 16); try { this.dd = Convert.ToInt32(hexStr.Substring(0, 2)); } catch { this.dd = 0; } try { this.HH = Convert.ToInt32(hexStr.Substring(2, 2)); } catch { this.HH = 0; } try { this.mm = Convert.ToInt32(hexStr.Substring(4, 2)); } catch { this.mm = 0; } }
public override string GetHexStr() { StringBuilder builderC = new StringBuilder(); for (int i = 0; i < 4; i++) { if (CenterStations.Length > i) { if (CenterStations[i] > 0 && CenterStations[i] <= 255) { builderC.Append(CenterStations[i].ToString("X").PadLeft(2, '0')); } else { builderC.Append("00"); } } } StringBuilder builder = new StringBuilder(); builder.Append(Key.ToString("X").PadLeft(2, '0')); Length = Convert.ToByte(WaterBaseProtocol.GetLengthHexStr(builderC.ToString().Length / 2, 0), 16); builder.Append(Length.ToString("X").PadLeft(2, '0')); builder.Append(builderC.ToString()); return(builder.ToString()); }
public override string GetHexStr() { if (!Ampere.HasValue) { return(""); } try { int ByteCount = 2; int Digits = 1; if ((double)Ampere.Value * Math.Pow(10, Digits) >= Math.Pow(10, ByteCount * 2)) { return(""); } StringBuilder builderC = new StringBuilder(); builderC.Append(((double)Ampere.Value * Math.Pow(10, Digits)).ToString().PadLeft(ByteCount * 2, '0')); StringBuilder builder = new StringBuilder(); builder.Append(Key.ToString("X").PadLeft(2, '0')); Length = Convert.ToByte(WaterBaseProtocol.GetLengthHexStr(ByteCount, Digits), 16); builder.Append(Length.ToString("X").PadLeft(2, '0')); builder.Append(builderC.ToString()); return(builder.ToString()); } catch { return(""); } }
public override void SetVal(int ByteCount, int Digits, string hexStr) { if (ByteCount <= 0 && Digits <= 0) { ByteCount = 4; Digits = 0; } this.Length = Convert.ToByte(WaterBaseProtocol.GetLengthHexStr(ByteCount, Digits), 16); this.AlarmStateV = HexStringUtility.HexStringToBinString(hexStr).PadLeft(32, '0'); }
public override string GetHexStr() { StringBuilder builderC = new StringBuilder(); builderC.Append(HexStringUtility.StrToHexString(SimNoTypeV.ToString())); builderC.Append(HexStringUtility.StrToHexString(SimNo)); StringBuilder builder = new StringBuilder(); builder.Append(Key.ToString("X").PadLeft(2, '0')); Length = Convert.ToByte(WaterBaseProtocol.GetLengthHexStr(builderC.ToString().Length / 2, 0), 16); builder.Append(Length.ToString("X").PadLeft(2, '0')); builder.Append(builderC.ToString()); return(builder.ToString()); }
public override string GetHexStr() { StringBuilder builderC = new StringBuilder(); if (HexStr.Length % 2 == 1) { builderC.Append("0"); } builderC.Append(HexStr); StringBuilder builder = new StringBuilder(); builder.Append(Key.ToString("X").PadLeft(2, '0')); Length = Convert.ToByte(WaterBaseProtocol.GetLengthHexStr(builderC.ToString().Length / 2, 0), 16); builder.Append(Length.ToString("X").PadLeft(2, '0')); builder.Append(builderC.ToString()); return(builder.ToString()); }
public override string GetHexStr() { //if (!Enum.IsDefined(typeof(ChannelType), ChannelTypeV)) // return ""; StringBuilder builderC = new StringBuilder(); if (Enum.IsDefined(typeof(ChannelType), ChannelTypeV)) { builderC.Append(ChannelTypeV.ToString("X").PadLeft(2, '0')); if (ChannelTypeV == (int)ChannelType._02) { string[] ips = IP.Split('.'); for (int i = 0; i < 4; i++) { if (ips.Length > i) { builderC.Append(ips[i].PadLeft(3, '0')); } else { builderC.Append("000"); } } builderC.Append(Port.ToString().PadLeft(6, '0')); } else { if (Add.Length % 2 == 1) { builderC.Append("0"); } builderC.Append(Add); } } StringBuilder builder = new StringBuilder(); builder.Append(Key.ToString("X").PadLeft(2, '0')); Length = Convert.ToByte(WaterBaseProtocol.GetLengthHexStr(builderC.ToString().Length / 2, 0), 16); builder.Append(Length.ToString("X").PadLeft(2, '0')); builder.Append(builderC.ToString()); return(builder.ToString()); }
public override string GetHexStr() { if (!Enum.IsDefined(typeof(WorkType), WorkTypeV)) { return(""); } StringBuilder builderC = new StringBuilder(); builderC.Append(WorkTypeV.ToString("X").PadLeft(2, '0')); StringBuilder builder = new StringBuilder(); builder.Append(Key.ToString("X").PadLeft(2, '0')); Length = Convert.ToByte(WaterBaseProtocol.GetLengthHexStr(builderC.ToString().Length / 2, 0), 16); builder.Append(Length.ToString("X").PadLeft(2, '0')); builder.Append(builderC.ToString()); return(builder.ToString()); }
public override string GetHexStr() { if (!Val.HasValue || (Val < 0 || Val > 9999)) { return(""); } StringBuilder builderC = new StringBuilder(); builderC.Append(Val.Value.ToString().PadLeft(4, '0')); StringBuilder builder = new StringBuilder(); builder.Append(Key.ToString("X").PadLeft(2, '0')); Length = Convert.ToByte(WaterBaseProtocol.GetLengthHexStr(builderC.ToString().Length / 2, 0), 16); builder.Append(Length.ToString("X").PadLeft(2, '0')); builder.Append(builderC.ToString()); return(builder.ToString()); }
public override void SetVal(int ByteCount, int Digits, string hexStr) { if (ByteCount <= 0 && Digits <= 0) { ByteCount = 2; Digits = 2; } this.Length = Convert.ToByte(WaterBaseProtocol.GetLengthHexStr(ByteCount, Digits), 16); try { this.Val = (decimal)(Convert.ToInt32(hexStr) * 1.0 / Math.Pow(10, Digits)); } catch { this.Val = null; } }
public override string GetHexStr() { StringBuilder builderC = new StringBuilder(); if (RemoteStation.Length <= 10) { builderC.Append(RemoteStation.PadLeft(10, '0')); } else { builderC.Append(RemoteStation.Substring(0, 10)); } StringBuilder builder = new StringBuilder(); builder.Append(Key.ToString("X").PadLeft(2, '0')); Length = Convert.ToByte(WaterBaseProtocol.GetLengthHexStr(builderC.ToString().Length / 2, 0), 16); builder.Append(Length.ToString("X").PadLeft(2, '0')); builder.Append(builderC.ToString()); return(builder.ToString()); }
public override string GetHexStr() { StringBuilder builderC = new StringBuilder(); if (BitStr.Length <= 64) { builderC.Append(HexStringUtility.BinStringToHexString(BitStr.PadLeft(64, '0'))); } else { builderC.Append(HexStringUtility.BinStringToHexString(BitStr.Substring(0, 64))); } StringBuilder builder = new StringBuilder(); builder.Append(Key.ToString("X").PadLeft(2, '0')); Length = Convert.ToByte(WaterBaseProtocol.GetLengthHexStr(builderC.ToString().Length / 2, 0), 16); builder.Append(Length.ToString("X").PadLeft(2, '0')); builder.Append(builderC.ToString()); return(builder.ToString()); }
public override string GetHexStr() { StringBuilder builderC = new StringBuilder(); if (Password.Length <= 4) { builderC.Append(Password.PadLeft(4, '0')); } else { builderC.Append(Password.Substring(0, 4)); } StringBuilder builder = new StringBuilder(); builder.Append(Key.ToString("X").PadLeft(2, '0')); Length = Convert.ToByte(WaterBaseProtocol.GetLengthHexStr(builderC.ToString().Length / 2, 0), 16); builder.Append(Length.ToString("X").PadLeft(2, '0')); builder.Append(builderC.ToString()); return(builder.ToString()); }
public override string GetHexStr() { try { int ByteCount = 3; int Digits = 0; StringBuilder builderC = new StringBuilder(); builderC.Append(dd.ToString().PadLeft(2, '0')); builderC.Append(HH.ToString().PadLeft(2, '0')); builderC.Append(mm.ToString().PadLeft(2, '0')); StringBuilder builder = new StringBuilder(); builder.Append(Key.ToString("X").PadLeft(2, '0')); Length = Convert.ToByte(WaterBaseProtocol.GetLengthHexStr(ByteCount, Digits), 16); builder.Append(Length.ToString("X").PadLeft(2, '0')); builder.Append(builderC.ToString()); return(builder.ToString()); } catch { return(""); } }
public override string GetHexStr() { int ByteCount = 4; int Digits = 0; StringBuilder builderC = new StringBuilder(); if (AlarmStateV.Length <= 32) { builderC.Append(HexStringUtility.BinStringToHexString(AlarmStateV).PadLeft(8, '0')); } else { builderC.Append(HexStringUtility.BinStringToHexString(AlarmStateV).Substring(0, 8)); } StringBuilder builder = new StringBuilder(); builder.Append(Key.ToString("X").PadLeft(2, '0')); Length = Convert.ToByte(WaterBaseProtocol.GetLengthHexStr(ByteCount, Digits), 16); builder.Append(Length.ToString("X").PadLeft(2, '0')); builder.Append(builderC.ToString()); return(builder.ToString()); }
public static List <RTUParam> analyse2(string Remain, out string msg) { List <RTUParam> List_RTUParam = new List <RTUParam>(); try { while (Remain.Length >= 4) { byte Key = Convert.ToByte(Remain.Substring(0, 2), 16); string LengthStr = Remain.Substring(2, 2); byte Length = Convert.ToByte(LengthStr, 16); int[] LS = WaterBaseProtocol.GetLengthList(LengthStr); int ByteCount = LS[0]; int Digits = LS[1]; RTUParam rp; if (Key == (byte)RTUParamKey._01) { rp = new RTUParam_01(); } else if (Key == (byte)RTUParamKey._02) { rp = new RTUParam_02(); } else if (Key == (byte)RTUParamKey._03) { rp = new RTUParam_03(); } else if (Key == (byte)RTUParamKey._04) { rp = new RTUParam_04(); } else if (Key == (byte)RTUParamKey._05) { rp = new RTUParam_05(); } else if (Key == (byte)RTUParamKey._06) { rp = new RTUParam_06(); } else if (Key == (byte)RTUParamKey._07) { rp = new RTUParam_07(); } else if (Key == (byte)RTUParamKey._08) { rp = new RTUParam_08(); } else if (Key == (byte)RTUParamKey._09) { rp = new RTUParam_09(); } else if (Key == (byte)RTUParamKey._0A) { rp = new RTUParam_0A(); } else if (Key == (byte)RTUParamKey._0B) { rp = new RTUParam_0B(); } else if (Key == (byte)RTUParamKey._0C) { rp = new RTUParam_0C(); } else if (Key == (byte)RTUParamKey._0D) { rp = new RTUParam_0D(); } else if (Key == (byte)RTUParamKey._0E) { rp = new RTUParam_0E(); } else if (Key == (byte)RTUParamKey._0F) { rp = new RTUParam_0F(); } else if (Key == (byte)RTUParamKey._20) { rp = new RTUParam_20(); } else if (Key == (byte)RTUParamKey._21) { rp = new RTUParam_21(); } else if (Key == (byte)RTUParamKey._22) { rp = new RTUParam_22(); } else if (Key == (byte)RTUParamKey._23) { rp = new RTUParam_23(); } else if (Key == (byte)RTUParamKey._24) { rp = new RTUParam_24(); } else if (Key == (byte)RTUParamKey._25) { rp = new RTUParam_25(); } else if (Key == (byte)RTUParamKey._26) { rp = new RTUParam_26(); } else if (Key == (byte)RTUParamKey._27) { rp = new RTUParam_27(); } else if (Key == (byte)RTUParamKey._28) { rp = new RTUParam_28(); } else if (Key == (byte)RTUParamKey._29) { rp = new RTUParam_29(); } else if (Key == (byte)RTUParamKey._2A) { rp = new RTUParam_2A(); } else if (Key == (byte)RTUParamKey._2B) { rp = new RTUParam_2B(); } else if (Key == (byte)RTUParamKey._2C) { rp = new RTUParam_2C(); } else if (Key == (byte)RTUParamKey._2D) { rp = new RTUParam_2D(); } else if (Key == (byte)RTUParamKey._2E) { rp = new RTUParam_2E(); } else if (Key == (byte)RTUParamKey._2F) { rp = new RTUParam_2F(); } else if (Key == (byte)RTUParamKey._30) { rp = new RTUParam_30(); } else if (Key == (byte)RTUParamKey._31) { rp = new RTUParam_31(); } else if (Key == (byte)RTUParamKey._32) { rp = new RTUParam_32(); } else if (Key == (byte)RTUParamKey._33) { rp = new RTUParam_33(); } else if (Key == (byte)RTUParamKey._34) { rp = new RTUParam_34(); } else if (Key == (byte)RTUParamKey._35) { rp = new RTUParam_35(); } else if (Key == (byte)RTUParamKey._36) { rp = new RTUParam_36(); } else if (Key == (byte)RTUParamKey._37) { rp = new RTUParam_37(); } else if (Key == (byte)RTUParamKey._38) { rp = new RTUParam_38(); } else if (Key == (byte)RTUParamKey._39) { rp = new RTUParam_39(); } else if (Key == (byte)RTUParamKey._3A) { rp = new RTUParam_3A(); } else if (Key == (byte)RTUParamKey._3B) { rp = new RTUParam_3B(); } else if (Key == (byte)RTUParamKey._3C) { rp = new RTUParam_3C(); } else if (Key == (byte)RTUParamKey._3D) { rp = new RTUParam_3D(); } else if (Key == (byte)RTUParamKey._3E) { rp = new RTUParam_3E(); } else if (Key == (byte)RTUParamKey._3F) { rp = new RTUParam_3F(); } else if (Key == (byte)RTUParamKey._40) { rp = new RTUParam_40(); } else if (Key == (byte)RTUParamKey._41) { rp = new RTUParam_41(); } else if (Key == (byte)RTUParamKey._97) { rp = new RTUParam_97(); } else if (Key == (byte)RTUParamKey._98) { rp = new RTUParam_98(); } else { rp = new RTUParam_00(Key); } List_RTUParam.Add(rp); Remain = Remain.Substring(4); } msg = ""; return(List_RTUParam); } catch (Exception ex) { msg = ex.Message; return(null); } }
public static List <Identifier> analyse(string Remain, byte AFN, out string msg) { List <Identifier> List_Identifier = new List <Identifier>(); try { while (Remain.Length >= 4) { byte Key = Convert.ToByte(Remain.Substring(0, 2), 16); string LengthStr = Remain.Substring(2, 2); byte Length = Convert.ToByte(LengthStr, 16); if (Key == (byte)Identifier_Standard._FF) { byte IdentifierSub = Convert.ToByte(Remain.Substring(2, 2), 16); if (IdentifierSub == (byte)Identifier_Custom._03) { if (Remain.Length < 30) { msg = "长度不足,无法获取日水温" + " " + Remain; return(null); } Identifier_FF_03 iden = new Identifier_FF_03(); iden.SetVal(0, 0, Remain.Substring(6, 24)); List_Identifier.Add(iden); Remain = Remain.Substring(30); } else if (IdentifierSub == (byte)Identifier_Custom._0E) { if (Remain.Length < 42) { msg = "长度不足,无法获取日埋深" + " " + Remain; return(null); } Identifier_FF_0E iden = new Identifier_FF_0E(); iden.SetVal(0, 0, Remain.Substring(6, 36)); List_Identifier.Add(iden); Remain = Remain.Substring(42); } else { msg = "非法自定义标识符" + IdentifierSub + "" + " " + Remain; return(null); } } else if (Key == (byte)Identifier_Standard._F0) { int ByteCount = 5; if (Remain.Length < 2 + 2 + ByteCount * 2) { msg = "长度不足,无法获取标识符" + Key + "数据" + " " + Remain; return(null); } Identifier_F0 iden = new Identifier_F0(); iden.SetVal(0, 0, Remain.Substring(4, 10)); List_Identifier.Add(iden); Remain = Remain.Substring(2 + 2 + ByteCount * 2); } else if (Key == (byte)Identifier_Standard._F1) { int ByteCount = 5; if (Enum.IsDefined(typeof(Identifier_F1.HaveKey), (int)AFN)) { ByteCount = 6; } if (Remain.Length < 2 + 2 + ByteCount * 2) { msg = "长度不足,无法获取标识符" + Key + "数据" + " " + Remain; return(null); } Identifier_F1 iden = new Identifier_F1(); iden.SetVal(0, 0, Remain.Substring(4, ByteCount * 2)); List_Identifier.Add(iden); Remain = Remain.Substring(2 + 2 + ByteCount * 2); } else if (Key == (byte)Identifier_Standard._F2) { Identifier_F2 iden = new Identifier_F2(); iden.SetVal(0, 0, Remain.Substring(4)); List_Identifier.Add(iden); msg = ""; return(List_Identifier); } else if (Key == (byte)Identifier_Standard._F3) { Identifier_F3 iden = new Identifier_F3(); iden.SetVal(0, 0, Remain.Substring(4)); List_Identifier.Add(iden); msg = ""; return(List_Identifier); } else if (Key == (byte)Identifier_Standard._F4) { int ByteCount = 12; if (Remain.Length < 2 + 2 + ByteCount * 2) { msg = "长度不足,无法获取标识符" + Key + "数据" + " " + Remain; return(null); } string ValStr = Remain.Substring(4, ByteCount * 2); Identifier_F4 iden = new Identifier_F4(); iden.SetVal(0, 0, ValStr); List_Identifier.Add(iden); Remain = Remain.Substring(2 + 2 + ByteCount * 2); } else if (Key == (byte)Identifier_Standard._F5) { int ByteCount = 24; if (Remain.Length < 2 + 2 + ByteCount * 2) { msg = "长度不足,无法获取标识符" + Key + "数据" + " " + Remain; return(null); } string ValStr = Remain.Substring(4, ByteCount * 2); Identifier_F5 iden = new Identifier_F5(); iden.SetVal(0, 0, ValStr); List_Identifier.Add(iden); Remain = Remain.Substring(2 + 2 + ByteCount * 2); } else if (Key == (byte)Identifier_Standard._F6) { int ByteCount = 24; if (Remain.Length < 2 + 2 + ByteCount * 2) { msg = "长度不足,无法获取标识符" + Key + "数据" + " " + Remain; return(null); } string ValStr = Remain.Substring(4, ByteCount * 2); Identifier_F6 iden = new Identifier_F6(); iden.SetVal(0, 0, ValStr); List_Identifier.Add(iden); Remain = Remain.Substring(2 + 2 + ByteCount * 2); } else if (Key == (byte)Identifier_Standard._F7) { int ByteCount = 24; if (Remain.Length < 2 + 2 + ByteCount * 2) { msg = "长度不足,无法获取标识符" + Key + "数据" + " " + Remain; return(null); } string ValStr = Remain.Substring(4, ByteCount * 2); Identifier_F7 iden = new Identifier_F7(); iden.SetVal(0, 0, ValStr); List_Identifier.Add(iden); Remain = Remain.Substring(2 + 2 + ByteCount * 2); } else if (Key == (byte)Identifier_Standard._F8) { int ByteCount = 24; if (Remain.Length < 2 + 2 + ByteCount * 2) { msg = "长度不足,无法获取标识符" + Key + "数据" + " " + Remain; return(null); } string ValStr = Remain.Substring(4, ByteCount * 2); Identifier_F8 iden = new Identifier_F8(); iden.SetVal(0, 0, ValStr); List_Identifier.Add(iden); Remain = Remain.Substring(2 + 2 + ByteCount * 2); } else if (Key == (byte)Identifier_Standard._F9) { int ByteCount = 24; if (Remain.Length < 2 + 2 + ByteCount * 2) { msg = "长度不足,无法获取标识符" + Key + "数据" + " " + Remain; return(null); } string ValStr = Remain.Substring(4, ByteCount * 2); Identifier_F9 iden = new Identifier_F9(); iden.SetVal(0, 0, ValStr); List_Identifier.Add(iden); Remain = Remain.Substring(2 + 2 + ByteCount * 2); } else if (Key == (byte)Identifier_Standard._FA) { int ByteCount = 24; if (Remain.Length < 2 + 2 + ByteCount * 2) { msg = "长度不足,无法获取标识符" + Key + "数据" + " " + Remain; return(null); } string ValStr = Remain.Substring(4, ByteCount * 2); Identifier_FA iden = new Identifier_FA(); iden.SetVal(0, 0, ValStr); List_Identifier.Add(iden); Remain = Remain.Substring(2 + 2 + ByteCount * 2); } else if (Key == (byte)Identifier_Standard._FB) { int ByteCount = 24; if (Remain.Length < 2 + 2 + ByteCount * 2) { msg = "长度不足,无法获取标识符" + Key + "数据" + " " + Remain; return(null); } string ValStr = Remain.Substring(4, ByteCount * 2); Identifier_FB iden = new Identifier_FB(); iden.SetVal(0, 0, ValStr); List_Identifier.Add(iden); Remain = Remain.Substring(2 + 2 + ByteCount * 2); } else if (Key == (byte)Identifier_Standard._FC) { int ByteCount = 24; if (Remain.Length < 2 + 2 + ByteCount * 2) { msg = "长度不足,无法获取标识符" + Key + "数据" + " " + Remain; return(null); } string ValStr = Remain.Substring(4, ByteCount * 2); Identifier_FC iden = new Identifier_FC(); iden.SetVal(0, 0, ValStr); List_Identifier.Add(iden); Remain = Remain.Substring(2 + 2 + ByteCount * 2); } else if (Key == (byte)Identifier_Standard._FD) { Identifier_FD iden = new Identifier_FD(); iden.SetVal(0, 0, Remain.Substring(4)); List_Identifier.Add(iden); msg = ""; return(List_Identifier); } else { int[] LS = WaterBaseProtocol.GetLengthList(LengthStr); int ByteCount = LS[0]; int Digits = LS[1]; if (Remain.Length < 2 + 2 + ByteCount * 2) { msg = "长度不足,无法获取标识符" + Key + "数据" + " " + Remain; return(null); } string ValStr = Remain.Substring(4, ByteCount * 2); Identifier iden; if (Key == (byte)Identifier_Standard._03) { iden = new Identifier_03(); } else if (Key == (byte)Identifier_Standard._04) { iden = new Identifier_04(); } else if (Key == (byte)Identifier_Standard._0E) { iden = new Identifier_0E(); } else if (Key == (byte)Identifier_Standard._1A) { iden = new Identifier_1A(); } else if (Key == (byte)Identifier_Standard._1F) { iden = new Identifier_1F(); } else if (Key == (byte)Identifier_Standard._20) { iden = new Identifier_20(); } else if (Key == (byte)Identifier_Standard._26) { iden = new Identifier_26(); } else if (Key == (byte)Identifier_Standard._38) { iden = new Identifier_38(); } else if (Key == (byte)Identifier_Standard._39) { iden = new Identifier_39(); } else if (Key == (byte)Identifier_Standard._45) { iden = new Identifier_45(); } else if (Key == (byte)Identifier_Standard._70) { iden = new Identifier_70(); } else if (Key == (byte)Identifier_Standard._71) { iden = new Identifier_71(); } else if (Key == (byte)Identifier_Standard._72) { iden = new Identifier_72(); } else if (Key == (byte)Identifier_Standard._73) { iden = new Identifier_73(); } else if (Key == (byte)Identifier_Standard._74) { iden = new Identifier_74(); } else if (Key == (byte)Identifier_Standard._75) { iden = new Identifier_75(); } else { iden = new Identifier_00(Key); } iden.SetVal(ByteCount, Digits, ValStr); List_Identifier.Add(iden); Remain = Remain.Substring(2 + 2 + ByteCount * 2); } } msg = ""; return(List_Identifier); } catch (Exception ex) { msg = ex.Message; return(null); } }