- 74
- 0
- 约4.07万字
- 约 42页
- 2021-11-17 发布于天津
- 举报
很久以前 C# 编的串口小程序 ,希望对初学 C# 串口编程的童鞋有所帮助 ~
运行界面如下图 :
以下是源代码 :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.IO.Ports;
namespace SerialPortTest_1
{
public partial class FormSerialPortTest1 : Form
{
private StreamReader sRead;
public int iTextbox2 = 0;
public FormSerialPortTest1()
{
InitializeComponent();
}
private void Form1_Load( object sender, EventArgs e)
{
string [] str = SerialPort .GetPortNames();
if (str == null )
{
MessageBox .Show( 本机没有串口! , Error );
return ;
}
comboBox1.Items.AddRange(str);
comboBox1.SelectedIndex = 0;
comboBox2.SelectedIndex = 6;
this .toolStripStatusLabel1.Text = 端口号:端口未打开 ;
this .toolStripStatusLabel2.Text = 波特率:端口未打开 ;
this .toolStripStatusLabel3.Text = 数据位:端口未打开 ;
this .toolStripStatusLabel4.Text = 停止位:端口未打开 ;
}
private void button1_Click( object sender, EventArgs e)
{
String str1 = comboBox1.Text;
String str2 = comboBox2.Text;
String str3 = comboBox3.Text;
String str4 = comboBox4.Text;
Int32 int2 = Convert .ToInt32(str2);
Int32 int3 = Convert .ToInt32(str3);
try
{
if (str1 == null )
{
MessageBox .Show( 请先选择串口! ,Error );
return ;
}
serialPort1.PortName = str1;
serialPort1.BaudRate = int2;
serialPort1.DataBits
您可能关注的文档
最近下载
- 2025年特许金融分析师衍生品在投资组合中的风险与收益特性专题试卷及解析.pdf VIP
- 绵羊繁殖力关键基因多态性解析及分子育种应用研究.docx VIP
- 2025至2030年中国汕头市服装行业市场调查研究及投资前景预测报告.docx
- 2024-2025学年浙江省宁波市宁海县五年级(下)期末数学试卷含答案.pdf VIP
- 国企会计考试题库及答案.pdf VIP
- 气血胸休克的急救护理.pptx
- 2025年房地产经纪人谈判策略题型解析专题试卷及解析.pdf VIP
- 2023年江西中考物理试卷.docx VIP
- 《深入学习关于科技创新的重要论述》学习辅导-2024年公需试题及参考答案.docx VIP
- 2025年无人机驾驶员执照感知-避让系统维护与校准专题试卷及解析.pdf VIP
原创力文档

文档评论(0)