資源簡介
基于C#程序的串口收發軟件,易于初學者學習引用。

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.ComponentModel;
using?System.Data;
using?System.Drawing;
using?System.Text;
using?System.Windows.Forms;
using?System.IO.Ports;
using?System.Threading;
namespace?uart_test
{
????public?partial?class?Form1?:?Form
????{
????????Boolean?UartClose?=?false;??//ToolOpen?的控制命令?
????????public?SerialPort?PortM3;??????//定義M3的端口
????????Uart?UartInitial?=?new?Uart();
????????#region
????????????public?string?ConvertString(string?value?int?frombase?int?tobase)
????????????{
????????????????string?temp?=?““;
????????????????int?intValue?=?Convert.ToInt32(value?frombase);
????????????????temp?=?Convert.ToString(intValue?tobase).ToUpper();
????????????????if?(temp.Length?2)
????????????????{?temp?=?“0“?+?temp;?}
????????????????return?temp;
????????????}
????????#endregion
????????public?Form1()
????????{
????????????InitializeComponent();
????????????comboBoxPort.Items.AddRange(SerialPort.GetPortNames());
????????????
????????}
????????private?void?butSend_Click(object?sender?EventArgs?e)
????????{
????????????if?(UartClose)
????????????{
????????????????butSend.BackColor?=?Color.FromArgb(255?192?192);
????????????????butSend.Text?=?“發送開啟“;
????????????????if?(PortM3?!=?null)
????????????????{
????????????????????PortM3.Close();
????????????????}
????????????????UartClose?=?false;
????????????}
????????????else
????????????{
????????????????if?(UartInitial.SerialPortOpen(serialBoardcomboBoxPort.SelectedItem.ToString()))
????????????????{
????????????????????butSend.Text?=?“發送關閉“;
????????????????????butSend.BackColor?=?Color.Red;
????????????????????UartClose?=?true;
????????????????????PortM3?=?serialBoard;
????????????????????//----發送數據---------------
????????????????????PortM3.Write(textBoxSend.Text);
????
????????????????????////----接收數據---------------
????????????????????//_keepReading?=?true;
????????????????????//_readThread?=?new?Thread(ReadPort);
????????????????????//_readThread.Start();
????????????????}
????????????}
????????}
????????private?void?button1_Click(object?sender?EventArgs?e)
????????{
????????????//Byte[]?TxData?={?1?2?3?4?5?6?255?8123231111?};
????????????//PortM3.Write(TxData?0?8);
????????????//PortM3.Write(TxData0TxData.Length);
????????????//PortM3.WriteLine(TxData.ToString());
????????????//textBoxRec.Text?=?TxData.ToString();
????????????//string?StrTemp?=?this.PortM3.ReadLine();
????????????//textBoxRec.Text?=?StrTemp;
????????????//_keepReading?=?true;
????????????//ReadPort();
????????}
????????private?void?serialBoard_DataReceived(object?sender?SerialDataReceivedEventArgs?e)
????????{
????????????//string?temptxt?=?this.PortM3.ReadLine();
????????????//string?b?=?temptxt;
????????//????/*-------按每個字節進行讀取---------------------*/
????????//????////int?SDateTemp?=?this.serialPort1.ReadByte();?
????????//????//int?bytes?=?thi
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2014-09-17?16:48??串口測試\
?????目錄???????????0??2014-09-17?16:48??串口測試\uart_test\
?????目錄???????????0??2014-09-17?16:48??串口測試\uart_test\uart_test\
?????文件?????????916??2014-05-21?08:59??串口測試\uart_test\uart_test.sln
?????文件???????15872??2015-10-21?09:50??串口測試\uart_test\uart_test.suo
?????目錄???????????0??2014-09-17?16:48??串口測試\uart_test\uart_test\bin\
?????目錄???????????0??2014-09-17?16:48??串口測試\uart_test\uart_test\bin\Debug\
?????文件???????24576??2014-05-21?16:34??串口測試\uart_test\uart_test\bin\Debug\uart_test.exe
?????文件???????30208??2014-05-21?16:34??串口測試\uart_test\uart_test\bin\Debug\uart_test.pdb
?????文件????????5632??2005-12-08?14:51??串口測試\uart_test\uart_test\bin\Debug\uart_test.vshost.exe
?????文件????????8145??2014-05-21?16:34??串口測試\uart_test\uart_test\Form1.cs
?????文件????????8831??2014-05-21?15:47??串口測試\uart_test\uart_test\Form1.Designer.cs
?????文件????????6186??2014-05-21?15:47??串口測試\uart_test\uart_test\Form1.resx
?????目錄???????????0??2014-09-17?16:48??串口測試\uart_test\uart_test\obj\
?????目錄???????????0??2014-09-17?16:48??串口測試\uart_test\uart_test\obj\Debug\
?????目錄???????????0??2014-05-21?09:02??串口測試\uart_test\uart_test\obj\Debug\Refactor\
?????目錄???????????0??2014-05-21?08:59??串口測試\uart_test\uart_test\obj\Debug\TempPE\
?????文件?????????842??2014-05-21?15:47??串口測試\uart_test\uart_test\obj\Debug\uart_test.csproj.GenerateResource.Cache
?????文件???????24576??2014-05-21?16:34??串口測試\uart_test\uart_test\obj\Debug\uart_test.exe
?????文件?????????180??2014-05-21?15:47??串口測試\uart_test\uart_test\obj\Debug\uart_test.Form1.resources
?????文件???????30208??2014-05-21?16:34??串口測試\uart_test\uart_test\obj\Debug\uart_test.pdb
?????文件?????????180??2014-05-21?09:33??串口測試\uart_test\uart_test\obj\Debug\uart_test.Properties.Resources.resources
?????文件?????????978??2015-10-21?09:47??串口測試\uart_test\uart_test\obj\uart_test.csproj.FileListAbsolute.txt
?????文件?????????468??2014-05-21?08:59??串口測試\uart_test\uart_test\Program.cs
?????目錄???????????0??2014-09-17?16:48??串口測試\uart_test\uart_test\Properties\
?????文件????????1176??2014-05-21?08:59??串口測試\uart_test\uart_test\Properties\AssemblyInfo.cs
?????文件????????2874??2014-05-21?08:59??串口測試\uart_test\uart_test\Properties\Resources.Designer.cs
?????文件????????5612??2014-05-21?08:59??串口測試\uart_test\uart_test\Properties\Resources.resx
?????文件????????1094??2014-05-21?08:59??串口測試\uart_test\uart_test\Properties\Settings.Designer.cs
?????文件?????????249??2014-05-21?08:59??串口測試\uart_test\uart_test\Properties\Settings.settings
?????文件????????1160??2014-05-21?10:39??串口測試\uart_test\uart_test\Uart.cs
............此處省略1個文件信息
- 上一篇:C# 高性能內存加密類庫 源碼
- 下一篇:C#三層結構增、刪、改、查
評論
共有 條評論