c#串口通信问题
using System;using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using
namespace comtry0
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
SerialPort SerialPort1 = new SerialPort();
SerialPort1.PortName = "COM1";
SerialPort1.BaudRate = 115200;
SerialPort1.DataBits = 8;
SerialPort1.Parity = Parity.None ;
SerialPort1.StopBits = StopBits.One ;
SerialPort1.ReadTimeout = 1000;
SerialPort1.Open();
byte[] date = Encoding.Unicode.GetBytes(textBox1.Text);
string str = Convert.ToBase64String(date);
SerialPort1.WriteLine(str);
MessageBox.Show("数据发送成功");
SerialPort1.Close();
}
private void button2_Click(object sender, EventArgs e)
{
SerialPort SerialPort1 = new SerialPort();
SerialPort1.PortName = "COM1";
SerialPort1.BaudRate = 115200;
SerialPort1.DataBits = 8;
SerialPort1.Parity = Parity.None;
SerialPort1.StopBits = StopBits.One;
SerialPort1.ReadTimeout = 1000;
SerialPort1.Open();
byte[] date = Convert.FromBase64String(SerialPort1.ReadLine());
textBox2.Text = Encoding.Unicode.GetString(date,0,date.Length);
SerialPort1.Close();
MessageBox.Show("数据接收成功");
}
这是我写的在wince6下的串口发送和接收的设备应用程序,问题(1)当向pc机上的串口调试助手发送数据时,串口调试助手可以接收到数据,但不是我所发送的数据;问题(2)利用串口调试助手向我编写的程序发送数据时,接收不到数据。请高人指点,我刚刚开始学习这么语言,最好能说的详细些。