/// <summary> /// 取得当个信息地址的值,字符串表示 /// </summary> /// <param name="valuestr"></param> /// <param name="infounitAddress"></param> /// <param name="bytetype"></param> /// <returns></returns> private static string getValue(string valuestr, InfoUnitAddress infounitAddress, int bytetype) { double value = (double)SystemCode.HexNumberToDenary(valuestr, infounitAddress.reversionType, bytetype, infounitAddress.signtype); if (infounitAddress.dotnum > 0) { value = Math.Round(value / Math.Pow(10, infounitAddress.dotnum), 1); } return(value.ToString()); }
/// <summary> /// 解析单个信息体 /// </summary> /// <param name="body"></param> /// <returns></returns> public static string[] analyze(string body, int infoType, InfoUnitAddress infounitAddress) { string valuestr = "", value = ""; switch (infoType) { case DataType.yaoce: valuestr = body.Substring(3 * 2, 4 * 2); value = getValue(valuestr, infounitAddress, 32); break; case DataType.yaoxin: //对于遥信的信息体,放回值和时间 valuestr = body.Substring(3 * 2, 1 * 2); value = getValue(valuestr, infounitAddress, 8); //再取得故障时间 valuestr = body.Substring(5 * 2, 7 * 2); int year = 2000 + (int)SystemCode.HexNumberToDenary(valuestr.Substring(12, 2), false, 8, 'u') % 99; int moth = (int)SystemCode.HexNumberToDenary(valuestr.Substring(10, 2), false, 8, 'u'); if (moth > 12) { moth = 12; } int day = (int)SystemCode.HexNumberToDenary(valuestr.Substring(8, 2), false, 8, 'u'); if (day > 31) { day = 28; } int hh = (int)SystemCode.HexNumberToDenary(valuestr.Substring(6, 2), false, 8, 'u'); if (hh > 23) { hh = 23; } int mm = (int)SystemCode.HexNumberToDenary(valuestr.Substring(4, 2), false, 8, 'u'); if (mm > 60) { mm = 59; } int ss = (int)SystemCode.HexNumberToDenary(valuestr.Substring(2, 2), false, 8, 'u'); if (ss > 60) { ss = 59; } value += ":" + new DateTime(year, moth, day, hh, mm, ss).ToString("yyyy-mm-dd HH:mm:ss"); break; case DataType.yaomai: valuestr = body.Substring(3 * 2, 4 * 2); value = getValue(valuestr, infounitAddress, 32); break; default: break; } return((infounitAddress.address + ":" + value).Split(':')); }
/// <summary> /// 解析单个信息体 /// </summary> /// <param name="body"></param> /// <returns></returns> public static string[] analyze(string body, int infoType, InfoUnitAddress infounitAddress) { string valuestr = "",value=""; switch (infoType) { case DataType.yaoce: valuestr = body.Substring(3 * 2, 4 * 2); value = getValue(valuestr, infounitAddress, 32); break; case DataType.yaoxin://对于遥信的信息体,放回值和时间 valuestr = body.Substring(3 * 2, 1 * 2); value = getValue(valuestr, infounitAddress, 8); //再取得故障时间 valuestr = body.Substring(5 * 2, 7 * 2); int year = 2000 + (int)SystemCode.HexNumberToDenary(valuestr.Substring(12, 2), false, 8, 'u') % 99; int moth = (int)SystemCode.HexNumberToDenary(valuestr.Substring(10, 2), false, 8, 'u'); if (moth > 12) moth = 12; int day = (int)SystemCode.HexNumberToDenary(valuestr.Substring(8, 2), false, 8, 'u'); if (day > 31) day = 28; int hh = (int)SystemCode.HexNumberToDenary(valuestr.Substring(6, 2), false, 8, 'u'); if (hh > 23) hh = 23; int mm = (int)SystemCode.HexNumberToDenary(valuestr.Substring(4, 2), false, 8, 'u'); if (mm > 60) mm = 59; int ss = (int)SystemCode.HexNumberToDenary(valuestr.Substring(2, 2), false, 8, 'u'); if (ss > 60) ss = 59; value+=":"+new DateTime(year, moth, day, hh, mm, ss).ToString("yyyy-mm-dd HH:mm:ss"); break; case DataType.yaomai: valuestr = body.Substring(3 * 2, 4 * 2); value = getValue(valuestr, infounitAddress, 32); break; default: break; } return (infounitAddress.address + ":" + value).Split(':'); }
/// <summary> /// 取得当个信息地址的值,字符串表示 /// </summary> /// <param name="valuestr"></param> /// <param name="infounitAddress"></param> /// <param name="bytetype"></param> /// <returns></returns> private static string getValue(string valuestr, InfoUnitAddress infounitAddress,int bytetype) { double value = (double)SystemCode.HexNumberToDenary(valuestr, infounitAddress.reversionType, bytetype, infounitAddress.signtype); if(infounitAddress.dotnum>0){ value = Math.Round(value /Math.Pow(10,infounitAddress.dotnum), 1); } return value.ToString(); }