rossmann-engineering / EasyModbusTCP.NET

Modbus TCP, Modbus UDP and Modbus RTU client/server library for .NET implementations
922 stars 396 forks source link

When the CRC fails, the system enters an infinite loop #83

Open 541728305 opened 2 years ago

541728305 commented 2 years ago

When the slave machine continuously receives incorrect response and CRC check fails, the stack overflow will occur in an infinite loop if (receivedUnitIdentifier != this.unitIdentifier) data = new byte[2100]; else countRetries = 0;

if ((crc[0] != data[data[8]+9] | crc[1] != data[data[8]+10])& dataReceived) { if (debug) StoreLogData.Instance.Store("CRCCheckFailedException Throwed", System.DateTime.Now); if (NumberOfRetries <= countRetries) { countRetries = 0; throw new EasyModbus.Exceptions.CRCCheckFailedException("Response CRC check failed"); } else { countRetries++; Console.WriteLine("countRetries:{0}", countRetries); return ReadHoldingRegisters(startingAddress, quantity); } }