S
Sean
I'm trying to read data from the Serial Port but I'm running in to a
strange problem. The data parses correctly in a Console Application,
but when I try to read the same way in a Windows Form Application it
drops data randomly.
In the windows form application I read data using the following code:
public Form1()
{
InitializeComponent();
serialPort1.Open();
}
private void Form1_FormClosing(object sender,
FormClosingEventArgs e)
{
if (serialPort1.IsOpen) serialPort1.Close();
}
private void serialPort1_DataReceived(object sender,
SerialDataReceivedEventArgs e)
{
this.Invoke(new EventHandler(DisplayText));
}
private void DisplayText(object sender, EventArgs e)
{
textBox1.AppendText(serialPort1.ReadExisting());
}
The output in the textbox is:
:E= PERSONAL MESSAGEMF
=$To:Sean Sims=:[email protected]=Sep 24 2008
11:43=Subject:Test
= text>
In the console application the same text appears as:
:E= PERSONAL MESSAGEMF
=$To:Sean Sims
=$From:[email protected]
=_Time:Sep 24 2008 11:43
=*Subject:Test
=#<Empty text>
It should appear like this:
PERSONAL MESSAGE
To:Sean Sims
From:[email protected]
Time:Sep 24 2008 11:43
Subject:Test
<Empty text>
First, what can I do to troubleshoot and/or prevent the lost data in
the middle of the message? Second, what can I do to get rid of the
strange characters that appear before each line? Thanks in advance for
any help you can offer.
strange problem. The data parses correctly in a Console Application,
but when I try to read the same way in a Windows Form Application it
drops data randomly.
In the windows form application I read data using the following code:
public Form1()
{
InitializeComponent();
serialPort1.Open();
}
private void Form1_FormClosing(object sender,
FormClosingEventArgs e)
{
if (serialPort1.IsOpen) serialPort1.Close();
}
private void serialPort1_DataReceived(object sender,
SerialDataReceivedEventArgs e)
{
this.Invoke(new EventHandler(DisplayText));
}
private void DisplayText(object sender, EventArgs e)
{
textBox1.AppendText(serialPort1.ReadExisting());
}
The output in the textbox is:
:E= PERSONAL MESSAGEMF
=$To:Sean Sims=:[email protected]=Sep 24 2008
11:43=Subject:Test
= text>
In the console application the same text appears as:
:E= PERSONAL MESSAGEMF
=$To:Sean Sims
=$From:[email protected]
=_Time:Sep 24 2008 11:43
=*Subject:Test
=#<Empty text>
It should appear like this:
PERSONAL MESSAGE
To:Sean Sims
From:[email protected]
Time:Sep 24 2008 11:43
Subject:Test
<Empty text>
First, what can I do to troubleshoot and/or prevent the lost data in
the middle of the message? Second, what can I do to get rid of the
strange characters that appear before each line? Thanks in advance for
any help you can offer.