Permalink
Browse files

Add hex display for non alphanumeric bytes.

Fix baudrate error: baudrate was not set when opening port2.
  • Loading branch information...
NiceCircuits committed Nov 20, 2015
1 parent ada9586 commit 515d53312efbfce3b022fd6f27e5278804894788
Showing with 12 additions and 8 deletions.
  1. +12 −8 DualTerminal/Form1.cs
View
@@ -28,17 +28,20 @@ public Form1()
// Append text of the given color.
private void AppendText(Color color, string text)
{
int start = richTextBox1.TextLength;
richTextBox1.AppendText(text);
int end = richTextBox1.TextLength;
// Textbox may transform chars, so (end-start) != text.Length
richTextBox1.Select(start, end - start);
foreach (char c in text.ToCharArray())
{
richTextBox1.SelectionColor = color;
// could set box.SelectionBackColor, box.SelectionFont too.
if ((c >= ' ' && c <= '~') || c == '\n' || c == '\r' || c == '\t')
{
richTextBox1.SelectionFont = new Font(richTextBox1.SelectionFont, FontStyle.Bold);
richTextBox1.AppendText(c.ToString());
}
else
{
richTextBox1.SelectionFont = new Font(richTextBox1.SelectionFont, FontStyle.Italic);
richTextBox1.AppendText("{"+((int)c).ToString("X2")+"}");
}
}
richTextBox1.SelectionLength = 0; // clear
}
private int refreshPorts()
@@ -93,6 +96,7 @@ private void openToolStripMenuItem_Click(object sender=null, EventArgs e=null)
serialPort1.PortName = toolStripComboBoxPort1.SelectedItem.ToString();
serialPort2.PortName = toolStripComboBoxPort2.SelectedItem.ToString();
serialPort1.BaudRate = Int32.Parse(toolStripComboBoxBaud.SelectedItem.ToString());
serialPort2.BaudRate = Int32.Parse(toolStripComboBoxBaud.SelectedItem.ToString());
serialPort1.Open();
serialPort2.Open();
openToolStripMenuItem.Enabled = false;

0 comments on commit 515d533

Please sign in to comment.