diff --git a/src/SonyBraviaDevice.cs b/src/SonyBraviaDevice.cs index 80f7bba..015658a 100644 --- a/src/SonyBraviaDevice.cs +++ b/src/SonyBraviaDevice.cs @@ -580,8 +580,19 @@ private object ProcessRs232Response(object _) Debug.Console(DebugLevels.ErrorLevel, this, "ProcessRs232Response: bytes-'{0}' (len-'{1}') | buffer-'{2}' (len-'{3}')", bytes.ToReadableString(), bytes.Length, buffer.ToReadableString(), buffer.Length); - while (buffer.Length >= 3) + const int safety = 10; + var numberOfSpins = 0; + while (buffer.Length >= 3 && numberOfSpins <= safety) { + ++numberOfSpins; + if (numberOfSpins == safety) + Debug.Console(0, + this, + Debug.ErrorLogLevel.Notice, + "We hit our safety limit, something is wrong... Buffer:{0}, Bytes:{1}", + buffer.ToReadableString(), + bytes.ToReadableString()); + var message = buffer.GetFirstMessage(); Debug.Console(DebugLevels.ErrorLevel, this, "ProcessRs232Response: bytes-'{0}' (len-'{1}') | buffer-'{2}' (len-'{3}') | message-'{4}' (len-'{5}')", bytes.ToReadableString(), bytes.Length,