資源簡介
串口通信測試程序,包含一個串口參數設置窗口
代碼片段和文件信息
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.Ports;
using?System.Threading;
using?System.IO;
using?System.Collections;
namespace?RS232Comm
{
????public?partial?class?MainForm?:?Form
????{
????????protected?Boolean?stop?=?false;????
????????protected?Boolean?conState?=?false;
????????private?StreamReader?sRead;
????????public?MainForm()
????????{
????????????InitializeComponent();
????????}
????????string?strRecieve;
????????bool?bAccept?=?false;
????????SerialPort?sp?=?new?SerialPort();
?
????????public?static?string?strPortName?=?““;
????????public?static?string?strBaudRate?=?““;
????????public?static?string?strDataBits?=?““;
????????public?static?string?strStopBits?=?““;
????????private?void?btnSetSP_Click(object?sender?EventArgs?e)//串口設置
????????{
????????????timer1.Enabled?=?false;
????????????sp.Close();
????????????ComSet?dlg?=?new?ComSet();
????????????if?(dlg.ShowDialog()?==?DialogResult.OK)
????????????{
????????????????sp.PortName?=?strPortName;
????????????????sp.BaudRate?=?int.Parse(strBaudRate);
????????????????sp.DataBits?=?int.Parse(strDataBits);
????????????????sp.StopBits?=?(StopBits)int.Parse(strStopBits);
????????????????sp.ReadTimeout?=?500;
????????????}
????????}
????????private?void?btnSwitchSP_Click(object?sender?EventArgs?e)//打開串口
????????{
????????????if?(btnSwitchSP.Text?==?“打開串口“)
????????????{
????????????????if?(strPortName?!=?““?&&?strBaudRate?!=?““?&&?strDataBits?!=?““?&&?strStopBits?!=?““)
????????????????{
????????????????????try
????????????????????{
????????????????????????if?(sp.IsOpen)
????????????????????????{
????????????????????????????sp.Close();
????????????????????????????sp.Open();?//打開串口????
????????????????????????}
????????????????????????else
????????????????????????{
????????????????????????????sp.Open();//打開串口????
????????????????????????}
????????????????????????btnSwitchSP.Text?=?“關閉串口“;
????????????????????????groupBox1.Enabled?=?true;
????????????????????????groupBox2.Enabled?=?true;
????????????????????????this.toolStripStatusLabel1.Text?=?“端口號:“?+?sp.PortName?+?“?丨“;
????????????????????????this.toolStripStatusLabel2.Text?=?“波特率:“?+?sp.BaudRate?+?“?丨“;
????????????????????????this.toolStripStatusLabel3.Text?=?“數據位:“?+?sp.DataBits?+?“?丨“;
????????????????????????this.toolStripStatusLabel4.Text?=?“停止位:“?+?sp.StopBits?+?“?丨“;
????????????????????????this.toolStripStatusLabel5.Text?=?““;
????????????????????}
????????????????????catch?(Exception?ex)
????????????????????{
????????????????????????MessageBox.Show(“錯誤:“?+?ex.Message“C#串口通信“);
????????????????????}
????????????????}
????????????????else
????????????????{
????????????????????MessageBox.Show(“請先設置串口!““RS232串口通信“);
????????????????}
????????????}
????????????else
????????????{
?????????????
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????219648??2014-08-09?19:46??C#SerialPort\bin\Debug\RS232Comm.exe
?????文件??????46592??2014-08-09?19:46??C#SerialPort\bin\Debug\RS232Comm.pdb
?????文件??????11600??2014-12-13?11:36??C#SerialPort\bin\Debug\RS232Comm.vshost.exe
?????文件????????490??2010-03-17?22:39??C#SerialPort\bin\Debug\RS232Comm.vshost.exe.manifest
?????文件??????23040??2014-08-09?13:49??C#SerialPort\bin\Debug\串口通信.exe
?????文件??????69120??2014-08-09?13:49??C#SerialPort\bin\Debug\串口通信.pdb
?????文件??????98798??2014-01-02?12:58??C#SerialPort\bipt.ico
?????文件???????9118??2014-08-09?19:49??C#SerialPort\MainForm.cs
?????文件??????14721??2014-08-09?19:46??C#SerialPort\MainForm.Designer.cs
?????文件?????154906??2014-08-09?19:46??C#SerialPort\MainForm.resx
?????文件???????2164??2014-08-09?12:42??C#SerialPort\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache
?????文件???????7367??2014-12-13?11:36??C#SerialPort\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
?????文件????????384??2012-07-10?17:08??C#SerialPort\obj\x86\Debug\GenerateResource.read.1.tlog
?????文件????????940??2012-07-10?17:08??C#SerialPort\obj\x86\Debug\GenerateResource.write.1.tlog
?????文件???????8614??2012-07-12?12:10??C#SerialPort\obj\x86\Debug\ResolveAssemblyReference.cache
?????文件????????180??2014-08-09?19:46??C#SerialPort\obj\x86\Debug\RS232Comm.ComSet.resources
?????文件???????2596??2014-12-13?11:36??C#SerialPort\obj\x86\Debug\RS232Comm.csproj.FileListAbsolute.txt
?????文件?????219648??2014-08-09?19:46??C#SerialPort\obj\x86\Debug\RS232Comm.exe
?????文件??????99364??2014-08-09?19:46??C#SerialPort\obj\x86\Debug\RS232Comm.MainForm.resources
?????文件??????46592??2014-08-09?19:46??C#SerialPort\obj\x86\Debug\RS232Comm.pdb
?????文件????????180??2014-08-09?19:46??C#SerialPort\obj\x86\Debug\RS232Comm.Properties.Resources.resources
?????文件???????4608??2014-08-09?13:57??C#SerialPort\obj\x86\Debug\TempPE\Properties.Resources.Designer.cs.dll
?????文件????????180??2014-08-09?13:49??C#SerialPort\obj\x86\Debug\串口通信.ComSet.resources
?????文件???????6568??2014-08-09?13:54??C#SerialPort\obj\x86\Debug\串口通信.csproj.FileListAbsolute.txt
?????文件???????1091??2014-01-03?19:14??C#SerialPort\obj\x86\Debug\串口通信.csproj.GenerateResource.Cache
?????文件???????9948??2014-01-02?11:13??C#SerialPort\obj\x86\Debug\串口通信.csprojResolveAssemblyReference.cache
?????文件????????180??2014-08-09?13:49??C#SerialPort\obj\x86\Debug\串口通信.Form1.resources
?????文件????????180??2014-08-09?13:49??C#SerialPort\obj\x86\Debug\串口通信.Form2.resources
?????文件????????180??2014-08-09?13:49??C#SerialPort\obj\x86\Debug\串口通信.Properties.Resources.resources
?????文件????????493??2014-08-09?13:57??C#SerialPort\Program.cs
............此處省略25個文件信息
- 上一篇:C# Mail-發送郵箱
- 下一篇:讀取xm
l顯示在dataGridView
評論
共有 條評論