public void BytesToDoubleTransferTest( ) { byte[] data = new byte[16]; ReverseBytesByWord(BitConverter.GetBytes(123.456789D), byteTransform.DataFormat).CopyTo(data, 0); ReverseBytesByWord(BitConverter.GetBytes(-0.00000123D), byteTransform.DataFormat).CopyTo(data, 8); double[] array = byteTransform.TransDouble(data, 0, 2); Assert.AreEqual <double>(123.456789D, array[0]); Assert.AreEqual <double>(-0.00000123D, array[1]); }
/// <summary> /// 读取指定地址的double数组 /// </summary> /// <param name="address">起始地址,格式为"1234"</param> /// <param name="length">数组长度</param> /// <returns>带有成功标志的double数据</returns> public OperateResult <double[]> ReadDouble(string address, ushort length) { OperateResult <byte[]> read = Read(address, (ushort)(length * 4)); if (!read.IsSuccess) { return(OperateResult.CreateFailedResult <double[]>(read)); } return(OperateResult.CreateSuccessResult(byteTransform.TransDouble(read.Content, 0, length))); }