/// <summary> /// 读取线性化参数 /// </summary> public LinearizationItem ReadLinearizationItem(long longAddress, byte para) { LinearizationItem ret = null; RequestPacket request = new RequestPacket() { LongOrShort = 1, Address = longAddress, Command = 0xC0, DataContent = new byte[] { para } }; ResponsePacket response = Request(request); if (response != null && response.DataContent != null && response.DataContent.Length >= 10) { byte[] d = response.DataContent; ret = new LinearizationItem(); ret.SensorValue = BitConverter.ToSingle(new byte[] { d[9], d[8], d[7], d[6] }, 0); ret.SensorAD = BitConverter.ToSingle(new byte[] { d[4], d[3], d[2], d[1] }, 0); } return(ret); }
public static void FillHeaderAndTail(List <LinearizationItem> lis) { int minAD = 0; int maxAD = 70000; float k = (lis[lis.Count - 1].SensorValue - lis[0].SensorValue) / (lis[lis.Count - 1].SensorAD - lis[0].SensorAD); //计算斜率 LinearizationItem header = new LinearizationItem(); header.SensorAD = minAD; header.SensorValue = lis[0].SensorValue - k * (lis[0].SensorAD - minAD); lis.Insert(0, header); LinearizationItem tail = new LinearizationItem(); tail.SensorAD = maxAD; tail.SensorValue = lis[lis.Count - 1].SensorValue + k * (maxAD - lis[lis.Count - 1].SensorAD); lis.Add(tail); if (lis.Count % 2 == 1) { lis.Add(tail); //凑成偶数,因为下发时两个两个下发 } }