V1/Cet.Develop.NETMF.IO/Protocols/Modbus/ModbusCodecBase.cs
/// <summary>
/// Helper for unpacking discrete data incoming as a bit-array
/// </summary>
/// <param name="command"></param>
/// <param name="body"></param>
Helper for unpacking discrete data incoming as a bit-array
Helper for unpacking discrete data incoming as a bit - array
internal static void PopDiscretes(
            ModbusCommand command,
            ByteArrayReader body)
        {
            var byteCount = body.ReadByte();
            var count = command.Count;
            command.Data = new ushort[count];
            command.QueryTotalLength += (byteCount + 1);
            int k = 0;
            while (count > 0)
            {
                byteCount--;
                int cell = body.ReadByte();
                int n = count <= 8 ? count : 8;
                count -= n;
                for (int i = 0; i < n; i++)
                    command.Data[k++] = (ushort)(cell & (1 << i));
            }
        }
internal static void PopDiscretes ( ModbusCommand command , ByteArrayReader body ) { var byteCount = body . ReadByte ( ) ; var count = command . Count ; command . Data = new ushort [ count ] ; command . QueryTotalLength += ( byteCount + 1 ) ; int k = 0 ; while ( count > 0 ) { byteCount -- ; int cell = body . ReadByte ( ) ; int n = count <= 8 ? count : 8 ; count -= n ; for ( int i = 0 ; i < n ; i ++ ) command . Data [ k ++ ] = ( ushort ) ( cell & ( 1 << i ) ) ; } }
Helper for unpacking discrete data incoming as a bit-array
Helper for unpacking discrete data incoming as a bit - array
command
ModbusCommand
None
body
ByteArrayReader
None