public void DataLength()
        {
            // Arrange
            var header = new EnttecMessageHeader();

            // Act
            header.SetDataLength(10);

            // Assert
            Assert.Equal(10, header.GetDataLength());
        }
Exemple #2
0
        private byte[] ReceiveInternal(ApplicationMessages messageType)
        {
            var startCode = new byte[1];

            if (!_ftdiDriver.Read(startCode))
            {
                return(null);
            }

            if (EnttecMessageHeader.StartCodeByte != startCode[0])
            {
                return(null);
            }

            var byte1 = new byte[1];
            var byte2 = new byte[1];
            var byte3 = new byte[1];

            if (!_ftdiDriver.Read(byte1))
            {
                return(null);
            }

            if (!_ftdiDriver.Read(byte2))
            {
                return(null);
            }

            if (!_ftdiDriver.Read(byte3))
            {
                return(null);
            }

            if (byte1[0] != (byte)messageType)
            {
                return(null);
            }

            var header = new EnttecMessageHeader(new byte[]
            {
                startCode[0],
                byte1[0],
                byte2[0],
                byte3[0]
            });

            if (!header.IsValid())
            {
                return(null);
            }

            var body = new EnttecMessageBody(new byte[header.GetDataLength()]);

            if (!_ftdiDriver.Read(body.Data))
            {
                return(null);
            }

            var footer = new EnttecMessageFooter();

            if (!(_ftdiDriver.Read(footer.Data) & footer.IsValid()))
            {
                return(null);
            }

            return(body.Data);
        }