V2/Cet/IO/Cet.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>
/// <returns>True if the data could be read</returns>
Helper for unpacking discrete data incoming as a bit-array
Helper for unpacking discrete data incoming as a bit - array
internal static bool PopDiscretes(
            ModbusCommand command,
            ByteArrayReader body)
        {
            var success = false;
            if (body.CanRead(1))
            {
                var byteCount = body.ReadByte();
                if (body.CanRead(byteCount))
                {
                    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));
                    }
                    success = true;
                }
            }
            return success;
        }
internal static bool PopDiscretes ( ModbusCommand command , ByteArrayReader body ) { var success = false ; if ( body . CanRead ( 1 ) ) { var byteCount = body . ReadByte ( ) ; if ( body . CanRead ( byteCount ) ) { 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 ) ) ; } success = true ; } } return success ; }
Helper for unpacking discrete data incoming as a bit-array
Helper for unpacking discrete data incoming as a bit - array
True if the data could be read
True if the data could be read
command
ModbusCommand
None
body
ByteArrayReader
None