資源簡介
C#編寫串口助手,實現串口的收發,實現十六進制的收發。

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.ComponentModel;
using?System.Data;
using?System.Drawing;
using?System.Linq;
using?System.Text;
using?System.Threading.Tasks;
using?System.Windows.Forms;
using?System.IO.Ports;
namespace?CH
{
????public?partial?class?COMForm?:?Form
????{
????????int?a?=?0;
????????int?b?=?0;//計算發送數據位數
????????string?data;//
????????string?checkBox2_data;//
????????public?COMForm()
????????{
????????????InitializeComponent();
????????}
????????private?void?axMSComm1_OnComm(object?sender?EventArgs?e)
????????{
????????}
????????private?void?label1_Click(object?sender?EventArgs?e)
????????{
????????}
????????private?void?timer1_Tick(object?sender?EventArgs?e)
????????{
????????}
????????private?void?TextReceive_TextChanged(object?sender?EventArgs?e)
????????{
????????}
????????private?void?TextSend_TextChanged(object?sender?EventArgs?e)
????????{
????????}
????????//獲取串口列表初始化
????????private?void?COMForm_Load(object?sender?EventArgs?e)
????????{
????????????//查詢到串口號然后顯示到列表里
????????????string[]?array?=?System.IO.Ports.SerialPort.GetPortNames();
????????????for?(int?i?=?0;?i?????????????{
????????????????string?name?=?array[i];
????????????????comboBox1.Items.Add(name);
????????????}
????????????//在下拉控件上面顯示
????????????comboBox1.Text?=?comboBox1.Items[0].ToString();
????????????comboBox2.Text?=?comboBox2.Items[2].ToString();
????????????comboBox3.Text?=?comboBox3.Items[0].ToString();
????????????comboBox4.Text?=?comboBox4.Items[0].ToString();
????????????checkBox1.Checked?=false;
????????????checkBox(TextReceive.Text);
????????}
????????//退出按鈕
????????private?void?CmdClosed_Click(object?sender?EventArgs?e)
????????{
????????????serialPort1.Close();
????????????Close();
????????}
????????//發送數據按鈕
????????private?void?CmdSend_Click(object?sender?EventArgs?e)
????????{
????????????string?outdata?=?TextSend.Text;
????????????byte[]?byteArray?=new?byte[outdata.Length]?;
????????????int?i?=?outdata.Length;
????????????if?(button1.Text?==?“打開串口“)
????????????{
????????????????MessageBox.Show(“請打開串口“);
????????????}
????????????else?if?(outdata?==?““)
????????????{
????????????????MessageBox.Show(“發送數據不能為空“);
????????????}
????????????else
????????????{?
????????????????if?(checkBox2.Checked?==?true)
????????????????{
???????????????????//協議:長度加數據
????????????????????//int?s?=?outdata.Length/2;
????????????????????//if?(s.ToString().Length%2==1)
????????????????????//?????outdata?=?s.ToString().PadLeft(s.ToString().Length+1‘0‘)?+?outdata;
????????????????????//else
????????????????????//?????outdata?=?s.ToString().PadLeft(s.ToString().Length?‘0‘)?+?outdata;
???????????????
????????????????????byteArray?=?strToToHexByte(outdata.Replace(“?“?““));??????
????????????????????serialPort1.Write(byteArray?0?(outdata.Length)?/?2);
??????????????????
????????????????????a?=?a?+?o
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????????896??2017-10-23?12:11??CH\CH.sln
?????文件???????43008??2017-10-28?15:38??CH\CH.v11.suo
?????目錄???????????0??2017-10-25?21:10??CH\CH\
?????文件?????????766??2017-10-25?21:10??CH\CH\2.ico
?????文件?????????766??2017-10-25?21:04??CH\CH\3.ico
?????文件?????????187??2017-10-23?12:11??CH\CH\App.config
?????目錄???????????0??2017-10-24?21:44??CH\CH\bin\
?????目錄???????????0??2017-10-25?21:10??CH\CH\bin\Debug\
?????文件???????11776??2017-10-25?21:10??CH\CH\bin\Debug\AxInterop.MSCommLib.dll
?????文件???????53760??2017-10-25?21:10??CH\CH\bin\Debug\AxInterop.WMPLib.dll
?????文件??????141312??2017-10-27?14:28??CH\CH\bin\Debug\CH.exe
?????文件?????????187??2017-10-23?12:11??CH\CH\bin\Debug\CH.exe.config
?????文件???????36352??2017-10-27?14:28??CH\CH\bin\Debug\CH.pdb
?????文件???????22984??2017-10-28?14:07??CH\CH\bin\Debug\CH.vshost.exe
?????文件?????????187??2017-10-23?12:11??CH\CH\bin\Debug\CH.vshost.exe.config
?????文件?????????490??2016-03-09?13:48??CH\CH\bin\Debug\CH.vshost.exe.manifest
?????文件???????18432??2017-10-25?21:10??CH\CH\bin\Debug\Interop.MSCommLib.dll
?????文件??????331264??2017-10-25?21:10??CH\CH\bin\Debug\Interop.WMPLib.dll
?????目錄???????????0??2017-10-25?21:10??CH\CH\bin\Debug\sq-AL\
?????文件????????4608??2017-10-27?14:28??CH\CH\bin\Debug\sq-AL\CH.resources.dll
?????目錄???????????0??2017-10-24?21:44??CH\CH\bin\Release\
?????文件???????11776??2017-10-24?21:44??CH\CH\bin\Release\AxInterop.MSCommLib.dll
?????文件???????53760??2017-10-24?21:44??CH\CH\bin\Release\AxInterop.WMPLib.dll
?????文件??????140800??2017-10-25?20:17??CH\CH\bin\Release\CH.exe
?????文件?????????187??2017-10-23?12:11??CH\CH\bin\Release\CH.exe.config
?????文件???????34304??2017-10-25?20:17??CH\CH\bin\Release\CH.pdb
?????文件???????22984??2017-10-25?20:20??CH\CH\bin\Release\CH.vshost.exe
?????文件?????????187??2017-10-23?12:11??CH\CH\bin\Release\CH.vshost.exe.config
?????文件?????????490??2016-03-09?13:48??CH\CH\bin\Release\CH.vshost.exe.manifest
?????文件???????18432??2017-10-24?21:44??CH\CH\bin\Release\Interop.MSCommLib.dll
?????文件??????331264??2017-10-24?21:44??CH\CH\bin\Release\Interop.WMPLib.dll
............此處省略66個文件信息
評論
共有 條評論