private void timer1_Tick(object sender, EventArgs e) { EndPoint remoteEP; int iUDPRecv, iUDPSend; byte[] byUDPSend; string szUDPRecv, szComRecv; timer1.Enabled = false; if (m_SvrStream.DataArrive(10)) { if (m_SvrStream.RecvUDP(out remoteEP, m_byUDPRecv, out iUDPRecv)) { m_UDPRecv++; textBoxUDPRecv.Text = m_UDPRecv.ToString(); szUDPRecv = Encoding.ASCII.GetString(m_byUDPRecv, 0, iUDPRecv); // pass command to COM port m_SerialSent++; textBoxSerialSent.Text = m_SerialSent.ToString(); if (m_com.AdamTransaction(szUDPRecv, out szComRecv)) { m_SerialRecv++; textBoxSerialRecv.Text = m_SerialSent.ToString(); byUDPSend = Encoding.ASCII.GetBytes(szComRecv); iUDPSend = byUDPSend.Length; if (m_SvrStream.SendUDP(ref remoteEP, byUDPSend, iUDPSend)) { m_UDPSent++; textBoxUDPSent.Text = m_UDPSent.ToString(); } } } } timer1.Enabled = true; }