110,534
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace wendu
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
for (int i = 1; i < 20; i++)
{
comboBox1.Items.Add("COM" + i.ToString());
}
comboBox1.Text = "COM1";
comboBox2.Text = "9600";
}
private void button1_Click(object sender, EventArgs e)
{
try
{
serialPort1.BaudRate = Convert.ToInt32(comboBox2.Text, 10); ;
serialPort1.PortName = comboBox1.Text;
serialPort1.Open();
}
catch
{
MessageBox.Show("输入有误,请检查", "错误");
}
double k = Convert.ToDouble(serialPort1.ReadLine());
double wendu = k ;
label4.Text = wendu.ToString() + "℃";
}
}
}