Exemple #1
0
 public static Crc Calc(byte[] buffer, int offset, int length, ICrcCalculator calculator)
 {
     if (calculator != null && buffer.Length > offset && buffer.Length - offset >= length)
     {
         return(calculator.Calculate(buffer, offset, length));
     }
     return(new Crc(null));
 }
Exemple #2
0
        public static bool CheckReverse(byte[] buffer, int offset, int length, ICrcCalculator calculator)
        {
            bool success = false;

            if (calculator != null &&
                buffer.Length > offset &&
                buffer.Length - offset >= length &&
                length > calculator.CrcDataLength)
            {
                var crc = Calc(buffer, offset, length - calculator.CrcDataLength, calculator);
                success = crc.CrcData.Length == calculator.CrcDataLength;
                for (int i = 0; i < calculator.CrcDataLength; i++)
                {
                    if (!success)
                    {
                        break;
                    }
                    success &= buffer[offset + length - calculator.CrcDataLength + i] == crc.CrcData.Reverse().ToArray()[i];
                }
            }

            return(success);
        }
Exemple #3
0
 /// <summary>
 /// Initializes a new instance of <see cref="PngImageEncoder"/>.
 /// </summary>
 /// <param name="crcCalculator"></param>
 public PngImageEncoder(ICrcCalculator crcCalculator)
 {
     _crcCalculator = crcCalculator;
 }
Exemple #4
0
 public ModbusRtuOverTcpTransport(IPipeResource pipeResource, ITransactionIdProvider transactionIdProvider, ICrcCalculator crcCalculator, ILogger <IModbusMaster> logger)
     : base(pipeResource, transactionIdProvider, logger)
 {
     this.crcCalculator = crcCalculator;
 }
Exemple #5
0
 public static bool CheckReverse(byte[] buffer, ICrcCalculator calculator)
 {
     return(CheckReverse(buffer, 0, buffer.Length, calculator));
 }
Exemple #6
0
 public static Crc Calc(byte[] buffer, ICrcCalculator calculator)
 {
     return(Calc(buffer, 0, buffer.Length, calculator));
 }