public void BytesToInt32TransferTest( )
        {
            byte[] data = new byte[8];
            ReverseBytesByWord(BitConverter.GetBytes(12345678), byteTransform.DataFormat).CopyTo(data, 0);
            ReverseBytesByWord(BitConverter.GetBytes(-9876654), byteTransform.DataFormat).CopyTo(data, 4);

            int[] array = byteTransform.TransInt32(data, 0, 2);
            Assert.AreEqual <int>(12345678, array[0]);
            Assert.AreEqual <int>(-9876654, array[1]);
        }
Esempio n. 2
0
        /// <summary>
        /// 读取指定地址的int数组
        /// </summary>
        /// <param name="address">起始地址,格式为"1234"</param>
        /// <param name="length">数组的长度</param>
        /// <returns>带有成功标志的int数据</returns>
        public OperateResult <int[]> ReadInt32(string address, ushort length)
        {
            OperateResult <byte[]> read = Read(address, (ushort)(length * 2));

            if (!read.IsSuccess)
            {
                return(OperateResult.CreateFailedResult <int[]>(read));
            }
            return(OperateResult.CreateSuccessResult(byteTransform.TransInt32(read.Content, 0, length)));
        }