日期:2014-05-18 浏览次数:21029 次
void com_Recived(object sender, SerialDataReceivedEventArgs e)
{
int n = comm.BytesToRead;
byte[] b = new byte[n];
comm.Read(b, 0, n);
builder.Append(Encoding.ASCII.GetString(b));
String line = builder.ToString();//
str = line.Substring(6, 4);
this.Invoke((EventHandler)(delegate
{
this.richTextBox1.AppendText(str);
}));
}
public delegate void _SafeAddtrTextCall(string text);//定义一个委托
private void safeAddtrText(string text)
{
if (this.InvokeRequired)
{
_SafeAddtrTextCall call = delegate(string s) { textBox41.Text +=s; };
this.Invoke(call, text);
}
else
{
textBox41.Text += text;
}
}
private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
string tmpstr = "";
string a = "";
for (int i = 0; i < serialPort1.BytesToRead; i++)
{
a = Convert.ToString(serialPort1.ReadByte(), 16);
tmpstr += a + " ";
}
tmpstr = tmpstr.ToUpper();
safeAddtrText(tmpstr);
}