资源简介
简单的串口通信工具,可以实现串口一些属性的设置,文件是在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个文件信息
相关资源
- 人机对战版五子棋C#源代码解压密码:
- ASP.NET 学生信息管理系统 整站 带数据
- C#版Socket通信含服务端、客户端、We
- C#windos窗体程序的对数据库的增、删、
- 局域网文件传输 Socket编程 C#代码
- C#实现数字签名算法
- C# 软件注册试用期限代码
- C#获取本地计算机的硬件信息源代码
- C#柔化方式显示图像_源代码
- C#+ArcEngine:矢量点转栅格-1VS2010窗体
- C#五子棋源代码wuziqi
- AES加密解密算法程序和源代码 C#实现
- C#中GDI+实现简单二维矢量图编辑器教
- C#调用matlab 源代码 csdn
- 我写的TreeGrid源代码 TreeGrid 网格树录
- 电子邮件email收取客户端程序,C#源代
- C#实现本地文件保存到另一台电脑的代
- C#编写的QQ简单界面源代码
- 客户订单管理系统源代码+数据库
- kalman卡尔曼滤波C#源代码
- c#编写串口通讯代码 多线程实现
- C#代码操作Excel不需要安装office
- C#学习之—五子棋源代码
- asp.net用OpenPop.dll获取邮件列表和内容
- C#数据同步源代码
- C#winform画图程序附解决方案,挺不错
- C# web编程,登陆界面代码
- VS2017 C#代码配色方案-monokai
- 微信企业付款到银行卡c#代码
- 简单收银系统 完整源代码
评论
共有 条评论