嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 2 元微信扫码支付:2 元
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
适合新手入门的串口调试助手
private void button1_Click(object sender, EventArgs e)
{
if (flag)
{
try
{
button1.Text = "关闭串口";
pictureBox1.Visible = true;
pictureBox2.Visible = false;
serialPort1.PortName = comboBox1.Text;
serialPort1.BaudRate = Convert.ToInt32(comboBox2.Text, 10);
serialPort1.Parity = 0;
serialPort1.DataBits = 8;
flag = false;
serialPort1.Open();
}
catch
{
MessageBox.Show("端口错误,请检查串口", "错误");
button1.Text = "打开串口";
flag = true;
pictureBox1.Visible = false;
pictureBox2.Visible = true;
serialPort1.Close();
}
}
else
{
button1.Text = "打开串口";
flag = true;
pictureBox1.Visible = false;
pictureBox2.Visible = true;
serialPort1.Close();
}
}
private void button3_Click(object sender, EventArgs e)
{
System.Windows.Forms.SaveFileDialog objSave = new System.Windows.Forms.SaveFileDialog();
objSave.Filter = "(*.txt)|*.txt|" "(*.*)|*.*";
objSave.FileName = "文件" DateTime.Now.ToString("yyyyMMddHHmm") ".txt";
if (objSave.ShowDialog() == DialogResult.OK)
{
StreamWriter FileWriter = new StreamWriter(objSave.FileName, true); //写文件
FileWriter.Write(this.textBox1.Text);//将字符串写入
FileWriter.Close(); //关闭StreamWriter对象
}
}