/// <summary> /// 未考虑数组的情况,用于解析帧 /// </summary> /// <param name="src">根据操作单元查字典把字节数组翻译为相应的数据类型</param> /// <param name="unit">操作单元</param> /// <returns></returns> public static object GetValue(byte[] src, ushort unit) { object temp; switch (MyDictionary.unittypedict[unit]) { //uchar case 0: { temp = src[0]; } break; //ushort case 1: { temp = ByteStruct.BytesToStruct(src, typeof(ushort)); } break; //float case 2: { temp = ByteStruct.BytesToStruct(src, typeof(float)); } break; //datetime case 3: { long _temp = (long)ByteStruct.BytesToStruct(src, typeof(long)); temp = TimerTick.TimeSpanToDate(_temp); } break; //char[] case 4: { char[] _temp = new char[src.Length]; for (int i = 0; i < src.Length; i++) { _temp[i] = (char)src[i]; } temp = _temp; break; } //ushort[2]==EraseRange case 5: { temp = (Define.EraseRange)ByteStruct.BytesToStruct(src, typeof(Define.EraseRange)); break; } //ushort[4]==GasFixPara_A case 6: { temp = (Define.GasFixPara_A)ByteStruct.BytesToStruct(src, typeof(Define.GasFixPara_A)); break; } //ushort[4]==GasFixPara_B case 7: { temp = (Define.GasFixPara_B)ByteStruct.BytesToStruct(src, typeof(Define.GasFixPara_B)); break; } //float[2]==EnvironmentSetting case 8: { temp = (Define.EnvironmentSetting)ByteStruct.BytesToStruct(src, typeof(Define.EnvironmentSetting)); break; } //float[3]==H2OAnlyParam_AW case 9: { temp = (Define.H2OAnlyParam_AW)ByteStruct.BytesToStruct(src, typeof(Define.H2OAnlyParam_AW)); break; } //float[3]==H2OAnlyParam_T case 10: { temp = (Define.H2OAnlyParam_T)ByteStruct.BytesToStruct(src, typeof(Define.H2OAnlyParam_T)); break; } //float[5]==GasFixParameters case 11: { temp = (Define.GasFixParameters)ByteStruct.BytesToStruct(src, typeof(Define.GasFixParameters)); break; } default: //MessageBox.Show("readunit-getdata:这里只做系统类型的处理,自定义类型暂未考虑"); temp = null; break; } return(temp); }