基于C#的串口通信上位机和下位机源程序文件Word下载.docx

上传人:b****6 文档编号:8651830 上传时间:2023-05-12 格式:DOCX 页数:49 大小:19.85KB
下载 相关 举报
基于C#的串口通信上位机和下位机源程序文件Word下载.docx_第1页
第1页 / 共49页
基于C#的串口通信上位机和下位机源程序文件Word下载.docx_第2页
第2页 / 共49页
基于C#的串口通信上位机和下位机源程序文件Word下载.docx_第3页
第3页 / 共49页
基于C#的串口通信上位机和下位机源程序文件Word下载.docx_第4页
第4页 / 共49页
基于C#的串口通信上位机和下位机源程序文件Word下载.docx_第5页
第5页 / 共49页
基于C#的串口通信上位机和下位机源程序文件Word下载.docx_第6页
第6页 / 共49页
基于C#的串口通信上位机和下位机源程序文件Word下载.docx_第7页
第7页 / 共49页
基于C#的串口通信上位机和下位机源程序文件Word下载.docx_第8页
第8页 / 共49页
基于C#的串口通信上位机和下位机源程序文件Word下载.docx_第9页
第9页 / 共49页
基于C#的串口通信上位机和下位机源程序文件Word下载.docx_第10页
第10页 / 共49页
基于C#的串口通信上位机和下位机源程序文件Word下载.docx_第11页
第11页 / 共49页
基于C#的串口通信上位机和下位机源程序文件Word下载.docx_第12页
第12页 / 共49页
基于C#的串口通信上位机和下位机源程序文件Word下载.docx_第13页
第13页 / 共49页
基于C#的串口通信上位机和下位机源程序文件Word下载.docx_第14页
第14页 / 共49页
基于C#的串口通信上位机和下位机源程序文件Word下载.docx_第15页
第15页 / 共49页
基于C#的串口通信上位机和下位机源程序文件Word下载.docx_第16页
第16页 / 共49页
基于C#的串口通信上位机和下位机源程序文件Word下载.docx_第17页
第17页 / 共49页
基于C#的串口通信上位机和下位机源程序文件Word下载.docx_第18页
第18页 / 共49页
基于C#的串口通信上位机和下位机源程序文件Word下载.docx_第19页
第19页 / 共49页
基于C#的串口通信上位机和下位机源程序文件Word下载.docx_第20页
第20页 / 共49页
亲,该文档总共49页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

基于C#的串口通信上位机和下位机源程序文件Word下载.docx

《基于C#的串口通信上位机和下位机源程序文件Word下载.docx》由会员分享,可在线阅读,更多相关《基于C#的串口通信上位机和下位机源程序文件Word下载.docx(49页珍藏版)》请在冰点文库上搜索。

基于C#的串口通信上位机和下位机源程序文件Word下载.docx

1200米。

首先亮出C#的源程序吧。

主要界面:

只是作为简单的运用,可以扩展的。

.下载可编辑.

源代码:

usingSystem;

usingSystem.Collections.Generic;

usingSystem.ComponentModel;

usingSystem.Data;

usingSystem.Drawing;

usingSystem.Text;

usingSystem.Windows.Forms;

usingSystem.IO.Ports;

usingSystem.Timers;

namespace单片机功能控制

{

publicpartialclassForm1:

Form

publicForm1()

InitializeComponent();

}

SerialPortsp=newSerialPort();

privatevoidbutton1_Click(objectsender,EventArgse)

Stringstr1=comboBox1.Text;

//串口号

Stringstr2=comboBox2.Text;

//波特率

Stringstr3=comboBox3.Text;

//校验位

Stringstr4=comboBox5.Text;

//停止位

Stringstr5=comboBox4.Text;

//数据位

Int32int2=Convert.ToInt32(str2);

//将字符串转为整型

Int32int5=Convert.ToInt32(str5);

groupBox3.Enabled=true;

//LED控制界面变可选

try

if(button1.Text=="

打开串口"

if(str1==null)

MessageBox.Show("

请先选择串口!

"

"

Error"

);

return;

sp.Close();

sp=newSerialPort();

sp.PortName=comboBox1.Text;

//串口编号

sp.BaudRate=int2;

switch(str4)//停止位

case"

1"

:

sp.StopBits=StopBits.One;

break;

1.5"

sp.StopBits=StopBits.OnePointFive;

2"

sp.StopBits=StopBits.Two;

default:

Error:

参数不正确"

switch(str3)

NONE"

sp.Parity=Parity.None;

break;

ODD"

sp.Parity=Parity.Odd;

EVEN"

sp.Parity=Parity.Even;

sp.DataBits=int5;

//设置串口属性

sp.Open();

//打开串口

button1.Text="

关闭串口"

;

textBox1.Text=Convert.ToString(sp.PortName)+"

已开启!

"

else

groupBox3.Enabled=false;

//LED控制界面变灰色

已关闭!

catch(Exceptioner)

Error:

+er.Message,"

privatevoidForm1_Load(objectsender,EventArgse)

//初始化

textBox1.Text="

欢迎使用简易的串口助手!

groupBox6.Enabled=false;

groupBox7.Enabled=false;

groupBox8.Enabled=false;

button3.Enabled=false;

button6.Enabled=false;

timer1.Start();

foreach(stringcominSystem.IO.Ports.SerialPort.GetPortNames())//

自动获取串行口名称

boBox1.Items.Add(com);

//默认设置

comboBox1.SelectedIndex=0;

//选择第一个com口

comboBox2.SelectedIndex=4;

//波特率4800

comboBox3.SelectedIndex=0;

//校验位NONE

comboBox4.SelectedIndex=0;

//停止位为1

comboBox5.SelectedIndex=0;

//数据位为8

catch

找不到通讯端口!

串口调试助手"

privatevoidtimer1_Tick(objectsender,EventArgse)

label6.Text=DateTime.Now.ToString();

privatevoidbutton2_Click(objectsender,EventArgse)

try{

if(button2.Text=="

开启"

groupBox6.Enabled=true;

radioButton1.Checked=false;

radioButton2.Checked=false;

radioButton3.Checked=false;

radioButton4.Checked=false;

checkBox1.Checked=false;

checkBox2.Checked=false;

checkBox3.Checked=false;

checkBox4.Checked=false;

checkBox5.Checked=false;

checkBox6.Checked=false;

checkBox7.Checked=false;

checkBox8.Checked=false;

button3.Enabled=true;

textBox2.Text=String.Empty;

button2.Text="

关闭"

privatevoidbutton3_Click(objectsender,EventArgse)

label7.Text="

已发送"

if(textBox2.Text=="

发送失败,请选择发送的数据!

sp.WriteLine(textBox2.Text);

//往串口写数据

privatevoidcheckBox1_CheckedChanged(objectsender,EventArgse)

if(checkBox1.Checked)

checkBox1.Checked=true;

准备发送"

textBox2.Text="

privatevoidcheckBox2_CheckedChanged(objectsender,EventArgse)

if(checkBox2.Checked)

checkBox2.Checked=true;

privatevoidcheckBox3_CheckedChanged(objectsender,EventArgse)

if(checkBox3.Checked)

checkBox3.Checked=true;

3"

privatevoidcheckBox4_CheckedChanged(objectsender,EventArgse)

if(checkBox4.Checked)

checkBox4.Checked=true;

4"

privatevoidcheckBox5_CheckedChanged(objectsender,EventArgse)

if(checkBox5.Checked)

checkBox5.Checked=true;

5"

privatevoidcheckBox6_CheckedChanged(objectsender,EventArgse)

if(checkBox6.Checked)

checkBox6.Checked=true;

6"

privatevoidcheckBox7_CheckedChanged(objectsender,EventArgse)

if(checkBox7.Checked)

checkBox7.Checked=true;

7"

privatevoidcheckBox8_CheckedChanged(objectsender,EventArgse)

if(checkBox8.Checked)

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 解决方案 > 学习计划

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2