public void NetCoreBitConverterToInt16ReturnsFalseOnInvalidSpanSize()
        {
            // Arrange
            var array = new byte[1];

            // Act/Assert
            Assert.False(NetCoreBitConverter.TryWriteBytes(array, short.MaxValue));
        }
Esempio n. 2
0
        public override void WriteTo(Memory <byte> buffer)
        {
            base.WriteTo(buffer);

            var bufferSpan = buffer.Span;

            NetCoreBitConverter.TryWriteBytes(bufferSpan.Slice(1, 2), IPAddress.HostToNetworkOrder((short)StartAddress));
            NetCoreBitConverter.TryWriteBytes(bufferSpan.Slice(3, 2), IPAddress.HostToNetworkOrder((short)Value));
        }
Esempio n. 3
0
        public override void WriteTo(Memory <byte> buffer)
        {
            base.WriteTo(buffer);

            var bufferSpan = buffer.Span;

            NetCoreBitConverter.TryWriteBytes(bufferSpan.Slice(1, 2), IPAddress.HostToNetworkOrder((short)StartAddress));
            NetCoreBitConverter.TryWriteBytes(bufferSpan.Slice(3, 2), IPAddress.HostToNetworkOrder((short)NumberOfPoints));
            bufferSpan[5] = (byte)(ByteSize - 6);
        }
        public override void WriteTo(Memory <byte> buffer)
        {
            base.WriteTo(buffer);

            var bufferSpan = buffer.Span;

            for (int i = 0; i < data.Length; i++)
            {
                NetCoreBitConverter.TryWriteBytes(bufferSpan.Slice((i * 2) + 6, 2), IPAddress.HostToNetworkOrder((short)data[i]));
            }
        }
Esempio n. 5
0
        protected override async Task WriteRequestAsync(IModbusRequest request, CancellationToken token = default)
        {
            using (var memoryOwner = MemoryPool <byte> .Shared.Rent(MbapHeaderSizeOnRequest + request.ByteSize))
            {
                var memory = memoryOwner.Memory;

                NetCoreBitConverter.TryWriteBytes(memory.Slice(0, 2).Span, IPAddress.HostToNetworkOrder((short)request.TransactionId));
                memory.Span[2] = 0;
                memory.Span[3] = 0;
                NetCoreBitConverter.TryWriteBytes(memory.Slice(4, 2).Span, IPAddress.HostToNetworkOrder((short)(request.ByteSize + 1)));
                memory.Span[6] = request.SlaveAddress;

                request.WriteTo(memory.Slice(MbapHeaderSizeOnRequest, request.ByteSize));

                await PipeResource.WriteAsync(memory.Slice(0, MbapHeaderSizeOnRequest + request.ByteSize), token).ConfigureAwait(false);
            }
        }