阅读原文 http://www.sufeinet.com/thread-2196-1-1.html

private void btnGo_Click(object sender, EventArgs e)
        {

            try
            {
                serialPort1.PortName = "COM1";
                serialPort1.Open();
                byte[] data = Encoding.Unicode.GetBytes(textBox1.Text);
                string str = Convert.ToBase64String(data);
                serialPort1.WriteLine(str);
                serialPort1.Close();
                MessageBox.Show("数据发送成功!", "系统提示");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message .ToString (),"提示信息");
            }
        }

        //当有数据到达里触发
        private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            serialPort1.PortName = "COM1";
            serialPort1.Open();

            byte[] data = Convert.FromBase64String(serialPort1.ReadLine());
            textBox2.Text = Encoding.Unicode.GetString(data);
            serialPort1.Close();
            MessageBox.Show("数据接收成功!", "系统提示");
        }

相关文章:

  • 2022-12-23
  • 2021-11-11
  • 2021-12-14
  • 2022-12-23
  • 2018-07-25
  • 2022-02-22
  • 2022-12-23
  • 2021-06-02
猜你喜欢
  • 2021-10-25
  • 2022-12-23
  • 2022-12-23
  • 2021-10-05
  • 2021-09-20
  • 2022-12-23
  • 2022-01-05
相关资源
相似解决方案