/* Displays data according to the display type set by the user */ private void DisplayReceiveData() { if (receiveDisplayType >= 0 && receiveDisplayType <= 2) { byte[] buffer = receiveBuffer.ToArray(); int offset = 0, count = buffer.Length; if (count > setting.maxShowByteCount) { offset = count - setting.maxShowByteCount; count = setting.maxShowByteCount; } if (receiveDisplayType == 0) { ReceiveData = ByteConvert.BytesToHexString(buffer, offset, count); } else if (receiveDisplayType == 1) { ReceiveData = Encoding.GetEncoding(setting.receiveDataEncoding).GetString(buffer, offset, count); } else { ReceiveData = ByteConvert.BytesToBinString(buffer, offset, count); } } else { int count = 0; ReceiveBuffer.Block tempBlock; Stack <string> stack = new Stack <string>(); for (int i = receiveBuffer.BlockCount - 1; i >= 0; --i) { tempBlock = receiveBuffer.FindBlock(i); int putCount = setting.maxShowByteCount - count; if (putCount > tempBlock.Data.Length) { putCount = tempBlock.Data.Length; } if (putCount == 0) { break; } string head = tempBlock.Time.ToString(setting.receiveLogTimeFormat) + (setting.receiveLogLineFeedSplitsTimeAndContent ? '\n' : ':'); if (receiveDisplayType == 3) { stack.Push(head + ByteConvert.BytesToHexString(tempBlock.Data, tempBlock.Data.Length - putCount, putCount) + '\n'); } else if (receiveDisplayType == 4) { stack.Push(head + Encoding.GetEncoding(setting.receiveDataEncoding).GetString(tempBlock.Data, tempBlock.Data.Length - putCount, putCount) + '\n'); } else { stack.Push(head + ByteConvert.BytesToBinString(tempBlock.Data, tempBlock.Data.Length - putCount, putCount) + '\n'); } count += tempBlock.Data.Length; if (count > setting.maxShowByteCount) { break; } } StringBuilder finalDisplay = new StringBuilder(); while (stack.Count > 0) { finalDisplay.Append(stack.Pop()); } ReceiveData = finalDisplay.ToString(); } }