资源简介
简单的串口通信工具,可以实现串口一些属性的设置,文件是在VS2017下的整个工程文件,方便修改、学习。C#语言实现。

代码片段和文件信息
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace _20180601
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button3_Click(object sender EventArgs e)//单击清除窗口按钮事件
{
richTextBox1.Clear();
}
private void button1_Click(object sender EventArgs e)//单击打开串口按钮事件
{
serialPort1.PortName = “COM5“;
serialPort1.BaudRate = 115200;
serialPort1.StopBits = System.IO.Ports.StopBits.One;
serialPort1.DataBits = 8;
serialPort1.Parity = System.IO.Ports.Parity.None;
try
{
serialPort1.Open();//打开串口后,锁定下拉框。
comboBox1.Enabled = false;
comboBox2.Enabled = false;
comboBox3.Enabled = false;
comboBox4.Enabled = false;
comboBox5.Enabled = false;
}
catch
{
MessageBox.Show(“串口打开错误,请检查!““消息提示“);
}
}
private void button2_Click(object sender EventArgs e)//点击关闭串口事件
{
serialPort1.Close();
comboBox1.Enabled = true;//关闭串口后,下拉框可选。
comboBox2.Enabled = true;
comboBox3.Enabled = true;
comboBox4.Enabled = true;
comboBox5.Enabled = true;
}
private void button4_Click(object sender EventArgs e)//点击保存按钮事件
{
textBox3.Text = “D:\\“;
string curTime = DateTime.Now.ToString(“yyyyMMddhhmmss“);//获取系统当前时间
textBox3.Text += curTime+“.txt“;//将当前时间文本显示在文本框中
FileStream fs = new FileStream(“D:\\“+ curTime+“.txt“ FileMode.Create FileAccess.Write);
StreamWriter sw = new StreamWriter(fs);
sw.WriteLine(richTextBox1.Text);
sw.Flush();
sw.Close();
}
private void button6_Click(object sender EventArgs e)//点击发送文件按钮
{
OpenFileDialog file = new OpenFileDialog();
file.title = “请选择要发送的文件“;
file.Filter = “文本文件|*.txt“;
if (file.ShowDialog() == DialogResult.OK)
{
// richTextBox2.LoadFile(file.FileName); 报错,提示无效的文件格式。
//如下,将文本文件中的内容读取到流中,再写入richTextBox2中
try
{
using (StreamReader sr = new StreamReader(file.FileName))
{
string line;
//循环发送将下列代码for(1000次)
while ((line = sr.ReadLine()) != null)
{
richTextBox2.Text += line;
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
..A..H. 49664 2018-06-02 13:14 20180601\.vs\20180601\v15\.suo
文件 647168 2018-06-02 13:13 20180601\.vs\20180601\v15\sqlite3\storage.ide
文件 3564 2018-06-01 18:40 20180601\20180601\20180601.csproj
文件 189 2018-06-01 18:23 20180601\20180601\App.config
文件 22528 2018-06-02 13:13 20180601\20180601\bin\Debug\20180601.exe
文件 189 2018-06-01 18:23 20180601\20180601\bin\Debug\20180601.exe.config
文件 26112 2018-06-02 13:13 20180601\20180601\bin\Debug\20180601.pdb
文件 5643 2018-06-02 13:13 20180601\20180601\Form1.cs
文件 21594 2018-06-02 13:09 20180601\20180601\Form1.Designer.cs
文件 12748 2018-06-02 13:09 20180601\20180601\Form1.resx
文件 42 2018-06-01 18:23 20180601\20180601\obj\Debug\20180601.csproj.CoreCompileInputs.cache
文件 684 2018-06-01 18:40 20180601\20180601\obj\Debug\20180601.csproj.FileListAbsolute.txt
文件 1012 2018-06-02 13:13 20180601\20180601\obj\Debug\20180601.csproj.GenerateResource.Cache
文件 2384 2018-06-01 18:40 20180601\20180601\obj\Debug\20180601.csprojResolveAssemblyReference.cache
文件 22528 2018-06-02 13:13 20180601\20180601\obj\Debug\20180601.exe
文件 26112 2018-06-02 13:13 20180601\20180601\obj\Debug\20180601.pdb
文件 1464 2018-06-02 09:49 20180601\20180601\obj\Debug\DesignTimeResolveAssemblyReferences.cache
文件 7120 2018-06-01 19:41 20180601\20180601\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
文件 0 2018-06-01 18:23 20180601\20180601\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
文件 0 2018-06-01 18:23 20180601\20180601\obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
文件 0 2018-06-01 18:23 20180601\20180601\obj\Debug\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
文件 4852 2018-06-02 13:13 20180601\20180601\obj\Debug\_20180601.Form1.resources
文件 180 2018-06-01 18:40 20180601\20180601\obj\Debug\_20180601.Properties.Resources.resources
文件 521 2018-06-01 18:23 20180601\20180601\Program.cs
文件 1314 2018-06-01 18:23 20180601\20180601\Properties\AssemblyInfo.cs
文件 2831 2018-06-01 18:23 20180601\20180601\Properties\Resources.Designer.cs
文件 5612 2018-06-01 18:23 20180601\20180601\Properties\Resources.resx
文件 1096 2018-06-01 18:23 20180601\20180601\Properties\Settings.Designer.cs
文件 249 2018-06-01 18:23 20180601\20180601\Properties\Settings.settings
文件 1123 2018-06-01 18:23 20180601\20180601.sln
............此处省略16个文件信息
相关资源
- asp.net C#购物车源代码
- 智慧城市 智能家居 C# 源代码
- MVC model层代码生成器 C#
- c# winform 自动登录 百度账户 源代码
- C#版保龄球记分代码
- C# 使用ListView控件实现图片浏览器(源
- c#记事本 基本功能已经全部实现 包附
- C# TCP通讯组件源代码
- C#版IE浏览器源代码
- C#使用GDI 绘制汽车车速表等量表源代
- 用C#绘制正弦曲线,要用到Form1_Resiz
- 随机抽题系统C#源代码
- 医院业务管理系统(C#源代码)
- C#代码生成器(生成MVC三层代码)
- 远程监控(C#源代码)
- C#Oracle数据库备份
- AssetStudio V0.16.0 源代码 使用VS2019
- 串口调试助手代码(XCOM V2.0)
- C#代码生成工具
- 热血江湖20服务端源代码
- C# 视觉处理代码、神经网络和遗传算
- C#跑马灯代码
- C#最新阿里云短信验证sdk代码
- socket服务端
- C# 立马关机 代码
- kepserver 连接 PLC代码
- VS2012保存时自动格式化代码插件(F
- EPLAN 菜单插件代码
- C# 取色工具源代码(RGB)
- C# 人员随机分组抽签工具及源代码
评论
共有 条评论