在串口接收到一组一组的横纵坐标值,想把每一组横纵坐标分开使用,在两个textbox控件中分别显示横纵坐标。但是发现并没有实时更新都是只是串口接收到的第一组数据
程序如下:
private void sp_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
byte[] ReceivedData = new byte[sp.BytesToRead];//创建接收字节数组
sp.Read(ReceivedData, 0, ReceivedData.Length);//读取所接收到的数据
receivedDatas.AddRange(ReceivedData);
textBox3.Text = (Convert.ToInt32(textBox3.Text) + ReceivedData.Length).ToString();
if (checkBox2.Checked)
{
textBox1.Text = Class1.ByteTo16Str(receivedDatas.ToArray());
}
else
{
textBox1.Text = Encoding.Default.GetString(receivedDatas.ToArray());
//让文本框获取焦点
string a = Encoding.Default.GetString(receivedDatas.ToArray());
string[] sArray = a.Split(',');
// textBox15.Text = a;
textBox15.Text = textBox15.Text +"\n"+sArray[0];
textBox16.Text = textBox16.Text + "\n" + sArray[1];
![图片说明](https://img-ask.csdn.net/upload/201705/19/1495177633_459101.png)
this.textBox15.Focus();
//设置光标的位置到文本尾
this.textBox15.Select(this.textBox1.TextLength, 0);
//滚动到控件光标处
this.textBox15.ScrollToCaret();
this.textBox16.Focus();
//设置光标的位置到文本尾
this.textBox16.Select(this.textBox1.TextLength, 0);
//滚动到控件光标处
this.textBox16.ScrollToCaret();
this.textBox1.Focus();
//设置光标的位置到文本尾
this.textBox1.Select(this.textBox1.TextLength, 0);
//滚动到控件光标处
this.textBox1.ScrollToCaret();
}
是需要timer控件还是怎么样可以实现呢?