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