串口数据显示在textbox里
我先把我的主要代码贴上来:
private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
byte[]lpBuffer=new byte [10];
uint[] m_v = new uint[5];
serialPort1.Read(lpBuffer, 0, 10);
m_v[0] = Convert.ToUInt32((lpBuffer[0] < < 4) + (lpBuffer[1] & 0x0f));
m_v[1] = Convert.ToUInt32((lpBuffer[2] < < 4) + (lpBuffer[3] & 0x0f));
m_v[2] = Convert.ToUInt32((lpBuffer[4] < < 4) + (lpBuffer[5] & 0x0f));
m_v[3] = Convert.ToUInt32((lpBuffer[6] < < 4) + (lpBuffer[7] & 0x0f));
m_v[4] = Convert.ToUInt32((lpBuffer[8] < < 4) + (lpBuffer[9] & 0x0f));
m_vol[0] = Convert.ToSingle((float)(m_v[0]) * 5 / 4095);
m_vol[1] = Convert.ToSingle((float)(m_v[1]) * 5 / 4095);
m_vol[2] = Convert.ToSingle((float)(m_v[2]) * 5 / 4095);
m_vol[3] = Convert.ToSingle((float)(m_v[3]) * 5 / 4095);
m_vol[4] = Convert.ToSingle((float)(m_v[4]) * 5 / 4095);
this.Invoke(new EventHandler(DoUpdate));
}
private void DoUpdate(object s, EventArgs e)
{
Cur_R.Text = m_vol[0].ToString();
Cur_X.Text = m_vol[1].ToString();
Cur_G.Text = m_vol[2].ToString();
Cur_B.Text = m_vol[3].ToString();
Cur_Phase.Text = m_vol[4].ToString();