J
jodleren
Hi
My code is below. My problem is that I am trying to receive data from
some hardware, and it works when I am debugging it. But when I run it
in released mode, I get junk data - my strings get mixed up.
And now when writing this, I just checked something - and found, that
a break point in runtime, and I see that my received data is ok, but
my readout (the 2 subsrings) causes the problems. Like they cannot
handle the amount of data. Any ideas?
My problem:
line = ReceivedLine.Substring(0, i).Trim();
string tmp = ReceivedLine.Substring(i + 1);
ReceivedLine = tmp;
Entire code:
Conn.NewLine = '\r'.ToString(); //set packet terminator
Conn.DataBits = 8;
Conn.BaudRate = 115200;
Conn.Parity = System.IO.Ports.Parity.None;
Conn.StopBits = System.IO.Ports.StopBits.One;
Conn.DataBits = 8;
Conn.DtrEnable = true;
Conn.RtsEnable = true;
Conn.ReadTimeout = Conn.WriteTimeout = 500;//ms
Conn.DataReceived += Conn_DataReceived;
// handle data received
string ReceivedLine;
private void Conn_DataReceived(object sender,
System.IO.Ports.SerialDataReceivedEventArgs e)
{
string line;
ReceivedLine = Conn.ReadExisting();// reader.ReadLine();
while((i = ReceivedLine.IndexOf('\r')) != -1)
{
line = ReceivedLine.Substring(0, i).Trim();
string tmp = ReceivedLine.Substring(i + 1);
ReceivedLine = tmp;
__Log2(line);
if (line != "")
{
if (line.Substring(0, 1) == "!")
__Log2("dataline");
}
}
My code is below. My problem is that I am trying to receive data from
some hardware, and it works when I am debugging it. But when I run it
in released mode, I get junk data - my strings get mixed up.
And now when writing this, I just checked something - and found, that
a break point in runtime, and I see that my received data is ok, but
my readout (the 2 subsrings) causes the problems. Like they cannot
handle the amount of data. Any ideas?
My problem:
line = ReceivedLine.Substring(0, i).Trim();
string tmp = ReceivedLine.Substring(i + 1);
ReceivedLine = tmp;
Entire code:
Conn.NewLine = '\r'.ToString(); //set packet terminator
Conn.DataBits = 8;
Conn.BaudRate = 115200;
Conn.Parity = System.IO.Ports.Parity.None;
Conn.StopBits = System.IO.Ports.StopBits.One;
Conn.DataBits = 8;
Conn.DtrEnable = true;
Conn.RtsEnable = true;
Conn.ReadTimeout = Conn.WriteTimeout = 500;//ms
Conn.DataReceived += Conn_DataReceived;
// handle data received
string ReceivedLine;
private void Conn_DataReceived(object sender,
System.IO.Ports.SerialDataReceivedEventArgs e)
{
string line;
ReceivedLine = Conn.ReadExisting();// reader.ReadLine();
while((i = ReceivedLine.IndexOf('\r')) != -1)
{
line = ReceivedLine.Substring(0, i).Trim();
string tmp = ReceivedLine.Substring(i + 1);
ReceivedLine = tmp;
__Log2(line);
if (line != "")
{
if (line.Substring(0, 1) == "!")
__Log2("dataline");
}
}