private void ComPortOnDataReceived([CanBeNull] object sender, [NotNull] SerialDataReceivedEventArgs e) { try { bool done; do { done = true; byte[] buffer; int bytesToRead = SafeGetBytesToRead(); int bytesRead = SafeComRead(bytesToRead, out buffer); if (bytesRead > 0 && buffer != null) { done = false; var block = new ArraySegment<byte>(buffer, 0, bytesRead); Log.Debug($"<= RAW: {block.FormatHexBuffer()}"); assembler.Add(block); } } while (!done); } catch (Exception ex) { Log.Error($"Unexpected error while processing received data from {PortName}.", ex); } }