V2/Cet/IO/Cet.IO.Protocols.Modbus/ModbusCodecBase.cs
/// <summary>
/// Helper for packing the discrete data outgoing as a bit-array
/// </summary>
/// <param name="command"></param>
/// <param name="body"></param>
Helper for packing the discrete data outgoing as a bit-array
Helper for packing the discrete data outgoing as a bit - array
internal static void PushDiscretes(
            ModbusCommand command,
            ByteArrayWriter body)
        {
            var count = command.Count;
            body.WriteByte((byte)((count + 7) / 8));
            int i = 0;
            int cell = 0;
            for (int k = 0; k < count; k++)
            {
                if (command.Data[k] != 0)
                    cell |= (1 << i);
                if (++i == 8)
                {
                    body.WriteByte((byte)cell);
                    i = 0;
                    cell = 0;
                }
            }
            if (i > 0)
                body.WriteByte((byte)cell);
        }
internal static void PushDiscretes ( ModbusCommand command , ByteArrayWriter body ) { var count = command . Count ; body . WriteByte ( ( byte ) ( ( count + 7 ) / 8 ) ) ; int i = 0 ; int cell = 0 ; for ( int k = 0 ; k < count ; k ++ ) { if ( command . Data [ k ] != 0 ) cell |= ( 1 << i ) ; if ( ++ i == 8 ) { body . WriteByte ( ( byte ) cell ) ; i = 0 ; cell = 0 ; } } if ( i > 0 ) body . WriteByte ( ( byte ) cell ) ; }
Helper for packing the discrete data outgoing as a bit-array
Helper for packing the discrete data outgoing as a bit - array
command
ModbusCommand
None
body
ByteArrayWriter
None