資源簡介
C#編寫的串口調試助手
<--------
很多和我一樣學習軟件專業的學生,有的時候對一些小項目真的是無可奈何
上次和我同學閑聊,他說C#寫一個串口調試助手好難,
見此情景,我就不自覺得也來寫了一個,親測可用
主要功能有:
1.串口設置:
1)接收端口
2)數據位
3)奇偶檢驗位
4)波特率
5)停止位
6)……
2.執行狀態
3.通信測試(HEX發送)
4.接收模式(響應模式、應答模式、HEX顯示)
下載須知:需要VS2012版本,及以上

代碼片段和文件信息
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;??//導入串口的命名空間
namespace?_01_SerialPort
{
????public?partial?class?Form1?:?Form
????{
????????public?delegate?void?showReceiveDelegate(string?text);?//當采用響應模式,應申明一個委托,實現不同線程的控件實驗
????????SerialPort?com?=?new?SerialPort(“COM2“?9600?Parity.None?8?StopBits.One);//初始化構造函數
????????public?Form1()
????????{
????????????InitializeComponent();
????????}
????????///?
????????///?窗體加載
????????///?
????????///?
????????///?
????????private?void?Form1_Load(object?sender?EventArgs?e)
????????{
??????????
????????????cmbPort.SelectedIndex?=?0;????????????
????????????cmbBaudRate.SelectedIndex?=?0;??????????
????????????cmbDataBits.SelectedIndex?=?0;???????????
????????????cmbStopBits.SelectedIndex?=?0;
????????????cmbParity.SelectedIndex?=?0;???????????
????????}
????????///?
????????///?串口打開與關閉
????????///?
????????///?
????????///?
????????private?void?btnOpen_Click(object?sender?EventArgs?e)
????????{
????????????if?(btnOpen.Text?==?“打開串口“)
????????????{
????????????????try
????????????????{
????????????????????if?(!com.IsOpen)
????????????????????{
????????????????????????com.PortName?=?cmbPort.Text;
????????????????????????com.BaudRate?=?int.Parse(cmbBaudRate.Text);
????????????????????????com.DataBits?=?int.Parse(cmbDataBits.Text);
????????????????????????switch?(cmbStopBits.SelectedIndex)????????????????????????{
????????????????????????????case?0:
????????????????????????????????com.StopBits?=?StopBits.One;?break;
????????????????????????????case?1:
????????????????????????????????com.StopBits?=?StopBits.Two;?break;
????????????????????????????case?2:
????????????????????????????????com.StopBits?=?StopBits.OnePointFive;?break;
????????????????????????????case?3:?????????????????????????????
????????????????????????????????com.StopBits?=?StopBits.None;?break;
????????????????????????}
????????????????????????switch?(cmbParity.SelectedIndex)
????????????????????????{
????????????????????????????case?0:?com.Parity?=?Parity.None;?break;
????????????????????????????case?1:?com.Parity?=?Parity.Odd;?break;
????????????????????????????case?2:?com.Parity?=?Parity.Even;?break;
????????????????????????}
????????????????????????com.Open();//打開串口
????????????????????}
????????????????????btnOpen.Text?=?“關閉串口“;
????????????????????txtStatus.Text?=?“串口已打開!“;
????????????????????btnSend.Enabled?=?true;
????????????????????if?(rbAck.Checked)
????????????????????????btnReceive.Enabled?=?true;?//應答模式,接收按鈕有效
????????????????}
????????????????catch
????????????????{?txtStatus.Text?=?“串口打開錯誤或串口不存在!“;?}
????????????}
????????????else?//關閉串口
?
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
????..A..H.?????45056??2017-10-26?09:39??01_SerialPort\.vs\01_SerialPort\v15\.suo
?????文件??????????0??2017-10-26?09:39??01_SerialPort\.vs\01_SerialPort\v15\Server\sqlite3\db.lock
?????文件?????512000??2017-10-26?09:39??01_SerialPort\.vs\01_SerialPort\v15\Server\sqlite3\storage.ide
?????文件???????3927??2015-03-18?08:57??01_SerialPort\01_SerialPort\01_SerialPort.csproj
?????文件??????17408??2015-04-14?11:51??01_SerialPort\01_SerialPort\bin\Debug\01_SerialPort.exe
?????文件??????32256??2015-04-14?11:51??01_SerialPort\01_SerialPort\bin\Debug\01_SerialPort.pdb
?????文件??????21464??2015-03-18?08:57??01_SerialPort\01_SerialPort\bin\Debug\01_SerialPort.vshost.exe
?????文件????????490??2015-03-18?08:57??01_SerialPort\01_SerialPort\bin\Debug\01_SerialPort.vshost.exe.manifest
?????文件??????10425??2015-04-07?13:26??01_SerialPort\01_SerialPort\Form1.cs
?????文件??????17358??2015-03-18?08:57??01_SerialPort\01_SerialPort\Form1.Designer.cs
?????文件???????5814??2015-03-18?08:57??01_SerialPort\01_SerialPort\Form1.resx
?????文件?????????42??2017-10-26?09:39??01_SerialPort\01_SerialPort\obj\Debug\01_SerialPort.csproj.CoreCompileInputs.cache
?????文件???????4302??2015-04-14?11:51??01_SerialPort\01_SerialPort\obj\Debug\01_SerialPort.csproj.FileListAbsolute.txt
?????文件????????905??2015-04-14?11:51??01_SerialPort\01_SerialPort\obj\Debug\01_SerialPort.csproj.GenerateResource.Cache
?????文件???????2157??2015-04-14?11:51??01_SerialPort\01_SerialPort\obj\Debug\01_SerialPort.csprojResolveAssemblyReference.cache
?????文件??????17408??2015-04-14?11:51??01_SerialPort\01_SerialPort\obj\Debug\01_SerialPort.exe
?????文件??????32256??2015-04-14?11:51??01_SerialPort\01_SerialPort\obj\Debug\01_SerialPort.pdb
?????文件????????790??2017-10-26?09:39??01_SerialPort\01_SerialPort\obj\Debug\DesignTimeResolveAssemblyReferences.cache
?????文件???????7248??2017-10-26?09:39??01_SerialPort\01_SerialPort\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
?????文件???????4608??2015-04-14?11:51??01_SerialPort\01_SerialPort\obj\Debug\TempPE\Properties.Resources.Designer.cs.dll
?????文件????????180??2015-03-18?08:57??01_SerialPort\01_SerialPort\obj\Debug\_01_SerialPort.Form1.resources
?????文件????????180??2015-03-18?08:57??01_SerialPort\01_SerialPort\obj\Debug\_01_SerialPort.Properties.Resources.resources
?????文件????????495??2015-03-18?08:57??01_SerialPort\01_SerialPort\Program.cs
?????文件???????1358??2015-03-18?08:57??01_SerialPort\01_SerialPort\Properties\AssemblyInfo.cs
?????文件???????2868??2015-03-18?08:57??01_SerialPort\01_SerialPort\Properties\Resources.Designer.cs
?????文件???????5612??2015-03-18?08:57??01_SerialPort\01_SerialPort\Properties\Resources.resx
?????文件???????1114??2015-03-18?08:57??01_SerialPort\01_SerialPort\Properties\Settings.Designer.cs
?????文件????????249??2015-03-18?08:57??01_SerialPort\01_SerialPort\Properties\Settings.settings
?????文件????????929??2015-03-18?08:57??01_SerialPort\01_SerialPort.sln
?????文件??????17920??2015-03-18?08:57??01_SerialPort\01_SerialPort.suo
............此處省略42個文件信息
評論
共有 條評論