MTSkull
Centurion
I wrote a Simple Hyper Terminal Emulator because my regular hyper terminal keeps locking up my computer. I have gotten the functionality pretty close to what I want with one exception. I am outputting the contents of the serial buffer to a rich text box that will also take key strokes and send them back to the device under test. The problem I am having is getting the richtext box to stay scrolled down so it displays only the latest received data.
Approaches I have tried...
richtext.scrolltocarat();
every time new serial data enters the text box the carat jumps back to the home position so scroll to carat does nothing.
SendKeys.Send("^{END}");
because I am reacting to keystroke events this sends the program into an infinite loop, I think.
Limiting the text box to 30 lines of the most recent data. Worked great when I was reading serial data in Line by Line, just push the results into a string collection. But the application needed to react to partial lines of incoming data.
Attached is the whole project if anyone would like to take a look. but here is the pertinent code.
Approaches I have tried...
richtext.scrolltocarat();
every time new serial data enters the text box the carat jumps back to the home position so scroll to carat does nothing.
SendKeys.Send("^{END}");
because I am reacting to keystroke events this sends the program into an infinite loop, I think.
Limiting the text box to 30 lines of the most recent data. Worked great when I was reading serial data in Line by Line, just push the results into a string collection. But the application needed to react to partial lines of incoming data.
Attached is the whole project if anyone would like to take a look. but here is the pertinent code.
C#:
private void timer1_Tick(object sender, EventArgs e)
{
//function checks the input stream for buffered text, if it is there read it out to the rtxtbox
if (serialPort1.IsOpen != true)
return;
//get input stream from port1
// check buffer?
if (serialPort1.BytesToRead > 0)
{
try
{
rtxtStatus.Text = rtxtStatus.Text + serialPort1.ReadExisting();
//Does not work, need to force carat to end so it will subequently scroll to the carat.
// Carat returns to home and does not stay at the end of the control.
//rtxtStatus.Focus();
//rtxtStatus.ScrollToCaret();
//Sending Cntrl End to move to the end of the rich text box
//send keys cause endless loop in conjunction with form keypress event.
//rtxtStatus.Focus();
//SendKeys.Send("^{END}");
//txtSendText.Focus();
//Trying to limit the lines of text to 30 keeping the most current info in view
//if (FromRadio.Count > 30)
//{
// rtxtStatus.Text = "";
// for(int x = (FromRadio.Count-31);x<FromRadio.Count;x++)
// rtxtStatus.Text = rtxtStatus.Text + FromRadio[x];
//}
//else
// rtxtStatus.Text = rtxtStatus.Text + FromRadio[FromRadio.Count-1];
}
catch
{
//do nothing??
// if it errors I don't care just keep going... for now
}
}
this.Update();
Application.DoEvents();
}
Attachments
Last edited by a moderator: