我想使用UART将温度值从微控制器发送到C#接口,并在标签上显示温度。内容
。这是我的微控制器代码:
while(1) {
key_scan(); // get value of temp
if (Usart_Data_Ready())
{
while(temperature[i]!=0)
{
if(temperature[i]!= )
{
Usart_Write(temperature[i]);
Delay_ms(1000);
}
i = i + 1;
}
i =0;
Delay_ms(2000);
}
}
我的C#代码是:
private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
txt += serialPort1.ReadExisting().ToString();
textBox1.Text = txt.ToString();
}
but exception arises there "Cross-thread operation not valid: Control textBox1 accessed from a thread other than the thread it was created on" Please tell me how to get temperature string from my microcontroller and remove this Error!