/// <summary> /// 读取指定地址的ushort数组 /// </summary> /// <param name="address">起始地址,格式为"1234"</param> /// <param name="length">数组长度</param> /// <returns>带有成功标志的ushort数据</returns> public OperateResult <ushort[]> ReadUInt16(string address, ushort length) { OperateResult <byte[]> read = Read(address, length); if (!read.IsSuccess) { return(OperateResult.CreateFailedResult <ushort[]>(read)); } return(OperateResult.CreateSuccessResult(byteTransform.TransUInt16(read.Content, 0, length))); }
public void BytesToUInt16TransferTest( ) { byte[] data = new byte[4]; BitConverter.GetBytes((ushort)1234).CopyTo(data, 0); BitConverter.GetBytes((ushort)54321).CopyTo(data, 2); data = SoftBasic.BytesReverseByWord(data); ushort[] array = byteTransform.TransUInt16(data, 0, 2); Assert.AreEqual <ushort>(1234, array[0]); Assert.AreEqual <ushort>(54321, array[1]); }